diff options
author | Justine Smithies <justine@smithies.me.uk> | 2024-11-08 20:48:58 +0000 |
---|---|---|
committer | Justine Smithies <justine@smithies.me.uk> | 2024-11-08 20:48:58 +0000 |
commit | c2fbc4d1717864a0055592e0b73d71c010e8686c (patch) | |
tree | 76e5bf50cc0f9c1b83f474740a8015d7f4e0ef26 /.config/eww/scripts/scratchpad-indicator.sh | |
parent | b9d24b3b6bdaed04fab07d9150c51d4f0f7a5c7d (diff) |
Initial commit
Diffstat (limited to '.config/eww/scripts/scratchpad-indicator.sh')
-rwxr-xr-x | .config/eww/scripts/scratchpad-indicator.sh | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/.config/eww/scripts/scratchpad-indicator.sh b/.config/eww/scripts/scratchpad-indicator.sh new file mode 100755 index 0000000..8fd06f4 --- /dev/null +++ b/.config/eww/scripts/scratchpad-indicator.sh @@ -0,0 +1,35 @@ +#!/bin/bash +# Scratchpad indicator for Sway + +output="$(swaymsg -t get_tree | jq -r 'recurse(.nodes[]?)|recurse(.floating_nodes[]?)|select(.name == "__i3_scratch").floating_nodes[]|"`<b>"+.name+"`</b> - "+.app_id+" "+(.id|tostring)')" +number="$(swaymsg -r -t get_tree | jq -r 'recurse(.nodes[]) | first(select(.name=="__i3_scratch")) | .floating_nodes | length')" + +if [ "$number" -gt 0 ]; then + text=" $number" +else + text="" +fi + +output="$(echo "$output" | sed -r 's/[&]+/and/g')" # Replace unprintable & character with the word 'and' +tooltip="\n" +tooltip+="$(echo "$output" | sed -z 's/\n/\\n/g')" +tooltip=${tooltip::-2} + +function ShowInfo() { + if [ "$number" -eq 0 ]; then + exit + else + tooltip="$(echo -e $tooltip)" + notify-send --hint=string:x-canonical-private-synchronous:scratchpad -u normal " Scratchpad" "$tooltip" + fi +} + +function Update() { + printf "%s" "$text" +} + +if [ "$1" = "ShowInfo" ]; then + ShowInfo +else + Update +fi |