89 lines
1.7 KiB
Bash
Executable File
89 lines
1.7 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
power_prefix="/sys/class/power_supply/"
|
|
[ -d "${power_prefix}sbs-20-000b" ] && bat="sbs-20-000b"
|
|
[ -d "${power_prefix}BAT0" ] && bat="BAT0"
|
|
|
|
[ "$(ps aux | grep pulseaudio | wc -l)" -eq 2 ] && 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"
|
|
}
|
|
|
|
mod_power () {
|
|
[ -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}'
|
|
}
|
|
|
|
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 () {
|
|
left="$(get_mod "bspwm")"
|
|
right="$(get_mod "date_time") $(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
|
|
update_mod date_time
|
|
}
|
|
|
|
tput civis
|
|
|
|
register_sigs
|
|
update_all
|
|
|
|
i=0
|
|
while true; do
|
|
sleep 0.25
|
|
[ "$i" -eq $((29 * 4)) ] && update_all && i=0
|
|
echo_bar
|
|
i="$(($i + 1))"
|
|
done
|