panel: another rewrite; use dash (smaller memory footprint) + polish

This commit is contained in:
Henrik Lissner 2016-11-05 01:50:03 +01:00
parent bcbb431374
commit 5a66167430
13 changed files with 191 additions and 175 deletions

View file

@ -2,6 +2,8 @@
[ -f ~/.secrets/accounts.sh ] && . ~/.secrets/accounts.sh || exit [ -f ~/.secrets/accounts.sh ] && . ~/.secrets/accounts.sh || exit
ERROR=
get-mail() { get-mail() {
local feed=$(curl -u "$1:$2" --silent https://mail.google.com/mail/feed/atom) local feed=$(curl -u "$1:$2" --silent https://mail.google.com/mail/feed/atom)
if [ "$(echo $feed | grep -c "<fullcount>")" -eq 1 ] if [ "$(echo $feed | grep -c "<fullcount>")" -eq 1 ]
@ -9,6 +11,7 @@ get-mail() {
echo $feed | grep -o "<entry>" | wc -l echo $feed | grep -o "<entry>" | wc -l
else else
>&2 echo "mail.sh: error with $1" >&2 echo "mail.sh: error with $1"
ERROR=1
echo 0 echo 0
fi fi
} }
@ -17,4 +20,6 @@ a=$(get-mail "${MAIL1[USER]}" "${MAIL1[PASS]}")
b=$(get-mail "${MAIL2[USER]}" "${MAIL2[PASS]}") b=$(get-mail "${MAIL2[USER]}" "${MAIL2[PASS]}")
c=$(get-mail "${MAIL3[USER]}" "${MAIL3[PASS]}") c=$(get-mail "${MAIL3[USER]}" "${MAIL3[PASS]}")
echo M$(( $a + $b + $c )) echo -n M$(( $a + $b + $c ))
[[ $ERROR ]] && echo -n !
echo

View file

@ -1,4 +1,4 @@
#!/usr/bin/env bash #!/usr/bin/env dash
while : while :
do do

View file

@ -0,0 +1,14 @@
#!/usr/bin/env dash
# No wifi interface? Abort!
ints=$(find /sys/class/net/*/wireless -type d)
[ -z "$ints" ] && echo "Ix" && exit
# Start watching
while :
do
signal=$(awk 'NR==3 {print $3}' /proc/net/wireless)
echo "I${signal%?}"
# echo "I${signal%?},$(iwgetid --raw)"
sleep 10
done

View file

@ -1,4 +1,4 @@
#!/usr/bin/env bash #!/usr/bin/env dash
checkupdates >/dev/null checkupdates >/dev/null
echo "U$(pacaur -Qu | wc -l)" echo "U$(pacaur -Qu | wc -l)"

View file

@ -1,4 +1,4 @@
#!/usr/bin/env bash #!/usr/bin/env dash
# I expect all volume adjustments to be done through the volume.sh script (in # 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 # os/arch/bin), which will inform lemonbar of changes, so we only need to intialize

View file

@ -1,14 +0,0 @@
#!/usr/bin/env bash
# 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)
echo "I${signal%?}"
# echo "I${signal%?},$(iwgetid --raw)"
sleep 5
done

View file

@ -1,27 +1,24 @@
#!/usr/bin/env bash #!/usr/bin/env dash
if [[ $1 == "--kill" ]] if [ "$1" = "--kill" ]
then then
pkill -f 'bash .+/panel\.sh' pkill -f '^bash .+/panel$'
exit exit
fi fi
CWD="$(cd $(dirname $0) && pwd -P)" CWD="$(cd $(dirname $0) && pwd -P)"
. $CWD/panel_config . $CWD/panel-config
# #
running() { pgrep -f $1 >/dev/null; } running() { pgrep -f $1 >/dev/null; }
cleanup() { rm -rf /tmp/panel-fifo-* && pkill -P $$; }
cleanup() {
[ -e "$PANEL_FIFO" ] && rm -f "$PANEL_FIFO"
pkill -P $$
}
# #
trap cleanup INT TERM QUIT EXIT trap cleanup INT TERM QUIT EXIT
[ -e "$PANEL_FIFO" ] && rm "$PANEL_FIFO" [ -e "$PANEL_FIFO" ] && rm "$PANEL_FIFO"
mkfifo "$PANEL_FIFO" mkfifo "$PANEL_FIFO"
echo "MKFIFO $PANEL_FIFO"
if running lemonbar if running lemonbar
then then
@ -34,24 +31,24 @@ fi
# Bootstrap panel(s) # Bootstrap panel(s)
# #
clock -sf "T%A, %b %d::%I:%M%p" > "$PANEL_FIFO" & clock -sf "T%A, %b %d::%I:%M%p" > "${PANEL_FIFO}" &
xtitle -sf 'X%s' > "$PANEL_FIFO" & xtitle -sf 'X%s' > "${PANEL_FIFO}" &
bspc subscribe report > "$PANEL_FIFO" & bspc subscribe report > "${PANEL_FIFO}" &
pushd $CWD/lemons >/dev/null cd $CWD/lemons >/dev/null
for lemon in *.sh for lemon in *
do do
echo "INIT: $lemon" echo "INIT $lemon"
./$lemon > "$PANEL_FIFO" & ./$lemon >"${PANEL_FIFO}" &
done done
popd >/dev/null cd - >/dev/null
# #
progress-bar() { progress_bar() {
BAR_SIZE=${2:-26} BAR_SIZE=${2:-26}
C1="%{F#FF0000}-%{F-}" C1="%{F${COLOR_6}}-%{F-}"
C2="%{F#555555}-%{F-}" C2="%{F${COLOR_DIM}}-%{F-}"
DELIM="%{F#777777}|%{F-}" DELIM=
echo "$1" | SIZE=$BAR_SIZE CHAR1="$C1" CHAR2="$C2" SEP='' START="$DELIM" END="$DELIM" mkb echo "$1" | SIZE=$BAR_SIZE CHAR1="$C1" CHAR2="$C2" SEP='' START="$DELIM" END="$DELIM" mkb
} }
@ -63,78 +60,83 @@ parse() {
data="${line#?}" data="${line#?}"
case $line in case $line in
# Minimal icons # Minimal icons
U*) updates=" %{F${COLOR[DIM]}}\ue00f%{F-}" U*) updates=" %{F${COLOR_DIM}}$ICON_UPD%{F-}"
if [[ "$data" > 0 ]]; then if [ "$data" -gt 0 ]; then
updates=" %{F${COLOR[2]}}\ue00f$data%{F-}" updates=" %{F${COLOR_2}}$ICON_UPD$data%{F-}"
fi fi
;; ;;
M*) icon="${ICON[mail]}" M*) icon="${ICON_MAIL}"
color="${COLOR_FG}"
if [ "$data" = *! ]
then
data="${data%?}"
color="${COLOR_1}"
fi
case "$data" in case "$data" in
!) mail="%{F${COLOR[3]}}$icon!%{F-}"
;;
[1-9]*) [1-9]*)
mail="%{F${COLOR[1]}}$icon$data%{F-}" mail="$icon$data"
;; ;;
0) mail="%{F${COLOR[DIM]}}$icon%{F-}" 0) mail="$icon"
color="${COLOR_DIM}"
;; ;;
esac esac
mail="%{F$color}$mail%{F-}"
;; ;;
V*) case "$data" in V*) case "$data" in
0) vol=" %{F${COLOR[DIM]}}${ICON[muted]}%{F-}" 0) vol=" %{F${COLOR_DIM}}${ICON_MUTED}%{F-}"
;; ;;
*) vol=" ${ICON[speaker]}" *) vol=" ${ICON_SPEAKER}"
;; ;;
esac esac
;; ;;
# Full segments
I*) # ssid=" ${data#*,}" I*) # ssid=" ${data#*,}"
case "${data%,*}" in case "${data%,*}" in
100|[6-9][0-9]) icon="${ICON[wifi3]} " ;; 100|[6-9][0-9]) icon="${ICON_WIFI3} " ;;
[2-5][0-9]) icon="${ICON[wifi2]} " ;; [2-5][0-9]) icon="${ICON_WIFI2} " ;;
# [1-2][0-9]) icon="${ICON[wifi2]} " ;; x) icon="${ICON_WIFI0}" ;;
x) icon="${ICON[wifioff]}" ;; *) icon="${ICON_WIFI1} " ;;
*) icon="${ICON[wifi1]} " ;;
esac esac
wifi=" $icon" wifi=" $icon"
;; ;;
# Full segments
E*) # TODO ethernet E*) # TODO ethernet
;; ;;
X*) title="$data" X*) xtitle="$data"
;; ;;
T*) datetime=" ${ICON[date]} ${data%::*} ${ICON[time]} ${data#*::}" T*) datetime=" ${ICON_DATE} ${data%::*} ${ICON_TIME} ${data#*::}"
;; ;;
S*) song="" S*) song=""
case "$data" in case "$data" in
P*) icon="${ICON[play]}" ;; P*) icon="%{F${COLOR_2}}${ICON_PLAY}%{F-}" ;;
p*) icon="${ICON[pause]}" ;; p*) icon="%{F${COLOR_4}}${ICON_PAUSE}%{F-}" ;;
*) icon="" ;; *) icon="" ;;
esac esac
if [[ -n $icon ]] if [ -n "$icon" ]
then then
info="${data#?}" info="${data#?}"
title=$(echo "$info" | cut -d'^' -f1) # title=$(echo "$info" | cut -d'^' -f1)
artist=$(echo "$info" | cut -d'^' -f2) # artist=$(echo "$info" | cut -d'^' -f2)
album=$(echo "$info" | cut -d'^' -f3) # album=$(echo "$info" | cut -d'^' -f3)
seek=$(echo "$info" | cut -d'^' -f4) seek=$(echo "$info" | cut -d'^' -f4)
perc=$(echo "$info" | cut -d'^' -f5) perc=$(echo "$info" | cut -d'^' -f5)
song="%{B${COLOR[ALTBG]}} $icon ${seek%/*} $(progress-bar $perc 24) ${seek#*/} %{B-}" # song="$title - $artist"
song="$song $title - $artist" # [ -n "$album" ] && song="$song ($album)"
[[ $album ]] && song="$song ($album)" song="%{B${COLOR_ALTBG}} $icon ${seek%/*} $(progress_bar $perc 16) ${seek#*/} %{B-} "
fi fi
;; ;;
W*) # bspwm's state W*) # bspwm's state
wm="" wm=""
IFS=':' IFS=':'
set -- $data set -- $data
while [[ $# > 0 ]] while [ "$#" -gt 0 ]
do do
id=$1 id=$1
name=${id#???} name=${id#???}
case $id in case $id in
[mM]*) [mM]*)
[[ $num_mon < 2 ]] && shift && continue [ "$num_mon" -lt 2 ] && shift && continue
case $id in case $id in
m*) # monitor m*) # monitor
_FG=$COLOR_MONITOR_FG _FG=$COLOR_MONITOR_FG
@ -174,7 +176,8 @@ parse() {
_BG=$COLOR_FOCUSED_URGENT_BG _BG=$COLOR_FOCUSED_URGENT_BG
;; ;;
esac esac
wm="${wm}%{F$_FG}%{B$_BG}%{A:bspc desktop -f ${id#?}:} ${ICON[$name]:$name} %{A}%{B-}%{F-}" eval "icon=\$ICON_$name"
wm="${wm}%{F$_FG}%{B$_BG}%{A:bspc desktop -f ${id#?}:} ${icon:-$name} %{A}%{B-}%{F-}"
;; ;;
esac esac
shift shift
@ -183,18 +186,19 @@ parse() {
esac esac
echo -e \ echo -e \
"%{l}${wm}${song}" \ "%{l}${wm}${song}" \
"%{c}${xtitle}" \
"%{r}${mail}${updates}${vol}${wifi}${datetime} " "%{r}${mail}${updates}${vol}${wifi}${datetime} "
done done
} }
parse < "$PANEL_FIFO" | \ parse < "${PANEL_FIFO}" | \
lemonbar \ lemonbar \
-a 32 \ -a 32 \
-g x$PANEL_HEIGHT \ -g x$PANEL_HEIGHT \
-f "$PANEL_FONT" \ -f "$PANEL_FONT" \
-f "$ICON_FONT" \ -f "$ICON_FONT" \
-F "${COLOR[FG]}" \ -F "$COLOR_FG" \
-B "${COLOR[BG]}" \ -B "$COLOR_BG" \
| sh & | sh &
wait wait

View file

@ -0,0 +1,70 @@
PANEL_FIFO=/tmp/panel-fifo
# Customization ########################
PANEL_HEIGHT=25
PANEL_FONT="terminus:size=9:antialias=false"
ICON_FONT="siji:size=9:antialias=false"
# Colors
for i in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
do
eval "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_NONE="#00${bg#?}"
COLOR_MONITOR_FG="#8dbcdf"
COLOR_MONITOR_BG="${COLOR_BG}"
COLOR_FOCUSED_MONITOR_FG="#b1d0e8"
COLOR_FOCUSED_MONITOR_BG="${COLOR_NONE}"
COLOR_FREE_FG="${COLOR_DIM}"
COLOR_FREE_BG="${COLOR_BG}"
COLOR_FOCUSED_FREE_FG="${COLOR_0}"
COLOR_FOCUSED_FREE_BG="${COLOR_NONE}"
COLOR_OCCUPIED_FG="#a7a5a5"
COLOR_OCCUPIED_BG="${COLOR_BG}"
COLOR_FOCUSED_OCCUPIED_FG="#d6d3d2"
COLOR_FOCUSED_OCCUPIED_BG="${COLOR_NONE}"
COLOR_URGENT_FG="${COLOR_1}"
COLOR_URGENT_BG="${COLOR_BG}"
COLOR_FOCUSED_URGENT_FG="#501d1f"
COLOR_FOCUSED_URGENT_BG="${COLOR_NONE}"
# bspwm desktop icons
ICON_DESKTOP=""
ICON_CODE=""
ICON_ART=""
ICON_WEB=""
ICON_CHAT=""
ICON_FILE=""
ICON_MUSIC=""
ICON_MEDIA=""
ICON_GAMES="" # ghost
# clock icons
ICON_DATE=""
ICON_TIME=""
# wireless icons
ICON_WIFI0=""
ICON_WIFI1=""
ICON_WIFI2=""
ICON_WIFI3=""
# media player icons
ICON_PLAY=""
ICON_PAUSE=""
ICON_STOP=""
ICON_MUTED=""
ICON_SPEAKER=""
# misc
ICON_MAIL=""
ICON_UPD=""

View file

@ -0,0 +1,36 @@
#!/usr/bin/env bash
CWD=$(cd $(dirname $0) && pwd -P)
if [ -t 0 ]
then
if [ "$#" -eq 0 ]
then
>&2 echo "Usage: panel_update.sh [LEMON_TO_UPDATE]"
exit 1
fi
case "$1" in
:*) LEMON="$CWD/lemons/${1#?}"
if [ ! -f "$LEMON" ]
then
>&2 echo "Couldn't find that lemon ($1)"
exit 2
fi
. $CWD/panel-config
pkill -f "bash \./lemons/${1#?}"
pushd "$CWD" >/dev/null
$LEMON > "$PANEL_FIFO" &
popd >/dev/null
;;
*) echo "$@" | $0
;;
esac
else
. $CWD/panel-config
while read -r line
do
echo "$line" > "$PANEL_FIFO" &
done
fi

