1
0
Fork 0

statusbar cleanup

This commit is contained in:
Luca Bilke 2024-09-24 13:44:14 +02:00
parent d894e6d19f
commit ee74984c0d
12 changed files with 193 additions and 167 deletions

View file

@ -21,3 +21,50 @@ export bgmagenta="background='#BB9AF7$bgalpha'"
export bgcyan="background='#7DCFFF$bgalpha'" export bgcyan="background='#7DCFFF$bgalpha'"
export bggray="background='#414868$bgalpha'" export bggray="background='#414868$bgalpha'"
export bgwhite="background='#C0CAF5$bgalpha'" export bgwhite="background='#C0CAF5$bgalpha'"
meter_bar() {
# shellcheck disable=SC2194
case $1 in
9[0-9] | 100)
color="$fgred"
bar="▉"
;;
8[0-9])
color="$fgorange"
bar="█"
;;
7[0-9])
color="$fgorange"
bar="▇"
;;
6[0-9])
color="$fgorange"
bar="▆"
;;
5[0-9])
color="$fggreen"
bar="▅"
;;
4[0-9])
color="$fggreen"
bar="▄"
;;
3[0-9])
color="$fggreen"
bar="▂"
;;
2[0-9])
color="$fggreen"
bar="▂"
;;
1[0-9])
color="$fggreen"
bar="▁"
;;
0[0-9] | [0-9])
color="$fggreen"
bar=" "
;;
esac
printf "%s:%s" "${color}" "${bar}"
}

View file

@ -1,45 +1,45 @@
#!/bin/sh #!/bin/sh
. "colors" . libsb
[ -z "$(ls /sys/class/power_supply)" ] && exit 0 [ -z "$(ls /sys/class/power_supply)" ] && exit 0
for battery in /sys/class/power_supply/BAT?*; do for battery in /sys/class/power_supply/BAT?*; do
pidof -x sbd-battery >/dev/null 2>&1 || "$HOME/.local/libexec/daemons/sbd-battery" "$battery" >/dev/null 2>&1 & pidof -x sbd-battery >/dev/null 2>&1 || "$HOME/.local/libexec/daemons/sbd-battery" "$battery" >/dev/null 2>&1 &
[ -n "${capacity+x}" ] && printf " " [ -n "${capacity+x}" ] && printf " "
capacity="$(cat "$battery/capacity" 2>&1)" capacity="$(cat "$battery/capacity" 2>&1)"
case "$(cat "$battery/status" 2>&1)" in case "$(cat "$battery/status" 2>&1)" in
"Full") "Full")
icon="󰂄" icon="󰂄"
color="$fgcyan" color="$fgcyan"
;; ;;
"Not charging") "Not charging")
icon="󰁹" icon="󰁹"
color="$fgorange" color="$fgorange"
;; ;;
"Unknown") "Unknown")
icon="󰂑" icon="󰂑"
color="$fgorange" color="$fgorange"
;; ;;
"Charging") "Charging")
icon="󰂄" icon="󰂄"
color="$fgcyan" color="$fgcyan"
;; ;;
"Discharging") "Discharging")
case $capacity in case $capacity in
[0-5]) icon="󰂎" color="$fgred" ;; [0-5]) icon="󰂎" color="$fgred" ;;
[6-9] | 10) icon="󰁺" color="$fgred" ;; [6-9] | 10) icon="󰁺" color="$fgred" ;;
1[1-9] | 20) icon="󰁻" color="$fgred" ;; 1[1-9] | 20) icon="󰁻" color="$fgred" ;;
2[1-9] | 30) icon="󰁼" color="$fgwhite" ;; 2[1-9] | 30) icon="󰁼" color="$fgwhite" ;;
3[1-9] | 40) icon="󰁽" color="$fgwhite" ;; 3[1-9] | 40) icon="󰁽" color="$fgwhite" ;;
4[1-9] | 50) icon="󰁾" color="$fgwhite" ;; 4[1-9] | 50) icon="󰁾" color="$fgwhite" ;;
5[1-9] | 60) icon="󰁿" color="$fgwhite" ;; 5[1-9] | 60) icon="󰁿" color="$fgwhite" ;;
6[1-9] | 70) icon="󰂀" color="$fgwhite" ;; 6[1-9] | 70) icon="󰂀" color="$fgwhite" ;;
7[1-9] | 80) icon="󰂁" color="$fgwhite" ;; 7[1-9] | 80) icon="󰂁" color="$fgwhite" ;;
8[1-9] | 90) icon="󰂂" color="$fgwhite" ;; 8[1-9] | 90) icon="󰂂" color="$fgwhite" ;;
9[1-9] | 100) icon="󰁹" color="$fgwhite" ;; 9[1-9] | 100) icon="󰁹" color="$fgwhite" ;;
esac esac
;; ;;
*) exit 1 ;; *) exit 1 ;;
esac esac
printf "%b" "<span $color>$icon</span>" printf "%b" "<span $color>$icon</span>"
done done

View file

@ -1,5 +1,5 @@
#!/bin/sh #!/bin/sh
. "colors" . libsb
n_cpu=$(grep -c 'cpu[0-9]\+' /proc/stat) n_cpu=$(grep -c 'cpu[0-9]\+' /proc/stat)
cache=$XDG_RUNTIME_DIR/cpubarscache cache=$XDG_RUNTIME_DIR/cpubarscache
@ -28,23 +28,16 @@ for i in $(seq "$n_cpu"); do
delta_idle=$((new_idle - old_idle)) delta_idle=$((new_idle - old_idle))
delta_total=$((new_total - old_total)) delta_total=$((new_total - old_total))
percent=$((((delta_total - delta_idle) * 100 / delta_total) / 10)) percent=$(((delta_total - delta_idle) * 100 / delta_total))
case "$percent" in meter=$(meter_bar "$percent")
0 | 1) color="$fggreen" bar="▁" ;;
2) color="$fggreen" bar="▂" ;;
3 | 4) color="$fggreen" bar="▃" ;;
5) color="$fgorange" bar="▄" ;;
6 | 7) color="$fgorange" bar="▅" ;;
8) color="$fgred" bar="▆" ;;
*) color="$fgred" bar="▇" ;;
esac
color=$(echo "$meter" | cut -d: -f1)
if [ "$color" != "$prevcolor" ]; then if [ "$color" != "$prevcolor" ]; then
$first || printf "%b" "</span>" $first || printf "%b" "</span>"
printf "%b" "<span $color>" printf "%b" "<span $color>"
fi fi
printf "%b" "$bar" printf "%b" "$(echo "$meter" | cut -d: -f2)"
first=false first=false
prevcolor=$color prevcolor=$color

View file

@ -1,5 +1,5 @@
#!/bin/sh #!/bin/sh
. "colors" . libsb
types=${SB_DISK_FS:-ext2,ext3,ext4,xfs,btrfs,vfat} types=${SB_DISK_FS:-ext2,ext3,ext4,xfs,btrfs,vfat}
@ -8,29 +8,22 @@ IFS='
first=true first=true
for mnt in $(findmnt -Py -t "$types"); do for mnt in $(findmnt -Py -t "$types"); do
eval "$mnt" eval "$mnt"
case "$TARGET" in case "$TARGET" in
/var/lib/docker) break ;; /var/lib/docker) break ;;
/) icon="󰙅" ;; /) icon="󰙅" ;;
/home) icon="󰋜" ;; /home) icon="󰋜" ;;
/boot*) icon="󰐥" ;; /boot*) icon="󰐥" ;;
*) icon="" ;; *) icon="" ;;
esac esac
$first || printf " " $first || printf " "
percent=$(df "$TARGET" | awk 'NR != 1 { gsub(/%/, "", $5); printf "%d", $5 / 10 }') percent=$(df "$TARGET" | awk 'NR != 1 { gsub(/%/, "", $5); printf "%d", $5 }')
case "$percent" in
0 | 1) color="$fggreen" bar="▁" ;;
2) color="$fggreen" bar="▂" ;;
3 | 4) color="$fggreen" bar="▃" ;;
5) color="$fggreen" bar="▄" ;;
6 | 7) color="$fggreen" bar="▅" ;;
8) color="$fgorange" bar="▆" ;;
*) color="$fgred" bar="▇" ;;
esac
printf "%b <span %b %b>%b</span>" "${icon}" "${color}" "${bggray}" "${bar}" meter=$(meter_bar "$percent")
first=false printf "%b <span %b %b>%b</span>" "${icon}" "$(echo "$meter" | cut -d: -f1)" "${bggray}" "$(echo "$meter" | cut -d: -f2)"
first=false
done done

