2016-11-02 16:58:47 -07:00
|
|
|
#!/usr/bin/env bash
|
2016-10-19 07:56:37 -07:00
|
|
|
|
2016-11-03 10:47:41 -07:00
|
|
|
if [[ $1 == "--kill" ]]
|
|
|
|
then
|
|
|
|
pkill -f 'bash .+/panel\.sh'
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2016-11-02 16:58:47 -07:00
|
|
|
CWD="$(cd $(dirname $0) && pwd -P)"
|
2016-11-03 10:47:41 -07:00
|
|
|
. $CWD/panel_config
|
2016-10-19 07:56:37 -07:00
|
|
|
|
2016-10-31 19:07:23 -07:00
|
|
|
#
|
2016-11-03 10:47:41 -07:00
|
|
|
running() { pgrep -f $1 >/dev/null; }
|
|
|
|
|
|
|
|
cleanup() {
|
|
|
|
[ -e "$PANEL_FIFO" ] && rm -f "$PANEL_FIFO"
|
|
|
|
pkill -P $$
|
|
|
|
}
|
2016-10-31 19:07:23 -07:00
|
|
|
|
2016-11-03 10:47:41 -07:00
|
|
|
#
|
|
|
|
trap cleanup INT TERM QUIT EXIT
|
|
|
|
[ -e "$PANEL_FIFO" ] && rm "$PANEL_FIFO"
|
|
|
|
mkfifo "$PANEL_FIFO"
|
|
|
|
|
|
|
|
if running lemonbar
|
2016-11-02 16:58:47 -07:00
|
|
|
then
|
2016-11-03 10:47:41 -07:00
|
|
|
2>&1 echo "Lemonbar already running"
|
|
|
|
exit 1
|
2016-11-02 16:58:47 -07:00
|
|
|
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" &
|
2016-10-31 19:07:23 -07:00
|
|
|
|
2016-11-02 16:58:47 -07:00
|
|
|
pushd $CWD/lemons >/dev/null
|
|
|
|
for lemon in *.sh
|
|
|
|
do
|
|
|
|
echo "INIT: $lemon"
|
|
|
|
./$lemon > "$PANEL_FIFO" &
|
|
|
|
done
|
|
|
|
popd >/dev/null
|
|
|
|
|
|
|
|
#
|
|
|
|
progress-bar() {
|
|
|
|
BAR_SIZE=${2:-26}
|
|
|
|
C1="%{F#FF0000}-%{F-}"
|
|
|
|
C2="%{F#555555}-%{F-}"
|
|
|
|
DELIM="%{F#777777}|%{F-}"
|
|
|
|
|
|
|
|
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
|
2016-10-31 19:07:23 -07:00
|
|
|
do
|
2016-11-02 16:58:47 -07:00
|
|
|
data="${line#?}"
|
|
|
|
case $line in
|
|
|
|
# Minimal icons
|
|
|
|
U*) updates=" %{F${COLOR[DIM]}}\ue00f%{F-}"
|
|
|
|
if [[ "$data" > 0 ]]; then
|
2016-11-03 10:47:41 -07:00
|
|
|
updates=" %{F${COLOR[2]}}\ue00f$data%{F-}"
|
2016-11-02 16:58:47 -07:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
M*) icon="${ICON[mail]}"
|
|
|
|
case "$data" in
|
|
|
|
!) mail="%{F${COLOR[3]}}$icon!%{F-}"
|
|
|
|
;;
|
|
|
|
[1-9]*)
|
|
|
|
mail="%{F${COLOR[1]}}$icon$data%{F-}"
|
|
|
|
;;
|
|
|
|
0) mail="%{F${COLOR[DIM]}}$icon%{F-}"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
V*) case "$data" in
|
2016-11-03 10:47:41 -07:00
|
|
|
0) vol=" %{F${COLOR[DIM]}}${ICON[muted]}%{F-}"
|
2016-11-02 16:58:47 -07:00
|
|
|
;;
|
2016-11-03 10:47:41 -07:00
|
|
|
*) vol=" ${ICON[speaker]}"
|
2016-11-02 16:58:47 -07:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
|
|
|
|
# Full segments
|
2016-11-03 10:47:41 -07:00
|
|
|
I*) # ssid=" ${data#*,}"
|
2016-11-02 16:58:47 -07:00
|
|
|
case "${data%,*}" in
|
2016-11-03 10:47:41 -07:00
|
|
|
100|[6-9][0-9]) icon="${ICON[wifi3]} " ;;
|
|
|
|
[2-5][0-9]) icon="${ICON[wifi2]} " ;;
|
|
|
|
# [1-2][0-9]) icon="${ICON[wifi2]} " ;;
|
2016-11-02 16:58:47 -07:00
|
|
|
x) icon="${ICON[wifioff]}" ;;
|
2016-11-03 10:47:41 -07:00
|
|
|
*) icon="${ICON[wifi1]} " ;;
|
2016-11-02 16:58:47 -07:00
|
|
|
esac
|
2016-11-03 10:47:41 -07:00
|
|
|
wifi=" $icon"
|
2016-11-02 16:58:47 -07:00
|
|
|
;;
|
|
|
|
E*) # TODO ethernet
|
|
|
|
;;
|
|
|
|
X*) title="$data"
|
|
|
|
;;
|
|
|
|
T*) datetime=" ${ICON[date]} ${data%::*} ${ICON[time]} ${data#*::}"
|
|
|
|
;;
|
|
|
|
S*) song=""
|
|
|
|
case "$data" in
|
|
|
|
P*) icon="${ICON[play]}" ;;
|
|
|
|
p*) icon="${ICON[pause]}" ;;
|
|
|
|
*) 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="%{B${COLOR[ALTBG]}} $icon ${seek%/*} $(progress-bar $perc 24) ${seek#*/} %{B-}"
|
|
|
|
song="$song $title - $artist"
|
|
|
|
[[ $album ]] && song="$song ($album)"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
W*) # bspwm's state
|
|
|
|
wm=""
|
|
|
|
IFS=':'
|
|
|
|
set -- $data
|
|
|
|
while [[ $# > 0 ]]
|
|
|
|
do
|
|
|
|
id=$1
|
|
|
|
name=${id#???}
|
|
|
|
case $id in
|
|
|
|
[mM]*)
|
|
|
|
[[ $num_mon < 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
|
|
|
|
wm="${wm}%{F$_FG}%{B$_BG}%{A:bspc desktop -f ${id#?}:} ${ICON[$name]:$name} %{A}%{B-}%{F-}"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
echo -e \
|
|
|
|
"%{l}${wm}${song}" \
|
2016-11-03 10:47:41 -07:00
|
|
|
"%{r}${mail}${updates}${vol}${wifi}${datetime} "
|
2016-10-31 19:07:23 -07:00
|
|
|
done
|
2016-11-02 16:58:47 -07:00
|
|
|
}
|
2016-10-31 19:07:23 -07:00
|
|
|
|
2016-11-02 16:58:47 -07:00
|
|
|
parse < "$PANEL_FIFO" | \
|
|
|
|
lemonbar \
|
|
|
|
-a 32 \
|
|
|
|
-g x$PANEL_HEIGHT \
|
|
|
|
-f "$PANEL_FONT" \
|
|
|
|
-f "$ICON_FONT" \
|
|
|
|
-F "${COLOR[FG]}" \
|
|
|
|
-B "${COLOR[BG]}" \
|
|
|
|
| sh &
|
2016-10-19 07:56:37 -07:00
|
|
|
|
2016-11-02 16:58:47 -07:00
|
|
|
wait
|