Skip to content

Instantly share code, notes, and snippets.

@noahmorrison
Last active July 8, 2022 19:30
Show Gist options
  • Save noahmorrison/c5768673e5ada4017b10 to your computer and use it in GitHub Desktop.
Save noahmorrison/c5768673e5ada4017b10 to your computer and use it in GitHub Desktop.
Bar for bspwm
#!/bin/sh
sc () {
if [ $COLOR = "bar" ] ; then
case $2 in
bold) case $1 in
black) echo "%{F#FF000000}";;
red) echo "%{F#FFFF0000}";;
green) echo "%{F#FF00FF00}";;
yellow) echo "%{F#FFFF4500}";;
blue) echo "%{F#FF1E90FF}";;
magenta) echo "%{F#FF8F00FF}";;
cyan) echo "%{F#FF536878}";;
white) echo "%{F#FFF8F8FF}";;
esac;;
*) case $1 in
black) echo "%{F#FF242424}";;
red) echo "%{F#FFFF0090}";;
green) echo "%{F#FFA7FC00}";;
yellow) echo "%{F#FFFF5A36}";;
blue) echo "%{F#FF007BA7}";;
magenta) echo "%{F#FF9966CC}";;
cyan) echo "%{F#FF91A3B0}";;
white) echo "%{F#FFF0EAD6}";;
reset) echo "%{F-}";;
esac;;
esac
fi
}
main () {
bat_info=`acpi`
bat_stat=`echo $bat_info | grep -o -P -e "\w+(?=,)"`
bat_levl=`echo $bat_info | grep -o -P -e "\d+(?=%)"`
if [ "Discharging" = "$bat_stat" ] ; then
output=`sc yellow`"[v]"
elif [ "Charging" = "$bat_stat" ] ; then
output=`sc green`"[^]"
else
output=`sc cyan`"[|]"
fi
if [ $bat_levl -gt 75 ] ; then
bat_colr=`sc green bold`
elif [ $bat_levl -gt 30 ] ; then
bat_colr=`sc cyan`
else
bat_colr=`sc red bold`
fi
output="$output $bat_colr $bat_levl%"
echo -e $output
}
while [[ $# > 1 ]]; do
key="$1"
shift
case $key in
-c|--color)
COLOR="$1"
case $COLOR in
bar|term) ;;
*) echo "invalid color, $COLOR, bar or term"
exit 1 ;;
esac
shift ;;
esac
done
COLOR=${COLOR:-none}
main
#!/bin/sh
COLOR_DEFAULT_BG="#FF000000"
COLOR_DEFAULT_FG="#FFCCCCCC"
COLOR_UNDERLINE="#FFFF4444"
COLOR_OCCUPIED_WORKSPACE="#FFaaaaaa"
COLOR_FREE_WORKSPACE="#FF444444"
COLOR_URGENT_WORKSPACE="#FFff2222"
S_L="" # status left
S_M="" # status middle
S_R="" # status right
parse_bspc_status () {
S_L="%{U$COLOR_UNDERLINE}"
while IFS=':' read -ra ADDR; do
for item in ${ADDR[@]}; do
case $item in
M*) continue ;;
O*) COLOR=$COLOR_OCCUPIED_WORKSPACE
OBJ='%{+u}'
;;
o*) COLOR=$COLOR_OCCUPIED_WORKSPACE
OBJ=''
;;
F*) COLOR=$COLOR_FREE_WORKSPACE
OBJ='%{+u}'
;;
f*) COLOR=$COLOR_FREE_WORKSPACE
OBJ=''
;;
U*) COLOR=$COLOR_URGENT_WORKSPACE
OBJ='%{+u}'
;;
u*) COLOR=$COLOR_URGENT_WORKSPACE
OBJ=''
;;
L*) continue ;;
esac
S_L="${S_L} %{F$COLOR}$OBJ${item:1}%{F-}%{-u}"
done
done <<< $1
}
update_sys_info () {
div="%{F#FF242424}|%{F-}"
date=`date "+%{F#FF555555}%a %{F#FF888888}%F %{F#FFcccccc}%l:%M %P%{F-}"`
bat=`battery --color bar`
vol=`get_vol`
S_R="${vol} $div ${bat} $div ${date} "
}
get_vol () {
perc=`amixer get Master | egrep -o "[0-9]+%"`
mute=`amixer get Master | egrep -o "(\[off\])"`
if [ "$mute" = "[off]" ] ; then
echo "%{F#FF242424}${perc}"
else
echo "%{F#FF007BA7}$perc"
fi
}
parse () {
while read -t 10 -r line || true; do
update_sys_info
if [ -n "$line" ]; then
parse_bspc_status ${line:1}
fi
echo "%{l}${S_L}%{c}${S_M}%{r}${S_R}"
done
}
if [ "$1" = "update" ] ; then
bspc desktop -n `bspc query -D -d focused`
exit 0
fi
bspc control --subscribe | parse | bar -B $COLOR_DEFAULT_BG -F $COLOR_DEFAULT_FG -b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment