From 8a3162d9831a0ed2bb3e59b6419e8a7a318b9d42 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Mon, 7 Nov 2016 01:40:02 +0100 Subject: [PATCH] panel: general polish + refactoring --- os/arch/.config/panel/lemons/battery | 36 ++++++++++- os/arch/.config/panel/lemons/mail | 22 +++++-- os/arch/.config/panel/lemons/music | 34 ++++++++-- os/arch/.config/panel/lemons/network | 17 ++++- os/arch/.config/panel/lemons/updates | 13 +++- os/arch/.config/panel/lemons/volume | 18 ++++-- os/arch/.config/panel/panel | 95 ++++------------------------ os/arch/.config/panel/panel-config | 27 +------- 8 files changed, 129 insertions(+), 133 deletions(-) diff --git a/os/arch/.config/panel/lemons/battery b/os/arch/.config/panel/lemons/battery index 8e61dcc9..0beec2b3 100755 --- a/os/arch/.config/panel/lemons/battery +++ b/os/arch/.config/panel/lemons/battery @@ -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 diff --git a/os/arch/.config/panel/lemons/mail b/os/arch/.config/panel/lemons/mail index f93b01c0..f610d3a8 100755 --- a/os/arch/.config/panel/lemons/mail +++ b/os/arch/.config/panel/lemons/mail @@ -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 "" | 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-}" diff --git a/os/arch/.config/panel/lemons/music b/os/arch/.config/panel/lemons/music index 7b28d612..e57d3442 100755 --- a/os/arch/.config/panel/lemons/music +++ b/os/arch/.config/panel/lemons/music @@ -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 diff --git a/os/arch/.config/panel/lemons/network b/os/arch/.config/panel/lemons/network index b778a8cb..f4194944 100755 --- a/os/arch/.config/panel/lemons/network +++ b/os/arch/.config/panel/lemons/network @@ -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 diff --git a/os/arch/.config/panel/lemons/updates b/os/arch/.config/panel/lemons/updates index 58512900..4c2936c8 100755 --- a/os/arch/.config/panel/lemons/updates +++ b/os/arch/.config/panel/lemons/updates @@ -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 diff --git a/os/arch/.config/panel/lemons/volume b/os/arch/.config/panel/lemons/volume index 89370d70..f2acff71 100755 --- a/os/arch/.config/panel/lemons/volume +++ b/os/arch/.config/panel/lemons/volume @@ -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" diff --git a/os/arch/.config/panel/panel b/os/arch/.config/panel/panel index bbd91231..3d200dee 100755 --- a/os/arch/.config/panel/panel +++ b/os/arch/.config/panel/panel @@ -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" - ;; - 0) mail="$icon" - color="${COLOR_DIM}" - ;; - esac - mail="%{F$color}$mail%{F-}" + M*) mail=" $data" ;; - V*) case "$data" in - 0) vol=" %{F${COLOR_DIM}}${ICON_MUTED}%{F-}" - ;; - *) vol=" ${ICON_SPEAKER}" - ;; - esac + V*) vol=" $data" ;; - 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="" diff --git a/os/arch/.config/panel/panel-config b/os/arch/.config/panel/panel-config index e794e48d..e7559947 100644 --- a/os/arch/.config/panel/panel-config +++ b/os/arch/.config/panel/panel-config @@ -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="" +