commit b33260add3cad2d9daf9d91c09b0c247de6f0176
parent 044776d7d61713b4dda63ff33b2853dec1a4718f
Author: mcol <mcol@posteo.net>
Date: Thu, 17 Jan 2019 19:49:03 +0000
splits modules into separate files; replace underscore spaces with lemonbar offset
Diffstat:
15 files changed, 468 insertions(+), 366 deletions(-)
diff --git a/modules b/modules
@@ -1,302 +0,0 @@
-#!/bin/bash
-#----------------------------------------------------------------------------------
-# modules
-#----------------------------------------------------------------------------------
-
-
-_i3() {
- # This could be made better if needed
- while true; do
- current=$((($(xprop -root _NET_CURRENT_DESKTOP | awk '{print $3}') + 1)))
- total=$(xprop -root _NET_NUMBER_OF_DESKTOPS | awk '{print $3}')
- output="i3="
-
- for i in $(seq $total)
- do
- if [[ $i == $current ]]; then
- output="${output}%{B$highlight}${pad}$i${pad}%{B-}"
- else
- output="${output}${pad}$i${pad}"
- fi
- done
- echo ${output} > "$fifo"
- sleep 0.3
- done
-}
-
-
-bspwm_draw() {
- output=""
- desktop=1
- IFS=':' read -a array <<< $(bspc wm --get-status)
- for item in "${array[@]}"
- do
- name=${item#?}
- desk=""
- case $item in
- O*) # focussed occupied
- desk="%{B$bspwm_focussed_bg}%{F$bspwm_focussed_fg}${bspwm_pad}${name}${bspwm_pad}%{F-}%{B-}"
- ;;
- F*) # focussed free
- desk="%{B$bspwm_focussed_bg}%{F$bspwm_focussed_fg}${bspwm_pad}${name}${bspwm_pad}%{F-}%{B-}"
- ;;
- U*) # focussed urgent
- desk="%{B$bspwm_focussed_bg}%{F$bspwm_focussed_fg}${bspwm_pad}${name}${bspwm_pad}%{F-}%{B-}"
- ;;
- o*) # unfocussed occupied
- desk="%{B$bspwm_unfocussed_occupied_bg}%{F$bspwm_unfocussed_occupied_fg}${bspwm_pad}${name}${bspwm_pad}%{F-}%{B-}"
- ;;
- f*) # unfocussed free
- desk="%{B$bspwm_unfocussed_free_bg}%{F$bspwm_unfocussed_free_fg}${bspwm_pad}${name}${bspwm_pad}%{F-}%{B-}"
- ;;
- u*) # unfocussed urgent
- desk="%{B$bspwm_unfocussed_urgent_bg}%{F$bspwm_unfocussed_urgent_fg}${bspwm_pad}{$name}${bspwm_pad}%{F-}%{B-}"
- ;;
- *) # anything else
- continue
- ;;
- esac
- output="${output}%{A:bspc desktop -f ^$desktop:}${desk}%{A}"
- (( desktop += 1 ))
- done
- echo "bspwm='${output}'" > "$fifo"
-}
-
-
-bspwm_draw_multimonitor() {
- num_monitors=$1
- monitor=0
- output=""
- desktop=1
- IFS=':' read -a array <<< $(bspc wm --get-status)
- for item in "${array[@]}"
- do
- name=${item#?}
- desk=""
- case $item in
- O*) # focussed occupied
- desk="%{B$bspwm_focussed_bg}%{F$bspwm_focussed_fg}${bspwm_pad}${name}${bspwm_pad}%{F-}%{B-}"
- ;;
- F*) # focussed free
- desk="%{B$bspwm_focussed_bg}%{F$bspwm_focussed_fg}${bspwm_pad}${name}${bspwm_pad}%{F-}%{B-}"
- ;;
- U*) # focussed urgent
- desk="%{B$bspwm_focussed_bg}%{F$bspwm_focussed_fg}${bspwm_pad}${name}${bspwm_pad}%{F-}%{B-}"
- ;;
- o*) # unfocussed occupied
- desk="%{B$bspwm_unfocussed_occupied_bg}%{F$bspwm_unfocussed_occupied_fg}${bspwm_pad}${name}${bspwm_pad}%{F-}%{B-}"
- ;;
- f*) # unfocussed free
- desk="%{B$bspwm_unfocussed_free_bg}%{F$bspwm_unfocussed_free_fg}${bspwm_pad}${name}${bspwm_pad}%{F-}%{B-}"
- ;;
- u*) # unfocussed urgent
- desk="%{B$bspwm_unfocussed_urgent_bg}%{F$bspwm_unfocussed_urgent_fg}${bspwm_pad}{$name}${bspwm_pad}%{F-}%{B-}"
- ;;
- LT|LM) # end of desktop listing
- (( monitor < num_monitors-1 )) || continue
- (( monitor += 1 ))
- output="${output}£"
- continue
- ;;
- *) # anything else
- continue
- ;;
- esac
- output="${output}%{A:bspc desktop -f ^$desktop:}${desk}%{A}"
- (( desktop += 1 ))
- done
- echo "bspwm='${output}'" > "$fifo"
-}
-
-_bspwm() {
- num_monitors=$(xrandr --listactivemonitors | head -n 1 | awk '{print $2}')
- [[ -z $bspwm_pad ]] && bspwm_pad="__"
- if [[ $num_monitors -gt 1 ]]
- then
- bspwm_draw_multimonitor $num_monitors
- bspc subscribe desktop_focus | while read msg
- do
- bspwm_draw_multimonitor $num_monitors
- done
- else
- bspwm_draw
- bspc subscribe desktop_focus | while read msg
- do
- bspwm_draw
- done
- fi
-}
-
-
-_mpctest() {
- if ! which mpc > /dev/null
- then
- echo "mpc=" > $fifo
- return
- fi
-
- get_clicks mpc
-
- while true; do
- if pgrep mpd > /dev/null
- then
- current=$(/usr/bin/mpc current | sed "s/'/''/g")
- echo "mpctest='${mpc_pre}${current}${mpc_post}'"
- mpc idle player > /dev/null
- else
- sleep 30
- fi
- done > "$fifo"
-}
-
-
-_mpc() {
- if ! which mpc > /dev/null
- then
- echo "mpc=" > $fifo
- return
- fi
- while true; do
- if pgrep mpd > /dev/null
- then
- current=$(/usr/bin/mpc current | sed "s/'/''/g")
- if [ -n "$click_mpc" ]
- then
- echo "mpc='%{A:$click_mpc:}$current%{A}'"
- else
- echo "mpc='$current'"
- fi
- mpc idle player > /dev/null
- else
- sleep 30
- fi
- done > "$fifo"
-}
-
-
-_servers() {
- while true; do
- if mount | grep -q -e duguidlab1 -e duguidlab -e ardbeg -e michandmatt
- then
- echo "servers='%{B$highlight}${pad}${pad}%{B-}'"
- else
- echo "servers="
- fi
- sleep 8
- done > "$fifo"
-}
-
-
-_wireguard() {
- [ -n "$wireguard_interface" ] || wireguard_interface=wg0
- if [ -n "$click_wireguard" ]
- then
- while true; do
- if ip link | grep -q $wireguard_interface
- then
- echo "vpn='%{A:$click_wireguard:}%{B$highlight}${pad}${pad}%{B-}%{A}'"
- else
- echo "vpn='%{A:$click_wireguard:}%{B$urgent}${pad}!!!${pad}%{B-}%{A}'"
- fi
- sleep 15
- done > "$fifo"
- else
- while true; do
- if ip link | grep -q $wireguard_interface
- then
- echo "vpn='%{B$highlight}${pad}${pad}%{B-}'"
- else
- echo "vpn='%{B$urgent}${pad}!!!${pad}%{B-}'"
- fi
- sleep 15
- done > "$fifo"
- fi
-}
-
-
-_battery() {
- [ -n "$battery_capacity" ] \
- || battery_capacity=/sys/class/power_supply/BAT0/capacity
- [ -n "$battery_status" ] \
- || battery_status=/sys/class/power_supply/BAT0/status
-
- while true; do
- capacity=$(cat $battery_capacity)
- charging_status=$(cat $battery_status)
-
- if [ "$charging_status" = "Charging" ] && [[ $capacity -ge 95 ]]
- then
- # overcharging
- echo "battery='%{B$urgent}${pad}${capacity}%${pad}%{B-}'"
-
- elif [[ $capacity -le 10 ]] && [ "$charging_status" = "Discharging" ]
- then
- # need to plug in
- echo "battery='%{B$urgent}${pad}${capacity}%${pad}%{B-}'"
-
- elif [ "$charging_status" = "Charging" ]
- then
- # charging
- echo "battery='%{B$highlight}${pad}${capacity}%${pad}%{B-}'"
- else
- # discharging
- echo "battery='${pad}${capacity}%${pad}'"
- fi
- sleep 60
- done > "$fifo"
-}
-
-
-_longdate() {
- if [ -n "$click_longdate" ]
- then
- while true; do
- echo "longdate='%{A:$click_longdate:}${pad}$(date "+%a, %d %b")${pad}%{A}'"
- sleep 10m
- done > "$fifo"
- else
- while true; do
- echo "longdate='${pad}$(date "+%a, %d %b")${pad}'"
- sleep_until 'tomorrow 00:00'
- done > "$fifo"
- fi
-}
-
-
-_clock() {
- if [ -n "$click_clock" ]
- then
- while true; do
- echo "clock='%{A:$click_clock:}%{B$highlight}${pad}$(date "+%H:%M")${pad}%{B-}%{A}'"
- sleep 30
- done > "$fifo"
- else
- while true; do
- echo "clock='%{B$highlight}${pad}$(date "+%H:%M")${pad}%{B-}'"
- sleep 30
- done > "$fifo"
- fi
-}
-
-
-_headphones() {
- # This is changed by piping 'headphones=X' to $fifo via udev on headphone hotplug
- echo "headphones=" > "$fifo"
-}
-
-
-_mute() {
- status=$(amixer sget Master | awk -F '[][]' 'NR==5{print $6}')
- case $status in
- on)
- echo "mute=" > "$fifo"
- ;;
- off)
- echo "mute=${pad}${mute_symbol}${pad}" > "$fifo"
- ;;
- esac
- #echo "mute="
-}
-
-
-# vim: filetype=sh
diff --git a/modules/battery b/modules/battery
@@ -0,0 +1,62 @@
+#----------------------------------------------------------------------------------
+# battery charge module
+#----------------------------------------------------------------------------------
+
+update_battery(){
+ capacity=$(cat $battery_capacity)
+ charging_status=$(cat $battery_status)
+
+ {
+ if [ "$charging_status" = "Charging" ] && [[ $capacity -ge 95 ]]
+ then
+ # overcharging
+ echo "battery='%{B$urgent}${pad}${capacity}%${pad}%{B-}'"
+
+ elif [[ $capacity -le 10 ]] && [ "$charging_status" = "Discharging" ]
+ then
+ # need to plug in
+ echo "battery='%{B$urgent}${pad}${capacity}%${pad}%{B-}'"
+
+ elif [ "$charging_status" = "Charging" ]
+ then
+ # charging
+ echo "battery='%{B$highlight}${pad}${capacity}%${pad}%{B-}'"
+ else
+ # discharging
+ echo "battery='${pad}${capacity}%${pad}'"
+ fi
+ } > "$fifo"
+}
+
+
+_battery() {
+ [ -n "$battery_capacity" ] || battery_capacity=/sys/class/power_supply/BAT0/capacity
+ [ -n "$battery_status" ] || battery_status=/sys/class/power_supply/BAT0/status
+
+ while true; do
+ capacity=$(cat $battery_capacity)
+ charging_status=$(cat $battery_status)
+
+ if [ "$charging_status" = "Charging" ] && [[ $capacity -ge 95 ]]
+ then
+ # overcharging
+ echo "battery='%{B$urgent}${pad}${capacity}%${pad}%{B-}'"
+
+ elif [[ $capacity -le 10 ]] && [ "$charging_status" = "Discharging" ]
+ then
+ # need to plug in
+ echo "battery='%{B$urgent}${pad}${capacity}%${pad}%{B-}'"
+
+ elif [ "$charging_status" = "Charging" ]
+ then
+ # charging
+ echo "battery='%{B$highlight}${pad}${capacity}%${pad}%{B-}'"
+ else
+ # discharging
+ echo "battery='${pad}${capacity}%${pad}'"
+ fi
+ sleep 60
+ done > "$fifo"
+}
+
+# vim: ft=sh
diff --git a/modules/bspwm b/modules/bspwm
@@ -0,0 +1,129 @@
+#----------------------------------------------------------------------------------
+# bspwm module
+#----------------------------------------------------------------------------------
+
+bspwm_draw() {
+ statnew=$(bspc wm --get-status)
+ if [[ $statnew = $stat ]]
+ then
+ # return if unchanged
+ return
+ else
+ stat=$statnew
+ fi
+
+ output=""
+ desktop=1
+ IFS=':' read -a array <<< $stat
+ for item in "${array[@]}"
+ do
+ name=${item#?}
+ desk=""
+ case $item in
+ O*) # focussed occupied
+ desk="%{B$bspwm_focussed_bg}%{F$bspwm_focussed_fg}${bspwm_pad}${name}${bspwm_pad}%{F-}%{B-}"
+ ;;
+ F*) # focussed free
+ desk="%{B$bspwm_focussed_bg}%{F$bspwm_focussed_fg}${bspwm_pad}${name}${bspwm_pad}%{F-}%{B-}"
+ ;;
+ U*) # focussed urgent
+ desk="%{B$bspwm_focussed_bg}%{F$bspwm_focussed_fg}${bspwm_pad}${name}${bspwm_pad}%{F-}%{B-}"
+ ;;
+ o*) # unfocussed occupied
+ desk="%{B$bspwm_unfocussed_occupied_bg}%{F$bspwm_unfocussed_occupied_fg}${bspwm_pad}${name}${bspwm_pad}%{F-}%{B-}"
+ ;;
+ f*) # unfocussed free
+ desk="%{B$bspwm_unfocussed_free_bg}%{F$bspwm_unfocussed_free_fg}${bspwm_pad}${name}${bspwm_pad}%{F-}%{B-}"
+ ;;
+ u*) # unfocussed urgent
+ desk="%{B$bspwm_unfocussed_urgent_bg}%{F$bspwm_unfocussed_urgent_fg}${bspwm_pad}{$name}${bspwm_pad}%{F-}%{B-}"
+ ;;
+ *) # anything else
+ continue
+ ;;
+ esac
+ output="${output}%{A:bspc desktop -f ^$desktop:}${desk}%{A}"
+ (( desktop += 1 ))
+ done
+ echo "bspwm='${output}'" > "$fifo"
+}
+
+
+bspwm_draw_multimonitor() {
+ statnew=$(bspc wm --get-status)
+ if [[ $statnew = $stat ]]
+ then
+ # return if unchanged
+ return
+ else
+ stat=$statnew
+ fi
+
+ num_monitors=$1
+ monitor=0
+ output=""
+ desktop=1
+
+ IFS=':' read -a array <<< $stat
+ for item in "${array[@]}"
+ do
+ name=${item#?}
+ desk=""
+ case $item in
+ O*) # focussed occupied
+ desk="%{B$bspwm_focussed_bg}%{F$bspwm_focussed_fg}${bspwm_pad}${name}${bspwm_pad}%{F-}%{B-}"
+ ;;
+ F*) # focussed free
+ desk="%{B$bspwm_focussed_bg}%{F$bspwm_focussed_fg}${bspwm_pad}${name}${bspwm_pad}%{F-}%{B-}"
+ ;;
+ U*) # focussed urgent
+ desk="%{B$bspwm_focussed_bg}%{F$bspwm_focussed_fg}${bspwm_pad}${name}${bspwm_pad}%{F-}%{B-}"
+ ;;
+ o*) # unfocussed occupied
+ desk="%{B$bspwm_unfocussed_occupied_bg}%{F$bspwm_unfocussed_occupied_fg}${bspwm_pad}${name}${bspwm_pad}%{F-}%{B-}"
+ ;;
+ f*) # unfocussed free
+ desk="%{B$bspwm_unfocussed_free_bg}%{F$bspwm_unfocussed_free_fg}${bspwm_pad}${name}${bspwm_pad}%{F-}%{B-}"
+ ;;
+ u*) # unfocussed urgent
+ desk="%{B$bspwm_unfocussed_urgent_bg}%{F$bspwm_unfocussed_urgent_fg}${bspwm_pad}{$name}${bspwm_pad}%{F-}%{B-}"
+ ;;
+ LT|LM) # end of desktop listing
+ (( monitor < num_monitors-1 )) || continue
+ (( monitor += 1 ))
+ output="${output}£"
+ continue
+ ;;
+ *) # anything else
+ continue
+ ;;
+ esac
+ output="${output}%{A:bspc desktop -f ^$desktop:}${desk}%{A}"
+ (( desktop += 1 ))
+ done
+ echo "bspwm='${output}'" > "$fifo"
+}
+
+_bspwm() {
+ bspwm_pad=%{O${bspwm_pad:-8}}
+ num_monitors=$(xrandr --listactivemonitors | head -n 1 | awk '{print $2}')
+ stat=
+ if [[ $num_monitors -gt 1 ]]
+ then
+ bspwm_draw_multimonitor $num_monitors
+ bspc subscribe desktop_focus node_add node_remove node_transfer | while read msg
+ do
+ bspwm_draw_multimonitor $num_monitors
+ done
+ else
+ bspwm_draw
+ bspc subscribe desktop_focus node_add node_remove node_transfer | while read msg
+ do
+ bspwm_draw
+ done
+ fi
+}
+
+
+
+# vim: ft=sh
diff --git a/modules/clock b/modules/clock
@@ -0,0 +1,17 @@
+#----------------------------------------------------------------------------------
+# clock module
+#----------------------------------------------------------------------------------
+
+update_clock() {
+ echo "clock='${clock_pre}%{B$highlight}${pad}$(date "+%H:%M")${pad}%{B-}${clock_post}'" > "$fifo"
+}
+
+_clock() {
+ get_clicks clock
+ while true; do
+ echo "clock='${clock_pre}%{B$highlight}${pad}$(date "+%H:%M")${pad}%{B-}${clock_post}'"
+ sleep 30
+ done > "$fifo"
+}
+
+# vim: ft=sh
diff --git a/modules/date b/modules/date
@@ -0,0 +1,20 @@
+#----------------------------------------------------------------------------------
+# date module
+#----------------------------------------------------------------------------------
+
+_date() {
+ if [ -n "$click_date" ]
+ then
+ while true; do
+ echo "date='%{A:$click_date:}${pad}$(date "+%a, %d %b")${pad}%{A}'"
+ sleep 10m
+ done > "$fifo"
+ else
+ while true; do
+ echo "date='${pad}$(date "+%a, %d %b")${pad}'"
+ sleep_until 'tomorrow 00:00'
+ done > "$fifo"
+ fi
+}
+
+# vim: ft=sh
diff --git a/modules/headphones b/modules/headphones
@@ -0,0 +1,10 @@
+#----------------------------------------------------------------------------------
+# headphone connection module
+#----------------------------------------------------------------------------------
+
+_headphones() {
+ # This is changed by piping 'headphones=X' to $fifo via udev on headphone hotplug
+ echo "headphones=" > "$fifo"
+}
+
+# vim: ft=sh
diff --git a/modules/i3 b/modules/i3
@@ -0,0 +1,25 @@
+#----------------------------------------------------------------------------------
+# i3 module
+#----------------------------------------------------------------------------------
+
+_i3() {
+ # This could be made better if needed
+ while true; do
+ current=$((($(xprop -root _NET_CURRENT_DESKTOP | awk '{print $3}') + 1)))
+ total=$(xprop -root _NET_NUMBER_OF_DESKTOPS | awk '{print $3}')
+ output="i3="
+
+ for i in $(seq $total)
+ do
+ if [[ $i == $current ]]; then
+ output="${output}%{B$highlight}${pad}$i${pad}%{B-}"
+ else
+ output="${output}${pad}$i${pad}"
+ fi
+ done
+ echo ${output} > "$fifo"
+ sleep 0.3
+ done
+}
+
+# vim: ft=sh
diff --git a/modules/inbox b/modules/inbox
@@ -0,0 +1,25 @@
+#----------------------------------------------------------------------------------
+# mail inbox module
+#----------------------------------------------------------------------------------
+
+# $inbox_dir specifies mail directory (defaults to ~/.mail)
+
+
+_inbox() {
+ [[ -z $inbox_dir ]] && inbox_dir=$HOME/.mail
+ get_clicks inbox
+
+ while true
+ do
+ new_mail=$(find $inbox_dir/*/INBOX/new/* -maxdepth 1 2> /dev/null | wc -l)
+ if [[ $new_mail > 0 ]]
+ then
+ echo "inbox='${inbox_pre}%{B$highlight}${pad}%{T2}%{T-}${new_mail}${pad}%{B-}${inbox_post}'" > "$fifo"
+ else
+ echo 'inbox=' > "$fifo"
+ fi
+ sleep 10
+ done
+}
+
+# vim: ft=sh
diff --git a/modules/mpc b/modules/mpc
@@ -0,0 +1,26 @@
+#----------------------------------------------------------------------------------
+# mpc/mpd module
+#----------------------------------------------------------------------------------
+
+_mpc() {
+ if ! which mpc > /dev/null
+ then
+ echo "mpc=" > $fifo
+ return
+ fi
+
+ get_clicks mpc
+
+ while true; do
+ if pgrep mpd > /dev/null
+ then
+ current=$(/usr/bin/mpc current | sed "s/'/''/g")
+ echo "mpc='${mpc_pre}${current}${mpc_post}'"
+ mpc idle player > /dev/null
+ else
+ sleep 30
+ fi
+ done > "$fifo"
+}
+
+# vim: ft=sh
diff --git a/modules/mute b/modules/mute
@@ -0,0 +1,18 @@
+#----------------------------------------------------------------------------------
+# mute status module
+#----------------------------------------------------------------------------------
+
+_mute() {
+ # to update: "echo '_mute; continue' > $fifo" when mute is toggled
+ status=$(amixer sget Master | awk -F '[][]' 'NR==5{print $6}')
+ case $status in
+ on)
+ echo "mute=" > "$fifo"
+ ;;
+ off)
+ echo "mute=${mute_format}" > "$fifo"
+ ;;
+ esac
+}
+
+# vim: ft=sh
diff --git a/modules/servers b/modules/servers
@@ -0,0 +1,17 @@
+#----------------------------------------------------------------------------------
+# file server connections module
+#----------------------------------------------------------------------------------
+
+_servers() {
+ while true; do
+ if mount | grep -q -e duguidlab1 -e duguidlab -e ardbeg -e michandmatt
+ then
+ echo "servers='%{B$highlight}${pad}${pad}%{B-}'"
+ else
+ echo "servers="
+ fi
+ sleep 8
+ done > "$fifo"
+}
+
+# vim: ft=sh
diff --git a/modules/wireguard b/modules/wireguard
@@ -0,0 +1,19 @@
+#----------------------------------------------------------------------------------
+# wireguard interface module
+#----------------------------------------------------------------------------------
+
+_wireguard() {
+ [ -n "$wireguard_interface" ] || wireguard_interface=wg0
+ get_clicks wireguard
+ while true; do
+ if ip link | grep -q $wireguard_interface
+ then
+ echo "wireguard='$wireguard_pre%{B$highlight}${pad}${pad}%{B-}$wireguard_post'"
+ else
+ echo "wireguard='$wireguard_pre%{B$urgent}${pad}!!!${pad}%{B-}$wireguard_post'"
+ fi
+ sleep 15
+ done > "$fifo"
+}
+
+# vim: ft=sh
diff --git a/start-lemonbar b/start-lemonbar
@@ -40,10 +40,10 @@ print_variables() {
cat << EOF
arrays specifying position of modules: modules_l
modules_c
- modules_r
+ modules_r
- spacing, placeheld by underscores: gap
- e.g. pad='___' pad
+ spacing in number of pixels: gap
+ e.g. pad=8 pad
margin_l
margin_r
@@ -61,7 +61,7 @@ print_variables() {
foreground
highlight
urgent
- underline
+ underline
bar on bottom: bottom
boolean true/false
@@ -69,17 +69,23 @@ print_variables() {
click/scroll commands: click_<module>
e.g. click_mpc_r='mpc toggle' click_<module>_c
click_<module_r
- scroll_<module>_u
- scroll_<module>_d
+ scroll_<module>_u
+ scroll_<module>_d
number of clickable areas: clickable_areas
integer; defaults to 20
+ modules might have their own settings: see the module file
EOF
exit
}
+error() {
+ echo $1 | tee $logfile
+}
+
+
sleep_until() {
local seconds=$(( $(date -d "$*" +%s) - $(date +%s) )) # Use $* to eliminate need for quotes
sleep $seconds
@@ -87,8 +93,8 @@ sleep_until() {
get_clicks() {
- # Give this the module name and it will return the prefix and suffix
- # required for specified click commands
+ # Give this the module name and it will generate the prefix and suffix
+ # required for specified click commands as $module_pre and $module_post
local mod=$1
local pre=
local post=
@@ -119,13 +125,39 @@ kill_lemonbar() {
}
-start_feed() {
+construct_output() {
+ # string together the modules and bar settings
+ output_string="%{l}${margin_l}"
+ for module in ${modules_l[@]}
+ do
+ output_string="${output_string}\${${module}}${gap}"
+ done
+ output_string="${output_string}%{c}${gap}"
+ for module in ${modules_c[@]}
+ do
+ output_string="${output_string}\${${module}}${gap}"
+ done
+ output_string="${output_string}%{r}"
+ for module in ${modules_r[@]}
+ do
+ output_string="${output_string}${gap}\${${module}}"
+ done
+ output_string="${output_string}${margin_r}"
+}
+
+
+start_feed2() {
# this listens to $fifo, constructs the output and sends it to the bar
while read -r line ; do
- final_output=
- output=
+ # each line received is a statement assigning a string to a variable
eval $line
+ if [[ $line = "update_*" ]]
+ then
+ error "update"
+ continue
+ fi
+
# £ in $line delimits outputs per monitor
if grep -q "£" <<< "$line"
then
@@ -140,50 +172,36 @@ start_feed() {
eval ${this_module}=£
fi
- # string together the final output
- output="%{l}${margin_l}"
- for module in ${modules_l[@]}
- do
- [ "${!module}" != "" ] && output="${output}${!module}${gap}"
- done
- output="${output}%{c}${gap}"
- for module in ${modules_c[@]}
- do
- [ "${!module}" != "" ] && output="${output}${!module}${gap}"
- done
- output="${output}%{r}"
- for module in ${modules_r[@]}
- do
- [ "${!module}" != "" ] && output="${output}${gap}${!module}"
- done
- output="${output}${margin_r}"
+ # generate output string
+ eval output=$output_string
# replace any £ placeholders to make monitor-specific outputs
if [[ $num_monitors -gt 1 ]]
then
-
+ final_output=
for ((s=0; s<=num_monitors-1; s++))
do
this_output="$(echo %{S$s}$output | sed "s/£/${fields[$s]}/")"
final_output="${final_output}${this_output}"
done
- sed "s/\\_/ /g" <<< ${final_output//_/ }
+ echo ${final_output}
else
- sed "s/\\_/ /g" <<< ${output//_/ }
+ echo ${output}
fi
done < "$fifo"
}
-
start_bar() {
printf "Lemonbar started.\n"
- start_feed | $bar | while read msg
-do
- # execute outputs from bar, logging to $logfile
- $msg &> $logfile &
-done
+ construct_output
+ start_feed2 | $bar | while read msg
+ do
+ # execute outputs from bar, logging to $logfile
+ printf "From bar: %s\n" "$msg"
+ $msg &>> $logfile &
+ done
}
@@ -191,25 +209,35 @@ done
# Parse inputs
##----------------------------------------------------------------------------------
+set -e
+
# Lemonbar directory
dir=$(dirname $(readlink -f $0))
# Modules
-modules_file=$dir/modules
+modules_dir=$dir/modules
# logfile for commands output from lemonbar
logfile="/tmp/lemonerror"
+[[ -f $logfile ]] && rm $logfile
-# fifo file
-fifo="/tmp/lemonbar"
+# fifo file - can be set by environmental variable LEMONFIFO or before command
+# for multiple bars
+if [[ -z $LEMONFIFO ]]
+then
+ fifo="/tmp/lemonbar"
+else
+ fifo=$LEMONFIFO
+fi
+# process arguments
while getopts ":hlTvt:f:kd" arg; do
case $arg in
h) print_help
;;
l) printf "Available modules:\n"
- grep -oe "_.*(" $modules_file | tr -d "_("
+ ls $modules_dir
exit
;;
@@ -249,7 +277,7 @@ then
then
. $dir/themes/$theme.bar
else
- echo "Theme $theme does not exist."
+ error "Theme $theme does not exist."
exit 1
fi
else
@@ -264,11 +292,22 @@ num_monitors=$(xrandr --listactivemonitors | head -n 1 | awk '{print $2}')
[ -e $fifo ] && rm $fifo
mkfifo "$fifo"
+# Format padding settings
+[[ -n "$pad" ]] && pad=%{O${pad}}
+[[ -n "$gap" ]] && gap=%{O${gap}}
+[[ -n "$margin_l" ]] && margin_l=%{O${margin_l}}
+[[ -n "$margin_r" ]] && margin_r=%{O${margin_r}}
+
# Start modules
-. $modules_file
for module in ${modules_l[@]} ${modules_c[@]} ${modules_r[@]}
do
- _$module &
+ if [[ -f $modules_dir/$module ]]
+ then
+ . $modules_dir/$module
+ _$module &
+ else
+ error "Module file for $module not found."
+ fi
done
@@ -278,7 +317,8 @@ done
if ${debug:-false}
then
- start_feed
+ construct_output
+ start_feed2
else
# path to binary can be given as bar_path, or defaults to 'lemonbar'
bar=${bar_path:-lemonbar}
@@ -286,25 +326,24 @@ else
# bar is placed at bottom of screen if $bottom = true
[[ $bottom == true ]] && bar+=' -b'
-
+
# bar geometry
# this was an undocumented fix I may have to fix if I don't want 100% width
[[ $num_monitors > 1 ]] && width=
bar+=" -g ${width}x${height}+${posx}+${posy}"
-
+
# colours, if specified in theme
[[ -n "$background" ]] && bar+=" -B $background" # background colour
[[ -n "$foreground" ]] && bar+=" -F $foreground" # foreground colour
[[ -n "$underline" ]] && bar+=" -U $underline" # underline colour
-
+
# fonts, defaulting to Liberation Sans, size 9, with optional fallback font
bar+=" -f ${font:-LiberationSans}-${font_size:-9}"
[[ -n "$font2" ]] && bar+=" -f $font2-${font_size2:-9}"
-
+
# max clickable_areas defaults to 20 but can be specified in theme
bar+=" -a ${clickable_areas:-20}"
-
- # start bar
+
start_bar
fi
diff --git a/themes/fisherman.bar b/themes/fisherman.bar
@@ -1,4 +1,3 @@
-#!bin/bash
#----------------------------------------------------------------------------------
# appearance
#----------------------------------------------------------------------------------
@@ -16,20 +15,20 @@ underline=$(xgetres color5)
font=Terminus
font2=FontAwesome
-gap=''
-pad='__'
-margin_l=''
-margin_r=''
+gap=
+pad=8
+margin_l=
+margin_r=
modules_l=( bspwm )
-modules_c=( mpctest )
-modules_r=( mute headphones servers wireguard battery longdate clock )
+modules_c=( mpc )
+modules_r=( inbox mute headphones servers wireguard battery date clock )
click_clock=urxvt
click_wireguard=nmcli_rofi
-click_longdate=
-click_mpc='scratch -g cantata'
-click_mpc_r='mpd-ctrl -n toggle'
+click_inbox='scratch -c mutt'
+click_mpc='scratch -c ncmpcpp'
+click_mpc_3='mpd-ctrl -n toggle'
scroll_mpc_u='mpd-ctrl -n prev'
scroll_mpc_d='mpd-ctrl -n next'
@@ -42,7 +41,6 @@ bspwm_unfocussed_free_fg=$highlight
bspwm_unfocussed_urgent_bg=$background
bspwm_unfocussed_urgent_fg=$urgent
-mute_symbol=
-click_mute='amixer sset Master toggle'
+mute_format='%{B${highlight}}${pad}${pad}%{B-}'
# vim: filetype=sh
diff --git a/themes/road.bar b/themes/road.bar
@@ -1,4 +1,3 @@
-#!bin/bash
#----------------------------------------------------------------------------------
# appearance
#----------------------------------------------------------------------------------