221 lines
7.2 KiB
Bash
Executable file
221 lines
7.2 KiB
Bash
Executable file
#!/usr/bin/env dash
|
|
|
|
if [ "$1" = "--kill" ]
|
|
then
|
|
pkill -f '^dash .+/panel$'
|
|
exit
|
|
fi
|
|
|
|
CWD="$(cd $(dirname $0) && pwd -P)"
|
|
. $CWD/panel-config
|
|
|
|
|
|
#
|
|
running() { pgrep -f $1 >/dev/null; }
|
|
cleanup() { rm -rf "$PANEL_FIFO"; pkill -P $$; }
|
|
|
|
#
|
|
trap cleanup INT TERM QUIT EXIT
|
|
[ -e "$PANEL_FIFO" ] && rm "$PANEL_FIFO"
|
|
mkfifo "$PANEL_FIFO"
|
|
echo "MKFIFO $PANEL_FIFO"
|
|
|
|
if running lemonbar
|
|
then
|
|
2>&1 echo "Lemonbar already running"
|
|
exit 1
|
|
fi
|
|
|
|
|
|
#
|
|
# Bootstrap panel(s)
|
|
#
|
|
|
|
clock -sf "T%A, %b %d::%I:%M%p" > "${PANEL_FIFO}" &
|
|
xtitle -sf 'X%s' > "${PANEL_FIFO}" &
|
|
bspc subscribe report > "${PANEL_FIFO}" &
|
|
|
|
cd $CWD/lemons >/dev/null
|
|
for lemon in *
|
|
do
|
|
echo "INIT $lemon"
|
|
./$lemon >"${PANEL_FIFO}" &
|
|
done
|
|
cd - >/dev/null
|
|
|
|
#
|
|
progress_bar() {
|
|
BAR_SIZE=${2:-26}
|
|
C1="%{F${COLOR_6}}-%{F-}"
|
|
C2="%{F${COLOR_DIM}}-%{F-}"
|
|
DELIM=
|
|
|
|
echo "$1" | SIZE=$BAR_SIZE CHAR1="$C1" CHAR2="$C2" SEP='' START="$DELIM" END="$DELIM" mkb
|
|
}
|
|
|
|
parse() {
|
|
num_mon=$(bspc query -M | wc -l)
|
|
while read -r line
|
|
do
|
|
data="${line#?}"
|
|
case $line in
|
|
# Minimal icons
|
|
B*) perc="${data%\%:*}"
|
|
state="${data#*:}"
|
|
case "${perc}" in
|
|
100|9[0-9]) icon="${ICON_BAT9}" ;;
|
|
8[0-9]) icon="${ICON_BAT8}" ;;
|
|
7[0-9]) icon="${ICON_BAT7}" ;;
|
|
6[0-9]) icon="${ICON_BAT6}" ;;
|
|
5[0-9]) icon="${ICON_BAT5}" ;;
|
|
4[0-9]) icon="${ICON_BAT4}" ;;
|
|
3[0-9]) icon="%{F$COLOR_3}${ICON_BAT3}%{F-}" ;;
|
|
2[0-9]) icon="%{F$COLOR_3}${ICON_BAT2}%{F-}" ;;
|
|
1[0-9]) icon="%{F$COLOR_1}${ICON_BAT1}%{F-}" ;;
|
|
*) icon="%{F$COLOR_1}${ICON_BAT0}%{F-}" ;;
|
|
esac
|
|
[ "$state" = "1" ] && battery="${icon}${ICON_BATAC}" || battery="${icon} "
|
|
;;
|
|
U*) updates=" %{F${COLOR_DIM}}$ICON_UPD%{F-}"
|
|
if [ "$data" -gt 0 ]; then
|
|
updates=" %{F${COLOR_2}}$ICON_UPD$data%{F-}"
|
|
fi
|
|
;;
|
|
M*) icon="${ICON_MAIL}"
|
|
color="${COLOR_FG}"
|
|
if [ "$data" = *! ]
|
|
then
|
|
data="${data%?}"
|
|
color="${COLOR_1}"
|
|
fi
|
|
case "$data" in
|
|
[1-9]*)
|
|
mail="$icon$data"
|
|
;;
|
|
0) mail="$icon"
|
|
color="${COLOR_DIM}"
|
|
;;
|
|
esac
|
|
mail="%{F$color}$mail%{F-}"
|
|
;;
|
|
V*) case "$data" in
|
|
0) vol=" %{F${COLOR_DIM}}${ICON_MUTED}%{F-}"
|
|
;;
|
|
*) vol=" ${ICON_SPEAKER}"
|
|
;;
|
|
esac
|
|
;;
|
|
I*) # ssid=" ${data#*,}"
|
|
case "${data%,*}" in
|
|
100|[6-9][0-9]) icon="${ICON_WIFI3} " ;;
|
|
[2-5][0-9]) icon="${ICON_WIFI2} " ;;
|
|
x) icon="${ICON_WIFI0}" ;;
|
|
*) icon="${ICON_WIFI1} " ;;
|
|
esac
|
|
wifi=" $icon"
|
|
;;
|
|
|
|
# Full segments
|
|
E*) # TODO ethernet
|
|
;;
|
|
X*) xtitle="$data"
|
|
;;
|
|
T*) datetime=" ${ICON_DATE} ${data%::*} ${ICON_TIME} ${data#*::}"
|
|
;;
|
|
S*) song=""
|
|
case "$data" in
|
|
P*) icon="%{F${COLOR_2}}${ICON_PLAY}%{F-}" ;;
|
|
p*) icon="%{F${COLOR_4}}${ICON_PAUSE}%{F-}" ;;
|
|
*) icon="" ;;
|
|
esac
|
|
if [ -n "$icon" ]
|
|
then
|
|
info="${data#?}"
|
|
# title=$(echo "$info" | cut -d'^' -f1)
|
|
# artist=$(echo "$info" | cut -d'^' -f2)
|
|
# album=$(echo "$info" | cut -d'^' -f3)
|
|
seek=$(echo "$info" | cut -d'^' -f4)
|
|
perc=$(echo "$info" | cut -d'^' -f5)
|
|
|
|
# song="$title - $artist"
|
|
# [ -n "$album" ] && song="$song ($album)"
|
|
song="%{B${COLOR_ALTBG}} $icon ${seek%/*} $(progress_bar $perc 16) ${seek#*/} %{B-} "
|
|
fi
|
|
;;
|
|
W*) # bspwm's state
|
|
wm=""
|
|
IFS=':'
|
|
set -- $data
|
|
while [ "$#" -gt 0 ]
|
|
do
|
|
id=$1
|
|
name=${id#???}
|
|
case $id in
|
|
[mM]*)
|
|
[ "$num_mon" -lt 2 ] && shift && continue
|
|
case $id in
|
|
m*) # monitor
|
|
_FG=$COLOR_MONITOR_FG
|
|
_BG=$COLOR_MONITOR_BG
|
|
;;
|
|
M*) # focused monitor
|
|
_FG=$COLOR_FOCUSED_MONITOR_FG
|
|
_BG=$COLOR_FOCUSED_MONITOR_BG
|
|
;;
|
|
esac
|
|
wm="${wm}%{F$_FG}%{B$_BG}%{A:bspc monitor -f ${id}:} ${name} %{A}%{B-}%{F-}"
|
|
;;
|
|
[fFoOuU]*)
|
|
case $id in
|
|
f*) # free desktop
|
|
_FG=$COLOR_FREE_FG
|
|
_BG=$COLOR_FREE_BG
|
|
;;
|
|
F*) # focused free desktop
|
|
_FG=$COLOR_FOCUSED_FREE_FG
|
|
_BG=$COLOR_FOCUSED_FREE_BG
|
|
;;
|
|
o*) # occupied desktop
|
|
_FG=$COLOR_OCCUPIED_FG
|
|
_BG=$COLOR_OCCUPIED_BG
|
|
;;
|
|
O*) # focused occupied desktop
|
|
_FG=$COLOR_FOCUSED_OCCUPIED_FG
|
|
_BG=$COLOR_FOCUSED_OCCUPIED_BG
|
|
;;
|
|
u*) # urgent desktop
|
|
_FG=$COLOR_URGENT_FG
|
|
_BG=$COLOR_URGENT_BG
|
|
;;
|
|
U*) # focused urgent desktop
|
|
_FG=$COLOR_FOCUSED_URGENT_FG
|
|
_BG=$COLOR_FOCUSED_URGENT_BG
|
|
;;
|
|
esac
|
|
eval "icon=\$ICON_$name"
|
|
wm="${wm}%{F$_FG}%{B$_BG}%{A:bspc desktop -f ${id#?}:} ${icon:-$name} %{A}%{B-}%{F-}"
|
|
;;
|
|
esac
|
|
shift
|
|
done
|
|
;;
|
|
esac
|
|
echo -e \
|
|
"%{l}${wm}${song}" \
|
|
"%{c}${xtitle}" \
|
|
"%{r}${battery}${mail}${updates}${vol}${wifi}${datetime} "
|
|
done
|
|
}
|
|
|
|
parse < "${PANEL_FIFO}" | \
|
|
lemonbar \
|
|
-a 32 \
|
|
-g x$PANEL_HEIGHT \
|
|
-f "$PANEL_FONT" \
|
|
-f "$ICON_FONT" \
|
|
-F "$COLOR_FG" \
|
|
-B "$COLOR_BG" \
|
|
| sh &
|
|
|
|
wait
|