View file

@ -1,5 +1,5 @@
#!/bin/sh #!/bin/sh
. "colors" . libsb
# NOTE: This script takes its dwmblocks update signal as an argument so that it can refresh itself (defaults to 5) # 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 # Options can be found at https://wttr.in/:help
@ -11,27 +11,27 @@ weatheropts="?FA"
emojiopts="?FA&format=%c" emojiopts="?FA&format=%c"
getforecast() { getforecast() {
curl -sfL --retry 5 "$url$weatheropts" >"$weatherfile" || return 1 curl -sfL --retry 5 "$url$weatheropts" >"$weatherfile" || return 1
curl -sfL "$url$emojiopts" --retry 5 | sed 's/☀️//;s/☁️//;s/⛅️//;s/⛈//;s/✨//;s/❄️//;s/🌦//;s/🌧//;s/🌨//;s/🌩//;s/🌫//;' | cut -d ' ' -f 1 >"$emojifile" || return 1 curl -sfL "$url$emojiopts" --retry 5 | sed 's/☀️//;s/☁️//;s/⛅️//;s/⛈//;s/✨//;s/❄️//;s/🌦//;s/🌧//;s/🌨//;s/🌩//;s/🌫//;' | cut -d ' ' -f 1 >"$emojifile" || return 1
} }
fresh() { fresh() {
[ -s "$weatherfile" ] && [ "$(stat -c %y "$weatherfile" 2>/dev/null | cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ] [ -s "$weatherfile" ] && [ "$(stat -c %y "$weatherfile" 2>/dev/null | cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ]
} }
readfile() { readfile() {
weather="$(cat "$weatherfile")" weather="$(cat "$weatherfile")"
precipitation="$(echo "$weather" | sed '16q;d' | grep -wo "[0-9]*%" | sort -rn | head -1q)" precipitation="$(echo "$weather" | sed '16q;d' | grep -wo "[0-9]*%" | sort -rn | head -1q)"
highlow="$(echo "$weather" | sed '13q;d' | grep -o "m\\([-+]\\)*[0-9]\\+" | sed 's/[+m]//g' | sort -g | sed -e 1b -e '$!d')" highlow="$(echo "$weather" | sed '13q;d' | grep -o "m\\([-+]\\)*[0-9]\\+" | sed 's/[+m]//g' | sort -g | sed -e 1b -e '$!d')"
emoji="$(cat "$emojifile")" emoji="$(cat "$emojifile")"
} }
output() { output() {
readfile readfile
printf "%b" "$emoji $precipitation <span $fgblue></span> $(echo "$highlow" | cut -d" " -f1)° <span $fgred></span> $(echo "$highlow" | cut -d" " -f2)°\n" printf "%b" "$emoji $precipitation <span $fgblue></span> $(echo "$highlow" | cut -d" " -f1)° <span $fgred></span> $(echo "$highlow" | cut -d" " -f2)°\n"
} }
if fresh; then if fresh; then
output output
else else
# WARN: Not currently used in dwmblocks # WARN: Not currently used in dwmblocks
getforecast && pkill "-RTMIN+5" dwmblocks & getforecast && pkill "-RTMIN+5" dwmblocks &
printf "%b" " Getting Weather\n" printf "%b" " Getting Weather\n"
fi fi

View file

@ -1,76 +1,76 @@
#!/bin/sh #!/bin/sh
. "colors" . libsb
status() { status() {
nmcli --terse device status | awk -v device="$1" -F: '$1 == device { print $3 }' nmcli --terse device status | awk -v device="$1" -F: '$1 == device { print $3 }'
} }
wireless() { wireless() {
if grep -vxq '0x\(1\|9\)003' "$info/flags"; then if grep -vxq '0x\(1\|9\)003' "$info/flags"; then
icon="󰀞" icon="󰀞"
else else
case "$(status "$device")" in case "$(status "$device")" in
connected) connected)
percent=$(awk -v interface="${device}:" '$1==interface { gsub(/[^0-9]/,"",$3); print $3 }' /proc/net/wireless) percent=$(awk -v interface="${device}:" '$1==interface { gsub(/[^0-9]/,"",$3); print $3 }' /proc/net/wireless)
# shellcheck disable=SC2194 # shellcheck disable=SC2194
case 1 in case 1 in
$((percent >= 80))) icon="󰤨" ;; $((percent >= 80))) icon="󰤨" ;;
$((percent >= 60))) icon="󰤥" ;; $((percent >= 60))) icon="󰤥" ;;
$((percent >= 40))) icon="󰤢" ;; $((percent >= 40))) icon="󰤢" ;;
$((percent >= 20))) icon="󰤟" ;; $((percent >= 20))) icon="󰤟" ;;
$((percent >= 0))) icon="󰤯" ;; $((percent >= 0))) icon="󰤯" ;;
esac esac
;; ;;
disconnected) return ;; disconnected) return ;;
*) icon="󰤫" ;; *) icon="󰤫" ;;
esac esac
wireless_status="${wireless_status:-}${icon} ${name} " wireless_status="${wireless_status:-}${icon} ${name} "
fi fi
} }
ethernet() { ethernet() {
case "$(status "$device")" in case "$(status "$device")" in
connected) icon="󰱓" ;; connected) icon="󰱓" ;;
unavailable | disconnected) return ;; unavailable | disconnected) return ;;
*) icon="󰛵" ;; *) icon="󰛵" ;;
esac esac
ethernet_status="${ethernet_status:-}${icon} " ethernet_status="${ethernet_status:-}${icon} "
} }
wireguard() { wireguard() {
wireguard_status="${wireguard_status:-}󰖂 ${name} " wireguard_status="${wireguard_status:-}󰖂 ${name} "
} }
vpn() { vpn() {
vpn_status="${vpn_status:-}󰖂 ${name} " vpn_status="${vpn_status:-}󰖂 ${name} "
} }
fallback() { fallback() {
: :
} }
output() { output() {
printf "%b" "${wireless_status}${ethernet_status}${wireguard_status}${vpn_status}" | sed 's/ $//' printf "%b" "${wireless_status}${ethernet_status}${wireguard_status}${vpn_status}" | sed 's/ $//'
} }
IFS=" IFS="
" "
for x in $(nmcli --terse connection show --active); do for x in $(nmcli --terse connection show --active); do
name="$(echo "$x" | cut -d: -f1)" name="$(echo "$x" | cut -d: -f1)"
type="$(echo "$x" | cut -d: -f3)" type="$(echo "$x" | cut -d: -f3)"
device="$(echo "$x" | cut -d: -f4)" device="$(echo "$x" | cut -d: -f4)"
info="/sys/class/net/${device}" info="/sys/class/net/${device}"
case "$type" in case "$type" in
*wireless) wireless ;; *wireless) wireless ;;
*ethernet) ethernet ;; *ethernet) ethernet ;;
wireguard | vpn) $type ;; wireguard | vpn) $type ;;
*) fallback ;; *) fallback ;;
esac esac
unset name type device info icon unset name type device info icon
done done
output output

View file

@ -1,5 +1,5 @@
#!/bin/sh #!/bin/sh
. "colors" . libsb
cache="${XDG_CACHE_HOME:-$HOME/.cache}/geoip" cache="${XDG_CACHE_HOME:-$HOME/.cache}/geoip"
@ -8,8 +8,8 @@ pub_addr="$(curl -s ipv4.icanhazip.com 2>/dev/null)"
location="$(awk -F: -v ip="$pub_addr" '$1==ip {print $2}' "$cache")" location="$(awk -F: -v ip="$pub_addr" '$1==ip {print $2}' "$cache")"
[ -z "$location" ] && { [ -z "$location" ] && {
location="$(curl -s "https://reallyfreegeoip.org/json/${pub_addr}" | jq -r '.country_name')" location="$(curl -s "https://reallyfreegeoip.org/json/${pub_addr}" | jq -r '.country_name')"
echo "${pub_addr}:${location}" >>"$cache" echo "${pub_addr}:${location}" >>"$cache"
} }
flag="$(awk -v loc="$location" '$0 ~ loc {print $1}' "${XDG_DATA_HOME:-$HOME/.local/share}/emoji")" flag="$(awk -v loc="$location" '$0 ~ loc {print $1}' "${XDG_DATA_HOME:-$HOME/.local/share}/emoji")"

View file

@ -1,14 +1,7 @@
#!/bin/sh #!/bin/sh
. "colors" . libsb
case "$(free -m | awk 'NR==2 { printf "%d", ($3 / $2) * 10 }')" in percent="$(free -m | awk 'NR==2 { printf "%d", ($3 / $2) * 100 }')"
0 | 1) color="$fggreen" bar="▁" ;; meter=$(meter_bar "$percent")
2) color="$fggreen" bar="▂" ;;
3 | 4) color="$fggreen" bar="▃" ;;
5) color="$fgorange" bar="▄" ;;
6 | 7) color="$fgorange" bar="▅" ;;
8) color="$fgred" bar="▆" ;;
*) color="$fgred" bar="▇" ;;
esac
printf "󰘚 <span %s %s>%s</span>" "${bggray}" "${color}" "$bar" printf "󰘚 <span %s %s>%s</span>" "$(echo "$meter" | cut -d: -f1)" "${bggray}" "$(echo "$meter" | cut -d: -f2)"

View file

@ -1,17 +1,17 @@
#!/bin/sh #!/bin/sh
. "colors" . libsb
filter() { filter() {
if mpc 1>/dev/null 2>&1 && [ "$(mpc | wc -l)" -eq 3 ]; then if mpc 1>/dev/null 2>&1 && [ "$(mpc | wc -l)" -eq 3 ]; then
song=$(mpc current -f "%artist% - %title%" | xargs -0) song=$(mpc current -f "%artist% - %title%" | xargs -0)
[ ${#song} -gt 35 ] && song="$(printf %.35s "$song")…" [ ${#song} -gt 35 ] && song="$(printf %.35s "$song")…"
mpc | awk 'NR==2' | grep -q playing && icon="󰏤" || icon="󰐊" mpc | awk 'NR==2' | grep -q playing && icon="󰏤" || icon="󰐊"
echo "$icon $song" echo "$icon $song"
elif mpc 1>/dev/null 2>&1 && [ "$(mpc | wc -l)" -eq 1 ]; then elif mpc 1>/dev/null 2>&1 && [ "$(mpc | wc -l)" -eq 1 ]; then
echo "󰓛" echo "󰓛"
else else
exit 1 exit 1
fi fi
} }
pidof -x sbd-music >/dev/null 2>&1 || "$HOME/.local/libexec/daemons/sbd-music" >/dev/null 2>&1 & pidof -x sbd-music >/dev/null 2>&1 || "$HOME/.local/libexec/daemons/sbd-music" >/dev/null 2>&1 &
filter filter

View file

@ -1,17 +1,17 @@
#!/bin/sh #!/bin/sh
. "colors" . libsb
# TODO: Coloring based on speed # TODO: Coloring based on speed
update() { update() {
sum=0 sum=0
for arg; do for arg; do
read -r i <"$arg" read -r i <"$arg"
sum=$((sum + i)) sum=$((sum + i))
done done
cache=$XDG_RUNTIME_DIR/${1##*/} cache=$XDG_RUNTIME_DIR/${1##*/}
[ -f "$cache" ] && read -r old <"$cache" || old=0 [ -f "$cache" ] && read -r old <"$cache" || old=0
printf "%b" "$sum\n" >"$cache" printf "%b" "$sum\n" >"$cache"
printf "%b" "$((sum - old))\n" printf "%b" "$((sum - old))\n"
} }
rx=$(update /sys/class/net/[ew]*/statistics/rx_bytes) rx=$(update /sys/class/net/[ew]*/statistics/rx_bytes)

View file

@ -1,5 +1,5 @@
#!/bin/sh #!/bin/sh
. "colors" . libsb
icon="" icon=""

View file

@ -1,5 +1,5 @@
#!/bin/sh #!/bin/sh
. "colors" . libsb
pidof -x sbd-playerctl >/dev/null 2>&1 || "$HOME/.local/libexec/daemons/sbd-playerctl" >/dev/null 2>&1 & 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" "" && exit 1 [ "$(playerctl status 2>&1)" = "No players found" ] && printf "%b" "" && exit 1