panel: general polish + refactoring

This commit is contained in:
Henrik Lissner 2016-11-07 01:40:02 +01:00
parent e196e2c4e3
commit 8a3162d983
8 changed files with 129 additions and 133 deletions

View file

@ -1,5 +1,7 @@
#!/usr/bin/env dash
. $(dirname $0)/../panel-config
# No guarantee that it will be called BAT0, but it suits my purposes.
if ! command -v acpi >/dev/null
then
@ -12,11 +14,41 @@ then
exit
fi
ICON_BAT0=""
ICON_BAT1=""
ICON_BAT2=""
ICON_BAT3=""
ICON_BAT4=""
ICON_BAT5=""
ICON_BAT6=""
ICON_BAT7=""
ICON_BAT8=""
ICON_BAT9=""
ICON_BATAC=""
while :
do
BAT=$(acpi --battery)
PERC=$(echo $BAT | cut -d, -f2)
echo -n "B${PERC#?}:"
echo "$BAT" | grep charging >/dev/null && echo "1" || echo "0"
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
if echo "$BAT" | grep charging >/dev/null
then
echo "${icon}${ICON_BATAC}"
else
echo "${icon} "
fi
sleep 15
done

View file

@ -1,8 +1,9 @@
#!/usr/bin/env bash
[ -f ~/.secrets/accounts.sh ] && . ~/.secrets/accounts.sh || exit
. $(dirname $0)/../panel-config
ERROR=
ICON_MAIL=""
get-mail() {
local feed=$(curl -u "$1:$2" --silent https://mail.google.com/mail/feed/atom)
@ -11,7 +12,7 @@ get-mail() {
echo $feed | grep -o "<entry>" | wc -l
else
>&2 echo "mail.sh: error with $1"
ERROR=1
ERROR=!
echo 0
fi
}
@ -20,6 +21,17 @@ a=$(get-mail "${MAIL1[USER]}" "${MAIL1[PASS]}")
b=$(get-mail "${MAIL2[USER]}" "${MAIL2[PASS]}")
c=$(get-mail "${MAIL3[USER]}" "${MAIL3[PASS]}")
echo -n M$(( $a + $b + $c ))
[[ $ERROR ]] && echo -n !
echo
num=$(( $a + $b + $c ))
icon="${ICON_MAIL}"
color=${COLOR_FG}
case "$num" in
[1-9]*)
icon="$icon$num"
;;
0) color="${COLOR_DIM}"
;;
esac
[ -n "$ERROR" ] && color=${COLOR_1}
echo "M%{F$color}$icon%{F-}"

View file

@ -1,24 +1,44 @@
#!/usr/bin/env dash
. $(dirname $0)/../panel-config
ICON_PLAY=""
ICON_PAUSE=""
# ICON_STOP=""
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
}
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)
# 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 " ;;
"[playing]") icon="%{F${COLOR_2}}${ICON_PLAY}%{F-}" ;;
"[paused]") icon="%{F${COLOR_4}}${ICON_PAUSE}%{F-}" ;;
*) icon="" ;;
esac
echo "$title^$artist^$album^$seek^$perc"
if [ -n "$icon" ]
then
# song="$title - $artist"
# [ -n "$album" ] && song="$song ($album)"
echo "%{B${COLOR_ALTBG}} $icon ${seek%/*} $(progress_bar $perc 16) ${seek#*/} %{B-} "
fi
else
echo "S"
fi

View file

@ -1,14 +1,25 @@
#!/usr/bin/env dash
# wireless icons
ICON_WIFI0=""
ICON_WIFI1=""
ICON_WIFI2=""
ICON_WIFI3=""
# No wifi interface? Abort!
ints=$(find /sys/class/net/*/wireless -type d)
[ -z "$ints" ] && echo "Ix" && exit
[ -z "$ints" ] && echo "I${ICON_WIFI0}" && exit
# Start watching
while :
do
# SSID=$(iwgetid --raw)
signal=$(awk 'NR==3 {print $3}' /proc/net/wireless)
echo "I${signal%?}"
# echo "I${signal%?},$(iwgetid --raw)"
case "${signal%?}" in
100|[6-9][0-9]) icon="${ICON_WIFI3}" ;;
[2-5][0-9]) icon="${ICON_WIFI2}" ;;
*) icon="${ICON_WIFI1}" ;;
esac
echo "I$icon"
sleep 10
done

View file

@ -1,4 +1,13 @@
#!/usr/bin/env dash
checkupdates >/dev/null
echo "U$(pacaur -Qu | wc -l)"
. $(dirname $0)/../panel-config
ICON_UPD=""
pkgs="$(checkupdates | wc -l)"
if [ "$pkgs" -gt 0 ]
then
echo "U%{F${COLOR_2}}$ICON_UPD$pkgs%{F-}"
else
echo "U%{F${COLOR_DIM}}$ICON_UPD%{F-}"
fi

View file

@ -4,11 +4,21 @@
# os/arch/bin), which will inform lemonbar of changes, so we only need to intialize
# volume once here.
data=$(amixer get Master)
vol=0
. $(dirname $0)/../panel-config
# media player icons
ICON_MUTED=""
ICON_SPEAKER=""
if echo "$data" | grep '\[on\]' >/dev/null
then
vol=$(echo "$data" | sed -n 's/^.*\[\([0-9]\+\)%.*$/\1/p' | uniq)
case "$vol" in
0) echo "V${ICON_MUTED}"
;;
*) echo "V${ICON_SPEAKER}"
;;
esac
else
echo "V%{F${COLOR_DIM}}${ICON_MUTED}%{F-}"
fi
echo "V$vol"

View file

@ -31,28 +31,17 @@ fi
# Bootstrap panel(s)
#
clock -sf "T%A, %b %d::%I:%M%p" > "${PANEL_FIFO}" &
clock -sf "T${ICON_DATE} %A, %b %d ${ICON_TIME} %I:%M%p" > "${PANEL_FIFO}" &
xtitle -sf 'X%s' > "${PANEL_FIFO}" &
bspc subscribe report > "${PANEL_FIFO}" &
cd $CWD/lemons >/dev/null
for lemon in *
for lemon in $CWD/lemons/*
do
echo "INIT $lemon"
./$lemon >"${PANEL_FIFO}" &
echo "INIT $(basename $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
@ -60,59 +49,15 @@ parse() {
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} "
B*) battery="$data"
;;
U*) updates=" %{F${COLOR_DIM}}$ICON_UPD%{F-}"
if [ "$data" -gt 0 ]; then
updates=" %{F${COLOR_2}}$ICON_UPD$data%{F-}"
fi
U*) updates=" $data"
;;
M*) icon="${ICON_MAIL}"
color="${COLOR_FG}"
if [ "$data" = *! ]
then
data="${data%?}"
color="${COLOR_1}"
fi
case "$data" in
[1-9]*)
mail="$icon$data"
M*) mail=" $data"
;;
0) mail="$icon"
color="${COLOR_DIM}"
V*) vol=" $data"
;;
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"
I*) wifi=" $data"
;;
# Full segments
@ -120,27 +65,9 @@ parse() {
;;
X*) xtitle="$data"
;;
T*) datetime=" ${ICON_DATE} ${data%::*} ${ICON_TIME} ${data#*::}"
T*) datetime=" $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
S*) song="$data "
;;
W*) # bspwm's state
wm=""

View file

@ -54,29 +54,4 @@ 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=""
# battery
ICON_BAT0=""
ICON_BAT1=""
ICON_BAT2=""
ICON_BAT3=""
ICON_BAT4=""
ICON_BAT5=""
ICON_BAT6=""
ICON_BAT7=""
ICON_BAT8=""
ICON_BAT9=""
ICON_BATAC=""