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

View file

@ -1,5 +1,5 @@
#!/bin/sh
. "colors"
. libsb
n_cpu=$(grep -c 'cpu[0-9]\+' /proc/stat)
cache=$XDG_RUNTIME_DIR/cpubarscache
@ -28,23 +28,16 @@ for i in $(seq "$n_cpu"); do
delta_idle=$((new_idle - old_idle))
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
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
meter=$(meter_bar "$percent")
color=$(echo "$meter" | cut -d: -f1)
if [ "$color" != "$prevcolor" ]; then
$first || printf "%b" "</span>"
printf "%b" "<span $color>"
fi
printf "%b" "$bar"
printf "%b" "$(echo "$meter" | cut -d: -f2)"
first=false
prevcolor=$color

View file

@ -1,5 +1,5 @@
#!/bin/sh
. "colors"
. libsb
types=${SB_DISK_FS:-ext2,ext3,ext4,xfs,btrfs,vfat}
@ -8,29 +8,22 @@ IFS='
first=true
for mnt in $(findmnt -Py -t "$types"); do
eval "$mnt"
case "$TARGET" in
/var/lib/docker) break ;;
/) icon="󰙅" ;;
/home) icon="󰋜" ;;
/boot*) icon="󰐥" ;;
*) icon="" ;;
esac
eval "$mnt"
case "$TARGET" in
/var/lib/docker) break ;;
/) icon="󰙅" ;;
/home) icon="󰋜" ;;
/boot*) icon="󰐥" ;;
*) icon="" ;;
esac
$first || printf " "
$first || printf " "
percent=$(df "$TARGET" | awk 'NR != 1 { gsub(/%/, "", $5); printf "%d", $5 / 10 }')
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
percent=$(df "$TARGET" | awk 'NR != 1 { gsub(/%/, "", $5); printf "%d", $5 }')
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

View file

@ -1,5 +1,5 @@
#!/bin/sh
. "colors"
. libsb
# 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
@ -11,27 +11,27 @@ weatheropts="?FA"
emojiopts="?FA&format=%c"
getforecast() {
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 --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
}
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() {
weather="$(cat "$weatherfile")"
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')"
emoji="$(cat "$emojifile")"
weather="$(cat "$weatherfile")"
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')"
emoji="$(cat "$emojifile")"
}
output() {
readfile
printf "%b" "$emoji $precipitation <span $fgblue></span> $(echo "$highlow" | cut -d" " -f1)° <span $fgred></span> $(echo "$highlow" | cut -d" " -f2)°\n"
readfile
printf "%b" "$emoji $precipitation <span $fgblue></span> $(echo "$highlow" | cut -d" " -f1)° <span $fgred></span> $(echo "$highlow" | cut -d" " -f2)°\n"
}
if fresh; then
output
output
else
# WARN: Not currently used in dwmblocks
getforecast && pkill "-RTMIN+5" dwmblocks &
printf "%b" " Getting Weather\n"
# WARN: Not currently used in dwmblocks
getforecast && pkill "-RTMIN+5" dwmblocks &
printf "%b" " Getting Weather\n"
fi

View file

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

View file

@ -1,5 +1,5 @@
#!/bin/sh
. "colors"
. libsb
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")"
[ -z "$location" ] && {
location="$(curl -s "https://reallyfreegeoip.org/json/${pub_addr}" | jq -r '.country_name')"
echo "${pub_addr}:${location}" >>"$cache"
location="$(curl -s "https://reallyfreegeoip.org/json/${pub_addr}" | jq -r '.country_name')"
echo "${pub_addr}:${location}" >>"$cache"
}
flag="$(awk -v loc="$location" '$0 ~ loc {print $1}' "${XDG_DATA_HOME:-$HOME/.local/share}/emoji")"

View file

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

View file

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

View file

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

View file

@ -1,5 +1,5 @@
#!/bin/sh
. "colors"
. libsb
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