2022-06-18 15:28:59 -05:00
|
|
|
#!/bin/sh
|
|
|
|
|
2022-07-04 02:00:59 -05:00
|
|
|
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
|
|
|
|
2022-11-27 11:04:53 -06:00
|
|
|
[ "$(pgrep -c pulseaudio)" -eq 1 ] && ss="pulse" || ss="alsa"
|
2022-07-04 02:00:59 -05:00
|
|
|
|
|
|
|
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'
|
|
|
|
}
|
|
|
|
|
2022-07-04 02:00:59 -05:00
|
|
|
mod_power () {
|
2022-07-07 21:28:49 -05:00
|
|
|
[ -z "$bat" ] ||
|
2022-07-04 02:00:59 -05:00
|
|
|
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' ' '
|
2022-07-04 02:00:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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")"
|
2022-07-04 02:00:59 -05:00
|
|
|
|
|
|
|
width="$(tput cols)"
|
|
|
|
rightwidth="${#right}"
|
|
|
|
|
|
|
|
# print left side
|
|
|
|
printf "\033[2J\033[H%s" "$left"
|
|
|
|
|
|
|
|
# print right side
|
2022-11-27 11:04:53 -06:00
|
|
|
printf "\033[1;%if%s" "$((width - rightwidth + 1))" "$right"
|
2022-07-04 02:00:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2022-07-04 02:00:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
tput civis
|
|
|
|
|
|
|
|
register_sigs
|
2022-07-04 12:38:02 -05:00
|
|
|
update_all
|
2022-07-04 02:00:59 -05:00
|
|
|
|
|
|
|
i=0
|
|
|
|
while true; do
|
2022-07-04 12:38:02 -05:00
|
|
|
sleep 0.25
|
|
|
|
[ "$i" -eq $((29 * 4)) ] && update_all && i=0
|
2022-07-04 02:00:59 -05:00
|
|
|
echo_bar
|
2022-11-27 11:04:53 -06:00
|
|
|
i="$((i + 1))"
|
2022-07-04 02:00:59 -05:00
|
|
|
done
|