Skip to content

Instantly share code, notes, and snippets.

@wallentx
Created September 10, 2015 19:50
Show Gist options
  • Save wallentx/019ec7db0566552aac33 to your computer and use it in GitHub Desktop.
Save wallentx/019ec7db0566552aac33 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# panel
# Start a panel on every monitor
# This script makes the assumption that monitors names are arranged left to right, named in increasing int value(1 2 3..)
# if this is not the case, you can override this with the num_mon variable below.
# Read the theme for display settings
. ~/.bspwm_theme
# Add panel scripts to path
export PATH=$PATH:~/.config/bspwm/panel
# Kill the panel if it is currently running
if [ $(pgrep -cx lemonbar) -gt 1 ] ; then
printf "%s\n" "The panel is already running."
while [[ $(pgrep -c "lemonbar") != 0 ]]
do
pkill -n -9 "lemonbar"
done
fi
trap 'trap - TERM; kill 0' INT TERM QUIT EXIT
# Store pid to kill this process later(toggle gaps/panel)
echo $$ > /tmp/panel-pid
# Track the current offset for making a bar per monitor, so we can make bars with specific geometries.
CUR_X_OFFSET=0
# Get the number of monitors we will be making bars for
num_mon=$(bspc query -M)
#[ "$HOSTNAME" = "soundstone" ] && num_mon=""
# panel_gap to 0 if no gaps.
[ "$BSPWM_GAPS" = false ] && PANEL_GAP=0
# display function used by both info.sh and panel_bar scripts:
declare -f block
if [ $? = "1" ]; then
function block() {
[ ! -z $NoPadding ] && pPadding=$NoPadding
if [ "$blockActive" = true ] ; then
echo -n "%{B$pBGActiveTab}%{F$pBG}$(printf %${pPadding}s)$@$(printf %${pPadding}s)%{B$pBG} "
else
echo -n "%{B$pBGInactiveTab}%{F$pFG}$(printf %${pPadding}s)$@$(printf %${pPadding}s)%{B$pBG} "
fi
}
export -f block
fi
for i in $num_mon; do
# remove any open panel fifo, and then create one
[ -e "$PANEL_FIFO$i" ] && rm "$PANEL_FIFO$i"
mkfifo "$PANEL_FIFO$i"
# This greps out the bspc control section of the current monitor we are on.
# The while loop in the middle appends 'W' to the start because the panel_bar
# script assumes input from a 'regular' bspc control --subscribe command
bspc control --subscribe |\
grep -oE "[Mm]$i[^TM]*[TML]" --line-buffered |\
while read line; do echo W$line; done \
> "$PANEL_FIFO$i" &
# title.sh allows for a tabbing feature like in i3, and handles multihead titles
# in a more natural manner, but can be a little more processor intensive.
# Substitute the xtitle command here if you just want the current active window
# name to be displayed.
xtitle -t 80 -sf 'T\\X%s//' > "$PANEL_FIFO$i" &
#title.sh $i > "$PANEL_FIFO$i" &
# info.sh outputs system information.
if [ -z "$(eval echo \$'barInfo'$i)" ]; then
info.sh $barInfo > "$PANEL_FIFO$i" &
else
#Custom bar options per monitor. (defined barInfo$i var for this monitor)
info.sh $(eval echo \$'barInfo'$i) > "$PANEL_FIFO$i" &
fi
# Grep for current monitor width (will be first number regex match from bspc query command below).
CUR_MON_WIDTH=$(bspc query -T -m $i | grep -oE "[0-9]{2,6}" | head -n 1)
# The nested expr statements account for gap settings and current offset.
# PANEL_GAP value is set in profile.
cat "$PANEL_FIFO$i" | panel_bar |\
lemonbar -g $(expr $CUR_MON_WIDTH - $(expr $PANEL_GAP + $PANEL_GAP))x$PANEL_HEIGHT+$(expr $CUR_X_OFFSET + $PANEL_GAP)+$PANEL_GAP -f "$PANEL_FONT_MAIN" -f "$PANEL_FONT_ICON" -f "font\-linux-12" -u $PANEL_UNDERLINE | sh &
# Increment the x offset for the next monitor.
CUR_X_OFFSET=$(expr $CUR_X_OFFSET + $CUR_MON_WIDTH )
done
wait
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment