1
0
Fork 0
mirror of https://github.com/Horhik/dotfiles.git synced 2024-11-23 08:31:31 +00:00
Dotfiles/.config/polybar/polybar-scripts/info-usbtoserial/info-usbtoserial.sh

45 lines
861 B
Bash
Raw Normal View History

2020-07-27 04:59:00 +00:00
#!/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