1
0
Fork 0
mirror of https://github.com/Horhik/dotfiles.git synced 2024-12-02 03:16:50 +00:00
Dotfiles/.config/polybar/polybar-scripts/info-usbtoserial/info-usbtoserial.sh
2020-07-27 07:59:00 +03:00

45 lines
861 B
Bash

#!/bin/sh
usbtoserial_print() {
devices=$(find /dev/ -name "ttyUSB*")
counter=0
for device in $devices; do
device_name=$(udevadm info --query=property --export --name "$device" | grep ID_MODEL_FROM_DATABASE | cut -d "'" -f 2 | cut -d ' ' -f 1)
if [ $counter -gt 0 ]; then
printf ", %s" "$device_name"
else
printf "#1 %s" "$device_name"
fi
counter=$((counter + 1))
done
printf '\n'
}
path_pid="/tmp/polybar-usbtoserial.pid"
case "$1" in
--update)
pid=$(cat $path_pid)
if [ "$pid" != "" ]; then
kill -10 "$pid"
fi
;;
*)
echo $$ > $path_pid
trap exit INT
trap "echo" USR1
while true; do
usbtoserial_print
sleep 30 &
wait
done
;;
esac