From 69411dd2c20a000e7b7e853ce5a07305a4ad86ae Mon Sep 17 00:00:00 2001 From: urosm Date: Sat, 28 Sep 2024 21:01:58 +0200 Subject: [PATCH] Rename and refactor swaystatus script --- .config/sway/config | 2 +- .local/bin/status.sh | 44 ------------------------------------------- .local/bin/swaystatus | 28 +++++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 45 deletions(-) delete mode 100755 .local/bin/status.sh create mode 100755 .local/bin/swaystatus diff --git a/.config/sway/config b/.config/sway/config index 6737fb4..93eb177 100644 --- a/.config/sway/config +++ b/.config/sway/config @@ -51,7 +51,7 @@ set $swaylock swaylock -f \ # bar ########################################################################## bar { separator_symbol " | " - status_command status.sh + status_command exec swaystatus strip_workspace_numbers yes wrap_scroll yes colors { diff --git a/.local/bin/status.sh b/.local/bin/status.sh deleted file mode 100755 index 9c30e81..0000000 --- a/.local/bin/status.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/sh - -printf "{\"version\":1}\n" -printf "[\n" - -if ! command -v jq >/dev/null; then - while :; do - printf '[{ "full_text":"jq: command not found", "urgent":true },],' - sleep 60 - done -fi - -while :; do - printf "[" - # notifications - makoctl list | jq -Mcj '.data[] | - if length>0 then { - "full_text":(["(",length,") ",.[0].summary.data]|join("")), - "urgent":(.[0].urgency.data==2), - } else { - "full_text":"(0)", - } end, ","' - # battery - # shellcheck disable=SC2002 - cat /sys/class/power_supply/BAT0/capacity | jq -Mcj ' - if .<20 then { - "full_text":([.," %"]|join("")), - "urgent":true, - } else { - "full_text":([.," %"]|join("")), - } end, ","' - # date - date +%c | jq -RMcj '{ "full_text":., }, ","' - # scratchpad - swaymsg -t get_tree | jq -Mcj '.nodes[] | select(.name=="__i3").nodes[] | - select(.name=="__i3_scratch").floating_nodes | { - "full_text":length, - "urgent":length, - }, ","' - printf "]," - # timeout - timeout 1 swaymsg -qt subscribe '["binding"]' >/dev/null - sleep 0.1 -done diff --git a/.local/bin/swaystatus b/.local/bin/swaystatus new file mode 100755 index 0000000..92ab5fe --- /dev/null +++ b/.local/bin/swaystatus @@ -0,0 +1,28 @@ +#!/bin/sh + +printf "{\"version\":1}\n" +printf "[\n" + +if ! command -v jq >/dev/null; then + while :; do + printf '[{"full_text":"jq: command not found","urgent":true},],' + sleep 60 + done +fi + +while :; do + printf "[" + # notifications + makoctl list | jq -cj '.data[][0] | {"full_text":.summary.data,"urgent":(.urgency.data==2)}, ","' + # battery + # shellcheck disable=SC2002 + cat /sys/class/power_supply/BAT0/capacity | jq -cj '{"full_text":((.|tostring)+" %"),"urgent":(.<20)}, ","' + # date + date | jq -Rcj '{"full_text":.}, ","' + # scratchpad + swaymsg -t get_tree | jq -cj 'recurse(.nodes[]) | select(.name=="__i3_scratch").floating_nodes | {"full_text":length,"urgent":length}, ","' + printf "]," + # timeout + timeout 1 swaymsg -qt subscribe '["binding"]' >/dev/null + sleep 0.1 +done