Last active
October 14, 2015 21:00
-
-
Save Ferdi265/0d8349a34c80174ab54e to your computer and use it in GitHub Desktop.
Lemonbar script for i3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# calculate workspace indicators (needs jshon) | |
workspaces() { | |
wtext=('%{F#174652}' '%{F#174652}' '%{F#174652}' '%{F#174652}' '%{F#174652}' '%{F#174652}' '%{F#174652}' '%{F#174652}' '%{F#174652}' '%{F#174652}') | |
wjson=$(jshon -a -j) | |
for w in $wjson; do | |
vars=($(echo $w | jshon -e num -u -p -e urgent -u -p -e focused -u -p -e visible -u)) | |
num=$((${vars[0]} - 1)) | |
if [[ ${vars[1]} == 'true' ]]; then | |
wtext[$num]='%{B#cb4b16}%{F#002b36}' | |
elif [[ ${vars[2]} == 'true' ]]; then | |
wtext[$num]='%{B#859900}%{F#002b36}' | |
elif [[ ${vars[3]} == 'true' ]]; then | |
wtext[$num]='%{B#268bd2}%{F#002b36}' | |
else | |
wtext[$num]='%{F-}' | |
fi | |
done | |
num=1 | |
for w in ${wtext[@]}; do | |
echo -n "$w%{A:s$num:}%{A3:m$num:} %{A}%{A}%{B-}" | |
num=$(($num + 1)) | |
done | |
} | |
# read /tmp/i3mode-$DISPLAY | |
modedisplay() { | |
m=$(cat /tmp/i3mode-$DISPLAY) | |
[[ $m == default ]] && return | |
echo -n "%{B#859900}%{F#002b36} $m mode %{B-}%{F-}" | |
} | |
# render loop, needs specially built lemonbar (from my Github), and the FontAwesome icon font | |
while true; do | |
# left - workspaces, mode | |
# left click indicator to focus workspace | |
# right click indicator to move workspace there | |
# empty indicators can be clicked | |
# center - active window title | |
# right - close window, time | |
echo "%{c}"$(xdotool getactivewindow getwindowname 2>/dev/null)"%{l}"$(i3-msg -t get_workspaces | workspaces)"%{B-}%{F-}"$(modedisplay)"%{r}"$(date '+%F %T')" %{B#cb4b16}%{F#002b36}%{A:k:} %{A}%{B-}%{F-}" | |
sleep 0.2 | |
done | lemonbar -S 21 -f 'DejaVu Sans:bold:size=10' -f 'FontAwesome' -B '#174652' -F '#fdf6e3' | while read -n1 cmd; do case $cmd in | |
s) read num; i3-msg -t command workspace $num;; | |
m) read num; i3-msg -t command move container to workspace $num;; | |
k) i3-msg -t command kill;; | |
esac; done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment