lemonbar: major refactor; polish bar

This commit is contained in:
Henrik Lissner 2016-11-03 00:58:47 +01:00
parent f56ceb724b
commit 8ee8f365da
17 changed files with 345 additions and 237 deletions

View file

@ -1,3 +0,0 @@
#!/usr/bin/env bash
bspc subscribe report > "$PANEL_FIFO" &

View file

@ -1,6 +0,0 @@
#!/usr/bin/env bash
date_icon="\ue267"
clock_icon="\ue016"
clock -sf "T${date_icon} %A, %b %d::${clock_icon} %I:%M %p"

View file

@ -0,0 +1,23 @@
#!/usr/bin/env bash
[ -f ~/.secrets/accounts.sh ] && . ~/.secrets/accounts.sh || exit
feed=$(curl -u "${MAIL_USER}:${MAIL_PASS}" --silent https://mail.google.com/mail/feed/atom)
con=$(echo $feed | grep -c "<fullcount>")
num=$(echo $feed | grep -o "<entry>" | wc -l)
if [ "$con" -eq 1 ]
then
# if [ "$num" -gt 0 ]; then
# oldnum=0
# [ -f /tmp/newmail ] && oldnum=$(cat /tmp/newmail)
# echo "$num" > /tmp/newmail
# if [ "$num" -ne "$oldnum" ]
# then
# notify-send 'New email'
# fi
# fi
echo "M$num"
else
echo "M!"
fi

View file

@ -0,0 +1,26 @@
# Not meant to be run directly
while :
do
output=$(mpc --format ";%title%;%artist%;%album%")
if echo $output | grep "^;" 2>&1 >/dev/null
then
title=$(echo "$output" | head -1 | cut -d';' -f2)
artist=$(echo "$output" | head -1 | cut -d';' -f3)
album=$(echo "$output" | head -1 | cut -d';' -f4)
seek=$(echo "$output" | awk 'NR==2 {print $3}')
perc=$(echo "$output" | awk 'NR==2 {print $4}' | tr -d '()')
state=$(echo "$output" | awk 'NR==2 {print $1}')
case "$state" in
"[playing]") echo -n "SP" ;;
"[paused]") echo -n "Sp" ;;
*) echo -n "S " ;;
esac
echo "$title^$artist^$album^$seek^$perc"
else
echo "S"
fi
sleep 1
done

View file

@ -1,7 +1,3 @@
#!/usr/bin/env bash
while :
do
echo "U"$(checkupdates | wc -l)
sleep 3600
done
echo "U$(checkupdates | wc -l)"

View file

@ -1,7 +1,8 @@
#!/usr/bin/env bash
muted="\ue202"
speaker="\ue203"
# I expect all volume adjustments to be done through the volume.sh script (in
# os/arch/bin), which will inform lemonbar of changes, so we only need to intialize
# volume once here.
data=$(amixer get Master)
vol=0
@ -10,10 +11,4 @@ then
vol=$(echo "$data" | sed -n 's/^.*\[\([0-9]\+\)%.*$/\1/p' | uniq)
fi
case "$vol" in
0) text="%{F$COLOR_FREE_FG}${muted}%{F-}"
;;
*) text="${speaker} ${vol}%"
;;
esac
echo "V%{A:volume.sh toggle:} ${text} %{A}"
echo "V$vol"

View file

@ -1,27 +1,13 @@
#!/usr/bin/env bash
wifioff="\ue21a"
wifi0="\ue25d"
wifi1="\ue25e"
wifi2="\ue25f"
wifi3="\ue260"
wifi4="\ue261"
# No wifi interface? Abort!
ints=$(awk -F "/" 'FNR==NR { wire[$5]++; next } { split(FILENAME, state, "/"); if (state[5] in wire && $1 == "up") print state[5] }' <(find /sys/class/net/*/wireless -type d) $(find /sys/class/net/*/operstate ! -type d))
[ -z "$ints" ] && echo "Ix" && exit
# Start watching
while :
do
signal=$(awk 'NR==3 {print $3}' /proc/net/wireless)
if [ -n "$signal" ]
then
icon=$wifi0
case "$signal" in
100|[6-9][0-9]*) icon=$wifi4 ;;
[4-5][0-9]*) icon=$wifi3 ;;
[2-3][0-9]*) icon=$wifi2 ;;
*) icon=$wifi1 ;;
esac
echo "I$icon $(iwgetid -r)"
else
echo "I%{F$COLOR_FREE_FG}${wifioff}%{F-} "
fi
echo "I${signal%?},$(iwgetid --raw)"
sleep 5
done

View file

