148 lines
		
	
	
		
			4.3 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable file
		
	
	
	
	
			
		
		
	
	
			148 lines
		
	
	
		
			4.3 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable file
		
	
	
	
	
#!/usr/bin/env dash
 | 
						|
 | 
						|
if [ "$1" = "--kill" ]
 | 
						|
then
 | 
						|
    pkill -f '^dash .+/panel$'
 | 
						|
    exit
 | 
						|
fi
 | 
						|
 | 
						|
CWD="$(cd $(dirname $0) && pwd -P)"
 | 
						|
. $CWD/panel-config
 | 
						|
 | 
						|
 | 
						|
#
 | 
						|
running() { pgrep -f $1 >/dev/null; }
 | 
						|
cleanup() { rm -rf "$PANEL_FIFO"; pkill -P $$; }
 | 
						|
 | 
						|
#
 | 
						|
trap cleanup INT TERM QUIT EXIT
 | 
						|
[ -e "$PANEL_FIFO" ] && rm "$PANEL_FIFO"
 | 
						|
mkfifo "$PANEL_FIFO"
 | 
						|
echo "MKFIFO $PANEL_FIFO"
 | 
						|
 | 
						|
if running lemonbar
 | 
						|
then
 | 
						|
    2>&1 echo "Lemonbar already running"
 | 
						|
    exit 1
 | 
						|
fi
 | 
						|
 | 
						|
 | 
						|
#
 | 
						|
# Bootstrap panel(s)
 | 
						|
#
 | 
						|
 | 
						|
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}" &
 | 
						|
 | 
						|
for lemon in $CWD/lemons/*
 | 
						|
do
 | 
						|
    echo "INIT $(basename $lemon)"
 | 
						|
    $lemon > "${PANEL_FIFO}" &
 | 
						|
done
 | 
						|
 | 
						|
#
 | 
						|
parse() {
 | 
						|
    num_mon=$(bspc query -M | wc -l)
 | 
						|
    while read -r line
 | 
						|
    do
 | 
						|
        data="${line#?}"
 | 
						|
        case $line in
 | 
						|
            # Minimal icons
 | 
						|
            B*) battery="$data"
 | 
						|
                ;;
 | 
						|
            U*) updates=" $data"
 | 
						|
                ;;
 | 
						|
            M*) mail=" $data"
 | 
						|
                ;;
 | 
						|
            V*) vol=" $data"
 | 
						|
                ;;
 | 
						|
            I*) wifi=" $data"
 | 
						|
                ;;
 | 
						|
 | 
						|
            # Full segments
 | 
						|
            E*) # TODO ethernet
 | 
						|
                ;;
 | 
						|
            X*) xtitle="$data"
 | 
						|
                ;;
 | 
						|
            T*) datetime="   $data"
 | 
						|
                ;;
 | 
						|
            S*) song="$data "
 | 
						|
                ;;
 | 
						|
            W*) # bspwm's state
 | 
						|
                wm=""
 | 
						|
                IFS=':'
 | 
						|
                set -- $data
 | 
						|
                while [ "$#" -gt 0 ]
 | 
						|
                do
 | 
						|
                    id=$1
 | 
						|
                    name=${id#???}
 | 
						|
                    case $id in
 | 
						|
                        [mM]*)
 | 
						|
                            [ "$num_mon" -lt 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
 | 
						|
                            eval "icon=\$ICON_$name"
 | 
						|
                            wm="${wm}%{F$_FG}%{B$_BG}%{A:bspc desktop -f ${id#?}:}  ${icon:-$name}  %{A}%{B-}%{F-}"
 | 
						|
                            ;;
 | 
						|
                    esac
 | 
						|
                    shift
 | 
						|
                done
 | 
						|
                ;;
 | 
						|
        esac
 | 
						|
        echo -e \
 | 
						|
            "%{l}${wm}${song}" \
 | 
						|
            "%{c}${xtitle}" \
 | 
						|
            "%{r}${battery}${mail}${updates}${vol}${wifi}${datetime} "
 | 
						|
    done
 | 
						|
}
 | 
						|
 | 
						|
parse < "${PANEL_FIFO}" | \
 | 
						|
    lemonbar \
 | 
						|
    -a 32 \
 | 
						|
    -g x$PANEL_HEIGHT \
 | 
						|
    -f "$PANEL_FONT" \
 | 
						|
    -f "$ICON_FONT" \
 | 
						|
    -F "$COLOR_FG" \
 | 
						|
    -B "$COLOR_BG" \
 | 
						|
    | sh &
 | 
						|
 | 
						|
wait
 |