1
0
Fork 0

rework printfs in statusbar scripts for better compatibility

This commit is contained in:
Luca Bilke 2023-05-24 18:33:43 +02:00
parent e820e6cdef
commit d1f31bb8b2
11 changed files with 73 additions and 44 deletions

View File

@ -1,10 +1,10 @@
#!/bin/sh #!/bin/sh
red="\e[31m" red="\033[31m"
orange="\e[33m" orange="\033[33m"
cyan="\e[36m" cyan="\033[36m"
green="\e[32m" green="\033[32m"
white="\e[37m" white="\033[37m"
reset="\e[0m" reset="\033[0m"
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 || sbd-battery "$battery" >/dev/null 2>&1 & pidof -x sbd-battery >/dev/null 2>&1 || sbd-battery "$battery" >/dev/null 2>&1 &
[ -n "${capacity+x}" ] && printf " " [ -n "${capacity+x}" ] && printf " "
@ -65,5 +65,5 @@ for battery in /sys/class/power_supply/BAT?*; do
;; ;;
*) exit 1 ;; *) exit 1 ;;
esac esac
printf "$color%s$reset %d" "$icon" "$capacity" printf "%b" "$color$icon$reset $capacity"
done && printf "\\n" done && printf "\\n"

View File

@ -1,3 +1,3 @@
#!/bin/sh #!/bin/sh
# TODO: Add color # TODO: Add color
sensors | awk '/Core 0/ {print "\e[11m🌡\e[10m" $3}' sensors | awk '/Core 0/ {print "\033[11m🌡\033[10m" $3}'

View File

@ -1,9 +1,17 @@
#!/bin/sh #!/bin/sh
reset="\033[0m"
normal="\033[10m"
big="\033[11m"
red="\033[31m"
green="\033[32m"
orange="\033[33m"
cache=/tmp/cpubarscache cache=/tmp/cpubarscache
stats=$(awk '/cpu[0-9]+/ {printf "%d %d %d\n", substr($1,4), ($2 + $3 + $4 + $5), $5 }' /proc/stat) stats=$(awk '/cpu[0-9]+/ {printf "%d %d %d\n", substr($1,4), ($2 + $3 + $4 + $5), $5 }' /proc/stat)
[ ! -f $cache ] && echo "$stats" >"$cache" [ ! -f $cache ] && echo "$stats" >"$cache"
old=$(cat "$cache") old=$(cat "$cache")
printf "\e[11m﬙\e[10m " printf "%b" "$big﬙$normal "
echo "$stats" | while read -r row; do echo "$stats" | while read -r row; do
id=${row%% *} id=${row%% *}
rest=${row#* } rest=${row#* }
@ -12,15 +20,15 @@ echo "$stats" | while read -r row; do
case "$(echo "$old" | awk '{if ($1 == id) case "$(echo "$old" | awk '{if ($1 == id)
printf "%d\n", (1 - (idle - $3) / (total - $2))*100 /12.5}' \ printf "%d\n", (1 - (idle - $3) / (total - $2))*100 /12.5}' \
id="$id" total="$total" idle="$idle")" in id="$id" total="$total" idle="$idle")" in
"0") printf "\e[32m▁" ;; "0") printf "%b" "$green▁" ;;
"1") printf "\e[32m▂" ;; "1") printf "%b" "$green▂" ;;
"2") printf "\e[32m▃" ;; "2") printf "%b" "$green▃" ;;
"3") printf "\e[33m▄" ;; "3") printf "%b" "$orange▄" ;;
"4") printf "\e[33m▅" ;; "4") printf "%b" "$orange▅" ;;
"5") printf "\e[33m▆" ;; "5") printf "%b" "$orange▆" ;;
"6" | "7" | "8") printf "\e[31m▇" ;; "6" | "7" | "8") printf "%b" "$red▇" ;;
esac esac
done done
printf "\e[0m\n" printf "%b" "$reset\n"
echo "$stats" >"$cache" echo "$stats" >"$cache"

View File

@ -1,5 +1,9 @@
#!/bin/sh #!/bin/sh
# $1 should be drive mountpoint, otherwise assumed /. # $1 should be drive mountpoint, otherwise assumed /.
reset="\033[0m"
big="\033[11m"
location=${1:-/} location=${1:-/}
[ -d "$location" ] || exit [ -d "$location" ] || exit
printf "\e[11m\e[10m %s\n" "$(df -h "$location" | awk ' /[0-9]/ {print $3 "/" $2}')" printf "%b" "$big$reset $(df -h "$location" | awk ' /[0-9]/ {print $3 "/" $2}')\n"

View File

@ -3,6 +3,12 @@
# 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
reset="\033[0m"
big="\033[11m"
verybig="\033[12m"
red="\033[31m"
blue="\033[34m"
weatherfile="$XDG_CACHE_HOME/weatherreport" weatherfile="$XDG_CACHE_HOME/weatherreport"
emojifile="$XDG_CACHE_HOME/weatheremoji" emojifile="$XDG_CACHE_HOME/weatheremoji"
url="wttr.in/$LOCATION" url="wttr.in/$LOCATION"
@ -17,19 +23,19 @@ 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 "\e[12m%s\e[10m %s \e[34;11m\e[0m %s° \e[31;11m\e[0m %s°\n" "$emoji" "$precipitation" $highlow printf "%b" "$verybig$emoji$reset $precipitation $big$blue$reset $(echo $highlow | cut -d" " -f1)° $big$red$reset $(echo $highlow | cut -d" " -f2)°\n"
} }
if fresh; then if fresh; then
output output
else else
getforecast && pkill -RTMIN+${1:-5} dwmblocks & getforecast && pkill -RTMIN+${1:-5} dwmblocks &
printf " Getting Weather\n" printf "%b" "$big$reset Getting Weather\n"
fi fi

View File

@ -1,11 +1,14 @@
#!/bin/sh #!/bin/sh
shift="" shift=""
reset="\033[0m"
big="\033[11m"
if ls /sys/class/net/w*/operstate 1>/dev/null 2>&1; then if ls /sys/class/net/w*/operstate 1>/dev/null 2>&1; then
for w in /sys/class/net/w*/; do 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:]")" 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:]")" grep -vxq '0x1003' "$w/flags" && wifi_icon="" || wifi_icon="$(sed "s/up/直/;s/down/睊/;s/dormant/睊/" $w/operstate | tr -d "[:space:]")"
printf "$shift\e[11m%s\e[10m %s" "$wifi_icon" "$percent" printf "%b" "$shift$big$wifi$icon$reset $percent"
shift=" " shift=" "
done done
fi fi
@ -13,16 +16,16 @@ fi
if ls /sys/class/net/e*/operstate 1>/dev/null 2>&1; then if ls /sys/class/net/e*/operstate 1>/dev/null 2>&1; then
for e in /sys/class/net/e*/operstate; do for e in /sys/class/net/e*/operstate; do
if_icon="$(sed "s/down//;s/up//" $e)" if_icon="$(sed "s/down//;s/up//" $e)"
printf "$shift\e[11m%s\e[10m" "$if_icon" printf "%b" "$shift$big$if_icon$reset"
shift=" " shift=" "
done done
fi fi
if ls /sys/class/net/tun*/operstate 1>/dev/null 2>&1; then if ls /sys/class/net/tun*/operstate 1>/dev/null 2>&1; then
for _ in /sys/class/net/tun*/operstate; do for _ in /sys/class/net/tun*/operstate; do
printf "$shift\e[11m%s\e[10m" "嬨" printf "%b" "$shift$big嬨$reset"
shift=" " shift=" "
done done
fi fi
printf "\n" printf "%b" "\n"

View File

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
big="\e[11m" big="\033[11m"
reset="\e[10m" reset="\033[0m"
update() { update() {
sum=0 sum=0
@ -11,9 +11,10 @@ update() {
done done
cache=/tmp/${1##*/} cache=/tmp/${1##*/}
[ -f "$cache" ] && read -r old <"$cache" || old=0 [ -f "$cache" ] && read -r old <"$cache" || old=0
printf %d\\n "$sum" >"$cache" printf "%b" "$sum\n" >"$cache"
printf %d\\n $((sum - old)) printf "%b" "$((sum - old))\n"
} }
rx=$(update /sys/class/net/[ew]*/statistics/rx_bytes) rx=$(update /sys/class/net/[ew]*/statistics/rx_bytes)
tx=$(update /sys/class/net/[ew]*/statistics/tx_bytes) tx=$(update /sys/class/net/[ew]*/statistics/tx_bytes)
printf "$big$reset%5sB $big$reset%5sB\\n" $(numfmt --to=iec "$rx" "$tx") printf "%b%5sB %b%5sB%b" "$big$reset" "$(numfmt --to=iec "$rx")" "$big$reset" "$(numfmt --to=iec "$tx")" "\n"

View File

@ -1,10 +1,12 @@
#!/bin/sh #!/bin/sh
icon="\e[11m\e[10m" big="\033[11m"
reset="\033[0m"
icon=""
if command -v pacman 1>/dev/null 2>&1; then if command -v pacman 1>/dev/null 2>&1; then
num="$(pacman -Qu | grep -Fcv "[ignored]")" num="$(pacman -Qu | grep -Fcv "[ignored]")"
[ "$num" -gt 0 ] && printf "%b %i" "$icon" "$num" [ "$num" -gt 0 ] && printf "%b" "$big$icon$reset$num"
fi fi
if command -v apt 1>/dev/null 2>&1; then if command -v apt 1>/dev/null 2>&1; then
@ -15,5 +17,5 @@ if command -v apt 1>/dev/null 2>&1; then
out="$out$i/" out="$out$i/"
done done
[ -n "$updates_available" ] && printf "%b %s" "$icon" "$(echo "$out" | sed 's/\/$//')" [ -n "$updates_available" ] && printf "%b" "$big$icon$reset $(echo "$out" | sed 's/\/$//')"
fi fi

View File

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
big="\e[11m" big="\033[11m"
reset="\e[10m" reset="\033[0m"
pidof -x sbd-playerctl >/dev/null 2>&1 || sbd-playerctl >/dev/null 2>&1 & pidof -x sbd-playerctl >/dev/null 2>&1 || 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ﱙ%b" "$big" "$reset" && exit 1

View File

@ -1,4 +1,7 @@
#!/bin/sh #!/bin/sh
big="\033[11m"
reset="\033[0m"
# Prints the current volume or ﱝ if muted. # Prints the current volume or ﱝ if muted.
[ "$(pamixer --get-mute)" = true ] && echo "\e[11mﱝ\e[10m" && exit [ "$(pamixer --get-mute)" = true ] && echo "\e[11mﱝ\e[10m" && exit
vol="$(pamixer --get-volume)" vol="$(pamixer --get-volume)"
@ -12,6 +15,6 @@ elif [ "$vol" -gt "0" ]; then
elif [ "$vol" -eq "0" ]; then elif [ "$vol" -eq "0" ]; then
icon="" icon=""
else else
printf "\e[11m\e[10m " && exit printf "%b%b " "\e[11m" "\e[0m" && exit
fi fi
printf "\e[11m%s\e[10m %s\n" "$icon" "$vol" printf "%b" "$big$icon$reset $vol\n"

View File

@ -1,3 +1,5 @@
#!/bin/sh #!/bin/sh
# pidof -x sbd-xkbmap >/dev/null 2>&1 || sbd-xkbmap >/dev/null 2>&1 & # pidof -x sbd-xkbmap >/dev/null 2>&1 || sbd-xkbmap >/dev/null 2>&1 &
printf "\e[11m\e[10m %s\n" "$(setxkbmap -query | grep -oP '(layout|variant):\s*\K\w+' | sed ':a;N;s/\n/:/')" big="\033[11m"
reset="\033[0m"
printf "%b" "$big$reset $(setxkbmap -query | grep -oP '(layout|variant):\s*\K\w+' | sed ':a;N;s/\n/:/')\n"