Skip to content

Instantly share code, notes, and snippets.

@sulami sulami/frankenwm2bar.sh
Last active Mar 15, 2017

Embed
What would you like to do?
FrankenWM status scripts
#!/usr/bin/env sh
wm="frankenwm"
ff="/tmp/frankenwm.fifo"
[[ -p $ff ]] || mkfifo -m 600 "$ff"
# desktop names
ds=("1" "2" "3" "4" "5" "6" "7" "8" "9" "0")
# layout names
ms=("[T]" "[M]" "[B]" "[G]" "[F]" "[D]" "[E]")
while read -t 60 -r wmout || true; do
if [[ $wmout =~ ^(([[:digit:]]+:)+[[:digit:]]+ ?)+$ ]]; then
read -ra desktops <<< "$wmout" && unset r
for desktop in "${desktops[@]}"; do
IFS=':' read -r d w m c u <<< "$desktop"
((c)) && fg="%{F#FF597BC5}%{U#FF597BC5}" i="${ms[$m]}" \
|| fg="%{F#FFADADAD}%{U-}"
((u)) && w+='%{F#FFADADAD}%{U-}'
# r+=" $fg${ds[$d]} [${w/#0/-}] "
r+=" $fg${ds[$d]} "
done
r="${r%::*}"
fi
printf "%s%s%s\n" "%{l} $r" "%{c}%{F#FFADADAD}$i" "%{r}$(date +"%F %R") "
done < "$ff" | bar -d -g x18xx -u 2 -B "#FF121212" -F "#FF579BC5" \
-f "-*-terminus-*-*-*-12-*-*-*-*-*-*-*" &
# pass output to fifo
"$wm" > "$ff"
#!/usr/bin/env sh
: "${wm:=frankenwm}"
: "${ff:="/tmp/frankenwm.fifo"}"
tags=('1' '2' '3' '4' '5' '6' '7' '8' '9' '0')
layouts=('[T]' '[M]' '[B]' '[G]' '[F]' '[D]' '[E]')
# Add some conky?
# conky | dzen2 -h 18 -x 320 -ta r -e -p -fn &
# Check if it's a pipe, otherwise create it
[[ -p $ff ]] || mkfifo -m 600 "$ff"
while read -t 60 -r wmout || true; do
desktops=( $(cut -d"|" -f1 <<< "$wmout") )
if [[ "${desktops[@]}" =~ ^(([[:digit:]]+:)+[[:digit:]]+ ?)+$ ]]; then
unset tmp
for desktop in "${desktops[@]}"; do
IFS=':' read -r d w m c u <<< "$desktop"
# Tags labels
label="${tags[$d]}"
# Is this the current desktop ? save the layout
((c)) && fg="#fefefe" bg="#204a87" && layout="${layouts[$m]}" \
|| fg="#b3b3b3" bg=""
# Has windows ?
((w)) && fg="#fce94f"
# Urgent windows ?
((u)) && fg="#ef2929"
tmp+="^fg($fg)^bg($bg) $label ^bg()^fg()"
done
fi
# Merge the clients indications, the tile and the info
echo "$tmp $layout"
done < "$ff" | dzen2 -h 18 -ta l -e -p &
while :; do "$wm" || break; done | tee -a "$ff"
#!/usr/bin/env sh
# create a fifo to send output
wm="frankenwm"
ff="/tmp/frankenwm.fifo"
[[ -p $ff ]] || mkfifo -m 600 "$ff"
while read -r; do
# filter output to only what we want to match and parse
[[ $REPLY =~ ^(([[:digit:]]+:)+[[:digit:]]+ ?)+$ ]] && read -ra desktops <<< "$REPLY" || continue
for desktop in "${desktops[@]}"; do
# set values for
# d - the desktop id
# w - number of windows in that desktop
# m - tiling layout/mode for that desktop
# c - whether that desktop is the current (1) or not (0)
# u - whether a window in that desktop has an urgent hint set (1) or not (0)
IFS=':' read -r d w m c u <<< "$desktop"
# name each desktop
case $d in
0) d="I" s="" ;;
1) d="II" s="::" ;;
2) d="III" s="::" ;;
3) d="IV" s="::" ;;
4) d="V" s="::" ;;
5) d="VI" s="::" ;;
6) d="VII" s="::" ;;
7) d="VIII" s="::" ;;
8) d="IX" s="::" ;;
9) d="X" s="::" ;;
esac
# the current desktop color should be #cccccc
# we will also display the current desktop's tiling layout/mode
((c)) && f="#cccccc" && case $m in
# name each layout/mode with a symbol
0) i="[T]" ;;
1) i="[B]" ;;
2) i="[G]" ;;
3) i="[M]" ;;
4) i="[F]" ;;
5) i="[D]" ;;
6) i="[E]" ;;
esac || f="#777777"
# if the desktop has an urgent hint its color should be #ff0000
((u)) && f="#ff0000"
# if the desktop has windows print that number next to the desktop name
# else just print the desktop name
((w)) && r+="$s ^fg($f)$d ($w)^fg() " || r+="$s ^fg($f)$d^fg() "
done
# read from fifo and output to dzen2
printf "%s%s\n" "$r" "$i" && unset r
done < "$ff" | dzen2 -h 18 -ta l -e -p -fn "-misc-terminusmod.icons-medium-r-normal--12-120-72-72-c-60-*-*" &
# pass output to fifo
"$wm"> "$ff"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.