lkjalkjdsalkj

This commit is contained in:
Peder Bergebakken Sundt 2024-04-16 06:50:47 +02:00
parent d94277cd14
commit 8970e79d0c
2 changed files with 33 additions and 0 deletions

View File

@ -0,0 +1,7 @@
{ writeShellApplication, libnotify }:
writeShellApplication {
name = "device-mon";
runtimeInputs = [ libnotify ];
text = builtins.readFile ./main.sh;
}

26
pkgs/device-mon/main.sh Normal file
View File

@ -0,0 +1,26 @@
#!/usr/bin/env bash
trap "echo Exited!; exit;" SIGINT SIGTERM
OLD="$(lsusb)"
while true; do
watch --chgexit -n0.2 lsusb >& /dev/null
NEW="$(lsusb)"
diff <(cat <<<"$OLD") <(cat <<<"$NEW") --unified | grep '^[+-]' | grep -Ev '^(---|\+\+\+)' |
while read line; do
echo "$line"
ID="$( echo "$line" | cut -c2- | cut -d' ' -f-6 )"
LABEL="$(echo "$line" | cut -c2- | cut -d' ' -f7- )"
case "$line" in
\+*)
notify-send --icon=device --expire-time=500 "New device connected" "${LABEL} <i>($ID)</i>"
;;
\-*)
notify-send --icon=device --expire-time=500 "Device disconnected" "${LABEL} <i>($ID)</i>"
;;
esac
done
OLD="$NEW"
done