Skip to content

Instantly share code, notes, and snippets.

@wallentx
Created September 10, 2015 19:51
Show Gist options
  • Save wallentx/3bb224a4f039bdc37776 to your computer and use it in GitHub Desktop.
Save wallentx/3bb224a4f039bdc37776 to your computer and use it in GitHub Desktop.
#!/bin/sh
# panel_bar
# a script to interpret panel fifo information(workspace/window titles/system info)
# clickable area aliases
AC='%{A:' # start click area
AB=':}' # end click area cmd
AE='%{A}' # end click area
# Shell commands for clickable areas
goto='bspc desktop -f' # go to this desktop
cycle='bspc desktop -l next' # cycle tiled/monocle
winfocus='bspc window -f ' # focus on a window
# define clickable menu thing:
dropdown="%{T3}`echo -n -e "\uf100"`%{T-}"
dropdown="$(pPadding=1 && block "$dropdown")"
dropdown="${AC}dzen_menu & ${AB}$dropdown${AE}"
while read -r line ; do
case $line in
S*)
sys_infos="${line#?}"
;;
T*)
title="%{F$pRest}"
IFS='\'
set -- ${line#?}
while [ $# -gt 0 ] ; do
item=$1
name=${item#?}
# form of $name will be window title // window id.
# split and use for clickable focus areas
winTitle="$(echo $name | grep -oE ".*//" | rev | cut -c 3- | rev)"
winID="$(echo $name | grep -oE "//.*" | cut -c 3-)"
if [ ! -z $winTitle ]; then
case $item in
A*) blockActive=true && title="${title}$(block $winTitle)";; #active window
X*) blockActive=false && title="${title}$(block ${AC}${winfocus} ${winID}${AB}${winTitle}${AE})";; #inactive window
esac
fi
title="$title%{B$pBG}"
shift
done
;;
W*)
# setting the underline for everything with wm_info
wm_infos="%{U$pBG+o}%{U$pBG+u}"
IFS=':'
set -- ${line#?}
while [ $# -gt 0 ] ; do
item=$1
name=${item#?}
desktopName=$(echo "$name" | cut -c3-)
curFree=false
command=$goto
blockActive=false
case $item in
O*) dColor="$pActive" && dDisplay="$DO" && blockActive=true;; #active occupied desktop
F*) dColor="$pActive" && dDisplay="$DF" && blockActive=true;; #active free desktop
U*) dColor="$pUrgent" && dDisplay="$DO";; #active urgent desktop
o*) dColor="$pRest" && dDisplay="$DO";; #inactive occupied desktop
f*) dColor="$pRest" && dDisplay="$DF";; #inactive free desktop
u*) dColor="$pUrgent" && dDisplay="$DO";; #inactive urgent desktop
L*) if [ ! -z "$NoModeToggle" ]; then
dDisplay=""
else
dColor="$pRest" && command="$cycle" && name=""
dDisplay="$([[ $item == LT ]] && echo $DT || echo $DM)"
fi;; # mode toggle
*) dDisplay="";; # Monitor
esac
if [[ ! -z "$dDisplay" ]]; then
[[ "$desktopDisplay" = name ]] && [[ ! $item == L* ]] && dDisplay="$desktopName"
if [[ "$showFreeDesktops" = true ]] || [[ ! $item == f* ]]; then
if [[ "$desktopDisplayType" = separate ]]; then
blockContent="${AC}${command} ${name}${AB}$(printf %${pPadding}s)${dDisplay}$(printf %${pPadding}s)${AE}"
NoPadding=0
wm_infos="$wm_infos$(block "$blockContent")"
NoPadding=""
else
wm_infos="$wm_infos%{F$dColor}${AC}${command} ${name}${AB} ${dDisplay} ${AE}"
fi
fi
fi
shift
done
# WHY DOES THIS LINE AFFECT THE SPACING ON THE LEFT WHEN SEPARATED
if [[ "$desktopDisplayType" == "together" ]]; then
NoPadding=$(expr $pPadding - 1)
wm_infos="$(block "$wm_infos")"
NoPadding=""
fi
wm_infos="$wm_infos%{B$pBG}";;
esac
printf "%s\n" "%{l} $dropdown$wm_infos%{r}$sys_infos%{c}$title"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment