dot_testing/sh/status

99 lines
1.9 KiB
Plaintext
Raw Normal View History

2022-06-18 15:28:59 -05:00
#!/bin/sh
power_prefix="/sys/class/power_supply/"
[ -d "${power_prefix}sbs-20-000b" ] && bat="sbs-20-000b"
2022-07-07 21:28:49 -05:00
[ -d "${power_prefix}BAT0" ] && bat="BAT0"
2022-06-18 15:28:59 -05:00
[ "$(pgrep -c pulseaudio)" -eq 1 ] && ss="pulse" || ss="alsa"
mod_bspwm () {
used_desk=$(bspc query -D -d .occupied --names | tr '\n' ' ')
current_desk=$(bspc query -D -d .focused --names)
final_string=""
current_printed=0
for i in $used_desk; do
[ "$i" = "$current_desk" ] && \
final_string=${final_string}"*$i " && \
current_printed=1 || \
final_string=${final_string}"$i "
done
[ $current_printed -eq 0 ] &&
final_string=${final_string}"*$current_desk "
printf "%s" "$final_string"
}
2022-08-16 20:42:57 -05:00
mod_period () {
nextclass
}
mod_sensors () {
sensors | grep 'Core 0' | awk -F' ' '{print $3}' | tr -d '\n'
}
mod_power () {
2022-07-07 21:28:49 -05:00
[ -z "$bat" ] ||
tr -d '\n' < /sys/class/power_supply/$bat/capacity
}
mod_vol () {
[ "$ss" = "pulse" ] && pactl list sinks | awk -F' ' '$1 == "Volume:" {print "pv" $5}'
[ "$ss" = "alsa" ] && amixer | grep '^ Front' | awk -F'[' '{ORS = ""; print "av" substr($2, 1, 3); exit}'
}
2022-07-04 12:38:02 -05:00
mod_date_time () {
date '+%m%d-%H:%M' | tr '\n' ' '
}
update_mod () {
output="$(eval "mod_$1")"
eval "output_$1=\"$output\""
}
get_mod () {
eval "printf '%s' \${output_$1}"
}
echo_bar () {
2022-07-04 12:38:02 -05:00
left="$(get_mod "bspwm")"
2022-08-16 20:42:57 -05:00
right="$(get_mod "date_time")$(get_mod "period") $(get_mod "sensors") $(get_mod "power") $(get_mod "vol")"
width="$(tput cols)"
rightwidth="${#right}"
# print left side
printf "\033[2J\033[H%s" "$left"
# print right side
printf "\033[1;%if%s" "$((width - rightwidth + 1))" "$right"
}
register_sigs () {
trap "update_mod vol" USR2
trap "update_mod bspwm" USR1
}
update_all () {
update_mod power
update_mod vol
update_mod bspwm
2022-07-04 12:38:02 -05:00
update_mod date_time
2022-08-16 20:42:57 -05:00
update_mod period
update_mod sensors
}
tput civis
register_sigs
2022-07-04 12:38:02 -05:00
update_all
i=0
while true; do
2022-07-04 12:38:02 -05:00
sleep 0.25
[ "$i" -eq $((29 * 4)) ] && update_all && i=0
echo_bar
i="$((i + 1))"
done