From 229a242c97d59a780127e8a7de4305b5f1ae3f6b Mon Sep 17 00:00:00 2001 From: Luca Bilke Date: Sat, 3 Feb 2024 17:52:33 +0100 Subject: [PATCH] rewrite statusbar scripts for pango --- .local/libexec/statusbar/colors | 25 +++++++++++++++++ .local/libexec/statusbar/sb-battery | 39 ++++++++++++--------------- .local/libexec/statusbar/sb-cpu | 33 ++++++++++------------- .local/libexec/statusbar/sb-date | 1 + .local/libexec/statusbar/sb-disk | 2 -- .local/libexec/statusbar/sb-forecast | 13 +++------ .local/libexec/statusbar/sb-internet | 13 +++++---- .local/libexec/statusbar/sb-nettraf | 6 ++--- .local/libexec/statusbar/sb-packages | 5 ++-- .local/libexec/statusbar/sb-playerctl | 8 +++--- 10 files changed, 74 insertions(+), 71 deletions(-) create mode 100755 .local/libexec/statusbar/colors diff --git a/.local/libexec/statusbar/colors b/.local/libexec/statusbar/colors new file mode 100755 index 000000000..85e8acd53 --- /dev/null +++ b/.local/libexec/statusbar/colors @@ -0,0 +1,25 @@ +#!/bin/sh + +fgalpha="FF" +bgalpha="CC" + +export big="size=40" +export verybig="size=60" +export fgblack="foreground='#15161E$fgalpha'" +export fgred="foreground='#F7768E$fgalpha'" +export fggreen="foreground='#9ECE6A$fgalpha'" +export fgorange="foreground='#E0AF68$fgalpha'" +export fgblue="foreground='#7AA2F7$fgalpha'" +export fgmagenta="foreground='#BB9AF7$fgalpha'" +export fgcyan="foreground='#7DCFFF$fgalpha'" +export fggray="foreground='#414868$fgalpha'" +export fgwhite="foreground='#C0CAF5$fgalpha'" +export bgblack="background='#15161E$bgalpha'" +export bgred="background='#F7768E$bgalpha'" +export bggreen="background='#9ECE6A$bgalpha'" +export bgorange="background='#E0AF68$bgalpha'" +export bgblue="background='#7AA2F7$bgalpha'" +export bgmagenta="background='#BB9AF7$bgalpha'" +export bgcyan="background='#7DCFFF$bgalpha'" +export bggray="background='#414868$bgalpha'" +export bgwhite="background='#C0CAF5$bgalpha'" diff --git a/.local/libexec/statusbar/sb-battery b/.local/libexec/statusbar/sb-battery index ec318f82b..338311e55 100755 --- a/.local/libexec/statusbar/sb-battery +++ b/.local/libexec/statusbar/sb-battery @@ -1,10 +1,5 @@ #!/bin/sh -red="\033[31m" -orange="\033[33m" -cyan="\033[36m" -green="\033[32m" -white="\033[37m" -reset="\033[0m" +. "$HOME/.local/libexec/statusbar/colors" [ -z "$(ls /sys/class/power_supply)" ] && exit 0 @@ -15,57 +10,57 @@ for battery in /sys/class/power_supply/BAT?*; do case "$(cat "$battery/status" 2>&1)" in "Full") icon="󰁹" - color="$green" + color="$fggreen" ;; "Not charging") icon="󰁹" - color="$white" + color="$fgwhite" ;; "Unknown") icon="󰂑" - color="$orange" + color="$fgorange" ;; "Charging") icon="󰂄" - color="$cyan" + color="$fgcyan" ;; "Discharging") if [ "$capacity" -le 10 ]; then icon="󰂎" - color="$red" + color="$fgred" elif [ "$capacity" -le 20 ]; then icon="󰁺" - color="$red" + color="$fgred" elif [ "$capacity" -le 30 ]; then icon="󰁻" - color="$white" + color="$fgwhite" elif [ "$capacity" -le 40 ]; then icon="󰁼" - color="$white" + color="$fgwhite" elif [ "$capacity" -le 50 ]; then icon="󰁽" - color="$white" + color="$fgwhite" elif [ "$capacity" -le 60 ]; then icon="󰁾" - color="$white" + color="$fgwhite" elif [ "$capacity" -le 70 ]; then icon="󰁿" - color="$white" + color="$fgwhite" elif [ "$capacity" -le 80 ]; then icon="󰂀" - color="$white" + color="$fgwhite" elif [ "$capacity" -le 90 ]; then icon="󰂁" - color="$white" + color="$fgwhite" elif [ "$capacity" -le 100 ]; then icon="󰂂" - color="$white" + color="$fgwhite" else icon="󰁹" - color="$white" + color="$fgwhite" fi ;; *) exit 1 ;; esac - printf "%b" "$color$icon$reset $capacity" + printf "%b" "$icon $capacity" done && printf "\\n" diff --git a/.local/libexec/statusbar/sb-cpu b/.local/libexec/statusbar/sb-cpu index 6db12090f..c0c969df1 100755 --- a/.local/libexec/statusbar/sb-cpu +++ b/.local/libexec/statusbar/sb-cpu @@ -1,11 +1,5 @@ #!/bin/sh - -reset="\033[0m" -normal="\033[10m" -big="\033[11m" -red="\033[31m" -green="\033[32m" -orange="\033[33m" +. "$HOME/.local/libexec/statusbar/colors" cache=/tmp/cpubarscache temp=$(sensors | awk '/CPU/ {printf ("%.f°C", $2)}' | tr -d "+") @@ -13,23 +7,24 @@ temp=$(sensors | awk '/CPU/ {printf ("%.f°C", $2)}' | tr -d "+") stats=$(awk '/cpu[0-9]+/ {printf "%d %d %d\n", substr($1,4), ($2 + $3 + $4 + $5), $5 }' /proc/stat 2>/dev/null) [ ! -f $cache ] && echo "$stats" >"$cache" old=$(cat "$cache") -printf "%b" "$big $normal$temp" +printf "%b" "$temp" echo "$stats" | while read -r row; do id=${row%% *} rest=${row#* } total=${rest%% *} idle=${rest##* } - case "$(echo "$old" | awk '{if ($1 == id) - printf "%d\n", (1 - (idle - $3) / (total - $2))*100 /12.5}' 2>/dev/null\ - id="$id" total="$total" idle="$idle")" in - "0") printf "%b" "$green▁" ;; - "1") printf "%b" "$green▂" ;; - "2") printf "%b" "$green▃" ;; - "3") printf "%b" "$orange▄" ;; - "4") printf "%b" "$orange▅" ;; - "5") printf "%b" "$orange▆" ;; - "6" | "7" | "8") printf "%b" "$red▇" ;; + case "$( + echo "$old" | + awk '{if ($1 == id) printf "%d\n", (1 - (idle - $3) / (total - $2))*100 /12.5}' \ + id="$id" total="$total" idle="$idle" 2>/dev/null + )" in + "0") printf "%b" "" ;; + "1") printf "%b" "" ;; + "2") printf "%b" "" ;; + "3") printf "%b" "" ;; + "4") printf "%b" "" ;; + "5") printf "%b" "" ;; + "6" | "7" | "8") printf "%b" "" ;; esac done -printf "%b" "$reset\n" echo "$stats" >"$cache" diff --git a/.local/libexec/statusbar/sb-date b/.local/libexec/statusbar/sb-date index 51e489453..791557441 100755 --- a/.local/libexec/statusbar/sb-date +++ b/.local/libexec/statusbar/sb-date @@ -1,2 +1,3 @@ #!/bin/sh + date +'%X %x' diff --git a/.local/libexec/statusbar/sb-disk b/.local/libexec/statusbar/sb-disk index fe8ba59f9..5863e759f 100755 --- a/.local/libexec/statusbar/sb-disk +++ b/.local/libexec/statusbar/sb-disk @@ -1,7 +1,5 @@ #!/bin/sh -# reset="\033[0m" -# big="\033[12m" IFS=' ' diff --git a/.local/libexec/statusbar/sb-forecast b/.local/libexec/statusbar/sb-forecast index 5fe651533..920ac3172 100755 --- a/.local/libexec/statusbar/sb-forecast +++ b/.local/libexec/statusbar/sb-forecast @@ -1,14 +1,9 @@ #!/bin/sh +. "$HOME/.local/libexec/statusbar/colors" # NOTE: This script takes its dwmblocks update signal as an argument so that it can refresh itself (defaults to 5) # Options can be found at https://wttr.in/:help -reset="\033[0m" -big="\033[11m" -verybig="\033[12m" -red="\033[31m" -blue="\033[34m" - weatherfile="$XDG_CACHE_HOME/weatherreport" emojifile="$XDG_CACHE_HOME/weatheremoji" url="wttr.in/$FORECAST_LOCATION" @@ -30,12 +25,12 @@ readfile() { } output() { readfile - printf "%b" "$verybig$emoji$reset $precipitation $big$blue$reset $(echo $highlow | cut -d" " -f1)° $big$red$reset $(echo $highlow | cut -d" " -f2)°\n" + printf "%b" "$emoji $precipitation $(echo "$highlow" | cut -d" " -f1)° $(echo "$highlow" | cut -d" " -f2)°\n" } if fresh; then output else - getforecast && pkill -RTMIN+${1:-5} dwmblocks & - printf "%b" "$big$reset Getting Weather\n" + getforecast && pkill "-RTMIN+${1:-5}" dwmblocks & + printf "%b" " Getting Weather\n" fi diff --git a/.local/libexec/statusbar/sb-internet b/.local/libexec/statusbar/sb-internet index 6c52b3c59..fc7d1974b 100755 --- a/.local/libexec/statusbar/sb-internet +++ b/.local/libexec/statusbar/sb-internet @@ -1,14 +1,13 @@ #!/bin/sh -shift="" +. "$HOME/.local/libexec/statusbar/colors" -reset="\033[0m" -big="\033[11m" +shift="" if ls /sys/class/net/w*/operstate 1>/dev/null 2>&1; then for w in /sys/class/net/w*/; do - percent="$(cat /proc/net/wireless | grep "$(basename "$(dirname $w/operstate)")" | tr -s ' ' | cut -d ' ' -f3 | tr -dc "[:digit:]")" - grep -vxq '0x1003' "$w/flags" && wifi_icon="" || wifi_icon="$(sed "s/up/󰖩/;s/down/󰖪/;s/dormant/󰤯/" $w/operstate | tr -d "[:space:]")" - printf "%b" "$shift$big$wifi_icon$reset $percent" + percent="$(grep "$(basename "$(dirname "$w/operstate")")" /proc/net/wireless | tr -s ' ' | cut -d ' ' -f3 | tr -dc "[:digit:]")" + grep -vxq '0x1003' "$w/flags" && wifi_icon="" || wifi_icon="$(sed "s/up/󰖩/;s/down/󰖪/;s/dormant/󰤯/" "$w/operstate" | tr -d "[:space:]")" + printf "%b" "$shift$wifi_icon $percent" shift=" " done fi @@ -22,7 +21,7 @@ fi if ls /sys/class/net/tun*/operstate 1>/dev/null 2>&1; then for _ in /sys/class/net/tun*/operstate; do - printf "%b" "$shift$big󰖂$reset" + printf "%b" "$shift󰖂" shift=" " done fi diff --git a/.local/libexec/statusbar/sb-nettraf b/.local/libexec/statusbar/sb-nettraf index add502b80..b344e3d2e 100755 --- a/.local/libexec/statusbar/sb-nettraf +++ b/.local/libexec/statusbar/sb-nettraf @@ -1,7 +1,5 @@ #!/bin/sh - -big="\033[11m" -reset="\033[0m" +. "$HOME/.local/libexec/statusbar/colors" update() { sum=0 @@ -17,4 +15,4 @@ update() { rx=$(update /sys/class/net/[ew]*/statistics/rx_bytes) tx=$(update /sys/class/net/[ew]*/statistics/tx_bytes) -printf "%b%5sB %b%5sB%b" "$big$reset" "$(numfmt --to=iec "$rx")" "$big$reset" "$(numfmt --to=iec "$tx")" "\n" +printf "%b%5sB %b%5sB%b" "" "$(numfmt --to=iec "$rx")" "" "$(numfmt --to=iec "$tx")" "\n" diff --git a/.local/libexec/statusbar/sb-packages b/.local/libexec/statusbar/sb-packages index bd9c78fc6..7187eb4b7 100755 --- a/.local/libexec/statusbar/sb-packages +++ b/.local/libexec/statusbar/sb-packages @@ -1,9 +1,8 @@ #!/bin/sh +. "$HOME/.local/libexec/statusbar/colors" -big="\033[11m" -reset="\033[0m" icon="" num="$(\xbps-install -Sun | grep -c "update")" -[ "$num" -gt 0 ] && printf "%b" "$big$icon$reset $num\n" +[ "$num" -gt 0 ] && printf "%b" "$icon $num\n" exit 0 diff --git a/.local/libexec/statusbar/sb-playerctl b/.local/libexec/statusbar/sb-playerctl index 8086ecd61..ae1045b59 100755 --- a/.local/libexec/statusbar/sb-playerctl +++ b/.local/libexec/statusbar/sb-playerctl @@ -1,13 +1,11 @@ #!/bin/sh - -big="\033[11m" -reset="\033[0m" +. "$HOME/.local/libexec/statusbar/colors" pidof -x sbd-playerctl >/dev/null 2>&1 || "$HOME/.local/libexec/daemons/sbd-playerctl" >/dev/null 2>&1 & -[ "$(playerctl status 2>&1)" = "No players found" ] && printf "%b%b" "$big" "$reset" && exit 1 +[ "$(playerctl status 2>&1)" = "No players found" ] && printf "%b" "" && exit 1 # song="$(playerctl metadata xesam:artist) - $(playerctl metadata xesam:title)" song="$(playerctl metadata xesam:title) - $(playerctl metadata xesam:artist)" [ ${#song} -gt 35 ] && song="$(printf %.35s "$song")…" icon="$(playerctl status | sed "s/Playing//;s/Paused//;s/Stopped/󰓛/;")" -printf "%b" "$big$icon$reset $song" +printf "%b" "$icon $song"