@ -1,52 +1,199 @@
#!/usr/bin/env dash
#!/usr/bin/env bash
# trap "trap - TERM; kill 0" INT TERM QUIT EXIT
CWD="$(cd $(dirname $0) && pwd -P)"
#
PANEL_FIFO=/tmp/panel-fifo
PWD=$(dirname $0)
THEME="hax"
LEMONBAR="$(pgrep -cx lemonbar)"
. $CWD/panel_config
# trap "trap - TERM; [ -e "$PANEL_FIFO" ] && rm "$PANEL_FIFO"; kill 0" INT TERM QUIT EXIT
. $PWD/themes/$THEME.sh
if [ "$#" -eq 0 ]; then
[ -e "$PANEL_FIFO" ] && rm "$PANEL_FIFO"
mkfifo "$PANEL_FIFO"
if [ "$LEMONBAR" -gt 0 ]
if [ -t 0 ]
then
if [ "$(pgrep -cx lemonbar)" -gt 0 ]
then
echo "Lemonbar already running"
2>&1 echo "Lemonbar already running"
exit
fi
# Load all lemons (components)
for comp in $PWD/lemons/*.sh
else
if pgrep lemonbar >/dev/null; then
# redirect stdin to fifo
[ -e "$PANEL_FIFO" ] || mkfifo "$PANEL_FIFO"
while read -r line
do
echo "INIT: $(basename $comp)"
. "$comp" > "$PANEL_FIFO" &
echo $line > "$PANEL_FIFO" &
done
else
2>&1 echo "Lemonbar isn't running"
fi
exit
fi
#
# Bootstrap panel(s)
#
$PWD/panel_parse.sh $THEME < "$PANEL_FIFO" | \
#
# 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" &
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
do
data="${line#?}"
case $line in
# Minimal icons
U*) updates=" %{F${COLOR[DIM]}}\ue00f%{F-}"
if [[ "$data" > 0 ]]; then
updates=" %{F${COLOR[2]}}\ue00f$data%{F-} "
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
0) vol="%{F${COLOR[DIM]}}${ICON[muted]}%{F-}"
;;
*) vol="${ICON[speaker]}"
;;
esac
;;
# Full segments
I*) ssid=" ${data#*,}"
case "${data%,*}" in
100|[6-9][0-9]) icon="${ICON[wifi4]}$ssid" ;;
[4-5][0-9]) icon="${ICON[wifi3]}$ssid" ;;
[2-3][0-9]) icon="${ICON[wifi2]}$ssid" ;;
[0-9]|1[0-9]) icon="${ICON[wifi1]}$ssid" ;;
x) icon="${ICON[wifioff]}" ;;
*) icon="${ICON[wifi0]}$ssid" ;;
esac
wifi=" $icon "
;;
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}" \
"%{r}${updates}${mail}${vol}${wifi}${datetime} "
done
}
parse < "$PANEL_FIFO" | \
lemonbar \
-a 32 \
-g x$PANEL_HEIGHT \
-f "$PANEL_FONT" \
-f "$ICON_FONT" \
-F "$COLOR_DEFAULT_FG" \
-B "$COLOR_DEFAULT_BG" \
-F "${COLOR[FG]}" \
-B "${COLOR[BG]}" \
| sh &
wait
elif [ -e "$PANEL_FIFO" ] && [ "$LEMONBAR" -gt 0 ]
then
if [ -f "$PWD/lemons/$1.sh" ]
then
. "$PWD/lemons/$1.sh" > "$PANEL_FIFO" &
fi
fi
wait

View file

@ -0,0 +1,74 @@
PANEL_FIFO=/tmp/panel-fifo
# Customization ########################
PANEL_HEIGHT=24
PANEL_FONT="terminus:size=9:antialias=false"
ICON_FONT="siji:size=9:antialias=false"
# Colors
declare -A COLOR
END=15
for ((i=0;i<=END;i++)); do
COLOR[$i]=$(xrdb -query | awk "/^\*\.color$i:/ {print \$2}")
done
BG="$(xrdb -query | awk '/^\*\.background:/ {print $2}')"
FG="$(xrdb -query | awk '/^\*\.foreground:/ {print $2}')"
# FG="#bbc2cf"
# BG="#e022252c"
COLOR[FG]="$FG"
COLOR[BG]="#e0${BG#?}"
COLOR[HL]="#185b75"
COLOR[DIM]="#155872"
COLOR[ALTBG]="#FF${BG#?}"
COLOR_MONITOR_FG="#8dbcdf"
COLOR_MONITOR_BG="${COLOR[BG]}"
COLOR_FOCUSED_MONITOR_FG="#b1d0e8"
COLOR_FOCUSED_MONITOR_BG="${COLOR[BG]}"
COLOR_FREE_FG="${COLOR[DIM]}"
COLOR_FREE_BG="${COLOR[BG]}"
COLOR_FOCUSED_FREE_FG="${COLOR[0]}"
COLOR_FOCUSED_FREE_BG="#00000000"
COLOR_OCCUPIED_FG="#a7a5a5"
COLOR_OCCUPIED_BG="${COLOR[BG]}"
COLOR_FOCUSED_OCCUPIED_FG="#d6d3d2"
COLOR_FOCUSED_OCCUPIED_BG="#00000000"
COLOR_URGENT_FG="${COLOR[1]}"
COLOR_URGENT_BG="${COLOR[BG]}"
COLOR_FOCUSED_URGENT_FG="#501d1f"
COLOR_FOCUSED_URGENT_BG="#d5443e"
COLOR_STATE_FG="#89b09c"
COLOR_STATE_BG="${COLOR[BG]}"
declare -A ICON
# bspwm desktop icons
ICON[desktop]="\ue1d7"
ICON[code]="\ue1ec"
ICON[art]="\ue1c7"
ICON[web]="\ue26d"
ICON[chat]="\ue19f"
ICON[file]="\ue1e1"
ICON[music]="\ue1a6"
ICON[misc]="\ue140"
# clock icons
ICON[date]="\ue267"
ICON[time]="\ue016"
# wireless icons
ICON[wifioff]="\ue21a"
ICON[wifi0]="\ue25d"
ICON[wifi1]="\ue25e"
ICON[wifi2]="\ue25f"
ICON[wifi3]="\ue260"
ICON[wifi4]="\ue261"
# media player icons
ICON[play]="\ue058"
ICON[pause]="\ue09b"
ICON[stop]="\ue099"
ICON[muted]="\ue202"
ICON[speaker]="\ue203"
# misc
ICON[mail]="\ue070"

View file

@ -1,104 +0,0 @@
#!/usr/bin/env bash
theme="$1"
. $(dirname $0)/themes/${theme}.sh
declare -A ICONS
ICONS[desktop]="\ue1d7"
ICONS[code]="\ue1ec"
ICONS[art]="\ue1c7"
ICONS[web]="\ue26d"
ICONS[chat]="\ue19f"
ICONS[file]="\ue1e1"
ICONS[music]="\ue1a6"
ICONS[misc]="\ue140"
num_mon=$(bspc query -M | wc -l)
while read -r line
do
data="${line#?}"
case $line in
E*) # TODO ethernet
;;
T*) # clock output
date=" ${data%::*} "
clock=" ${data#*::} "
;;
I*) # wifi
wifi=" $data "
;;
M*) # TODO mail
mail=" \ue1a8 2 "
;;
S*) # TODO current song
playing=" \ue1a6 ... "
;;
B*) # TODO bluetooth
bt="\ue00b"
;;
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#?}:} ${ICONS[$name]:$name} %{A}%{B-}%{F-}"
;;
esac
shift
done
;;
U*) # updates
updates=" \ue00f $data updates "
;;
V*) # volume
vol="$data"
;;
esac
echo -e "%{l}${wm}${playing}%{r}${mail} ${wifi} ${date} ${clock} ${bt}${vol}"
done

View file

@ -0,0 +1,21 @@
#!/usr/bin/env bash
if [ "$#" -eq 0 ]
then
>&2 echo "Usage: panel_update.sh [LEMON_TO_UPDATE]"
exit 1
fi
CWD=$(cd $(dirname $0) && pwd -P)
LEMON="$CWD/lemons/$1.sh"
if [ ! -f "$LEMON" ]
then
>&2 echo "Couldn't find that lemon ($1)"
exit 2
fi
pkill -f "bash \./$1\.sh"
pushd $CWD/lemons >/dev/null
./$1.sh | ../panel.sh &
popd >/dev/null

View file

@ -1,31 +0,0 @@
#!/bin/bash
PANEL_HEIGHT=24
PANEL_FONT="gohufont:size=11:antialias=false"
ICON_FONT="siji:size=9:antialias=false"
# Colors
FG="#bbc2cf" # 1a6582
BG="#e022252c"
HIGHLIGHT="#00185b75"
COLOR_DEFAULT_FG=$FG
COLOR_DEFAULT_BG=$BG
COLOR_MONITOR_FG="#8dbcdf"
COLOR_MONITOR_BG=$BG
COLOR_FOCUSED_MONITOR_FG="#b1d0e8"
COLOR_FOCUSED_MONITOR_BG=$BG
COLOR_FREE_FG="#155872"
COLOR_FREE_BG=$BG
COLOR_FOCUSED_FREE_FG="#000000"
COLOR_FOCUSED_FREE_BG=$HIGHLIGHT
COLOR_OCCUPIED_FG="#a7a5a5"
COLOR_OCCUPIED_BG=$BG
COLOR_FOCUSED_OCCUPIED_FG="#d6d3d2"
COLOR_FOCUSED_OCCUPIED_BG=$HIGHLIGHT
COLOR_URGENT_FG="#f15d66"
COLOR_URGENT_BG=$BG
COLOR_FOCUSED_URGENT_FG="#501d1f"
COLOR_FOCUSED_URGENT_BG="#d5443e"
COLOR_STATE_FG="#89b09c"
COLOR_STATE_BG=$BG

View file

@ -1,11 +0,0 @@
#!/usr/bin/bash
FIFO=/tmp/panel-fifo
if [[ ! -p $FIFO ]]
then
>&2 echo "FIFO not initialized"
exit
fi
echo "$@" > "$FIFO" &

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash
if [[ $# == 0 ]]
if [[ $# = 0 ]]
then
data=$(amixer get Master)
vol=$(echo "$data" | sed -n 's/^.*\[\([0-9]\+\)%.*$/\1/p' | uniq)
@ -21,9 +21,4 @@ case "$COMMAND" in
esac
# Report to lemonbar, if active
if amixer get Master | grep '\[off\]' >/dev/null
then
panel_notify.sh "V0"
else
panel_notify.sh "V$vol"
fi
~/.config/panel/panel_update.sh volume