View file

@ -0,0 +1,2 @@
#!/usr/bin/env bash
$(dirname $0)/panel-notify :updates

View file

@ -1,77 +0,0 @@
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[games]="\ue140" # ghost
# clock icons
ICON[date]="\ue267"
ICON[time]="\ue016"
# wireless icons
# ICON[wifioff]="\ue21a"
# ICON[wifi1]="\ue25e"
# ICON[wifi2]="\ue25f"
# ICON[wifi3]="\ue260"
# ICON[wifi4]="\ue261"
ICON[wifioff]="\ue217"
ICON[wifi1]="\ue218"
ICON[wifi2]="\ue219"
ICON[wifi3]="\ue21a"
# media player icons
ICON[play]="\ue058"
ICON[pause]="\ue09b"
ICON[stop]="\ue099"
ICON[muted]="\ue04f"
ICON[speaker]="\ue05d"
# misc
ICON[mail]="\ue070"

View file

@ -1,2 +0,0 @@
#!/usr/bin/env bash
/home/hlissner/.config/panel/panel_update.sh updates

View file

@ -1,22 +0,0 @@
#!/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
. $CWD/panel_config
pkill -f "bash \./lemons/$1\.sh"
pushd "$CWD" >/dev/null
./lemons/$1.sh > "$PANEL_FIFO" &
popd >/dev/null