Skip to content

Instantly share code, notes, and snippets.

/lemonbar.sh Secret

Created April 8, 2016 07:55
Show Gist options
  • Save anonymous/d1be0f0c469269643a3e2a010fbfa9ad to your computer and use it in GitHub Desktop.
Save anonymous/d1be0f0c469269643a3e2a010fbfa9ad to your computer and use it in GitHub Desktop.
#!/bin/sh
# Main panel parameters
GEOMETRY="1280x18x0x0"
BCKGRND="#333333"
FRGRND="#d4d0c8"
UNDRLN="#d4d0c8"
FONT_I='Fira Mono:Medium:size=9'
FONT_II='FontAwesome:size=11'
# Separator
BarSprtr()
{
echo "%{F#555555} | %{F-}"
}
# Dmenu as a "start button". "%{T2}" and "%{T1}" things means font #1 and font #2
# slots/shortcuts.
BarDmenu()
{
Dmenu_display="%{T2} %{T1}"
Dmenu_cmd='dmenu_run -i -nb "#D4D0C8" -sb "#333333" -sf "#D4D0C8"'
echo "%{A:$Dmenu_cmd:}$Dmenu_display%{A}"
}
# Interactive tags indicator. Left click is supported as well as a scroll
# (tat+/tag-). Current tab indicated by underline.
BarTags()
{
CURTAG=$(xprop -root _NET_CURRENT_DESKTOP | awk '{print $3}')
if [ "$CURTAG" = "0" ]
then
tag_one="%{+u+o} term %{-u-o}"
else
tag_one="term"
fi
tag_one_cmd="xdotool set_desktop 0"
if [ "$CURTAG" = "1" ]
then
tag_two="%{+u+o} www %{-u-o}"
else
tag_two="www"
fi
tag_two_cmd="xdotool set_desktop 1"
if [ "$CURTAG" = "2" ]
then
tag_three="%{+u+o} text %{-u-o}"
else
tag_three="text"
fi
tag_three_cmd="xdotool set_desktop 2"
if [ "$CURTAG" = "3" ]
then
tag_four="%{+u+o} media %{-u-o}"
else
tag_four="media"
fi
tag_four_cmd="xdotool set_desktop 3"
PrevTag="xdotool set_desktop $(($(xdotool get_desktop)-1))"
NextTag="xdotool set_desktop $(($(xdotool get_desktop)+1))"
AllTags="%{A:$tag_one_cmd:}$tag_one%{A} %{A:$tag_two_cmd:}$tag_two%{A} \
%{A:$tag_three_cmd:}$tag_three%{A} %{A:$tag_four_cmd:}$tag_four%{A}"
echo "%{A4:$PrevTag:}%{A5:$NextTag:}$AllTags%{A}%{A}"
}
# Current window name or root window name if there's no active window.
# BarCWindow()
# {
# CWINDOW=$(xprop -id $(xprop -root _NET_ACTIVE_WINDOW | awk '{print $5}') | grep "_NET_WM_NAME" | cut -c 29- | sed 's/^.\(.*\).$/\1/' | cut -c -40 2> /dev/null)
# ROOTWINDOW=$(xprop -root WM_NAME | cut -c 19- | sed 's/^.\(.*\).$/\1/' 2> /dev/null)
# if [ -n "$CWINDOW" ]
# then
# echo " ${CWINDOW}"
# else
# echo "${ROOTWINDOW}"
# fi
# }
BarMusak()
{
if [ -n "$(pidof cmus)" ]
then
State=$(cmus-remote -Q 2> /dev/null | grep status | cut -d " " -f 2-)
Artist=$(cmus-remote -Q 2> /dev/null | grep "tag artist " | cut -d " " -f 3-)
Title=$(cmus-remote -Q 2> /dev/null | grep title | cut -d " " -f 3-)
Stream=$(cmus-remote -Q 2> /dev/null | grep stream | cut -d " " -f 2-)
Filename=$(cmus-remote -Q 2> /dev/null | grep file | cut -d " " -f 2- | xargs -0 basename)
Muspause="cmus-remote -u"
Musprev="cmus-remote -r"
Musnext="cmus-remote -n"
Musvolmin="cmus-remote -v -2%"
Musvolpl="cmus-remote -v +2%"
if [ "$State" = "playing" ]
then
State=""
elif [ "$State" = "stopped" ]
then
State=""
elif [ "$State" = "paused" ]
then
State=""
fi
if [ -n "$Stream" ]
then
MusDisplay="$State $Stream"
elif [ -n "$Artist" ] && [ -n "$Title" ]
then
if [ -n "$Artist" ]
then
Artist=" $Artist — "
fi
if [ -n "$Title" ]
then
Title="$Title"
fi
MusDisplay="$State $Artist$Title"
else
MusDisplay="$State $Filename"
fi
MusDisplay=$(echo $MusDisplay | cut -c -60 2> /dev/null)
echo "%{A1:$Musprev:}%{A2:$Muspause:}%{A3:$Musnext:}%{A5:$Musvolmin:}%{A4:$Musvolpl:}$MusDisplay%{A}%{A}%{A}%{A}%{A}"
fi
}
BarWeather()
{
weatherURL='http://www.accuweather.com/en/ru/omsk/294463/weather-forecast/294463'
weather=$(wget -q -T 1 -O- "$weatherURL" | awk -F\' '/acm_RecentLocationsCarousel\.push/{print $10"°C" }'| head -1)
echo " $weather"
}
# Keyboard layout. Stupid dirty hack that uses an LED-indicators state, which
# can be setted to indicate current layout. In my case that's scroll lock LED.
BarKeyboard()
{
KbdLayout=$(xset q | grep LED | cut -c66)
case $KbdLayout in
[4567]) KbdLayout=" %{U#86ABD9}%{+u}Ru%{-u}%{U-}";;
[0123]) KbdLayout=" %{U#D70751}%{+u}En%{-u}%{U-}";;
esac
echo "$KbdLayout"
}
# Volume (alsa Master channel) state. Will dim volume color and change icon
# if it's muted. Also clickable (terminal with alsamixer).
BarVolume()
{
Vol_Stts=$(amixer get PCM | tail -n 1 | cut -d '[' -f 4 | sed 's/].*//g')
Vol_Lvl=$(amixer get PCM | tail -n 1 | cut -d '[' -f 2 | sed 's/%.*//g')
Vol_Plus="amixer set PCM 1%+"
Vol_Mns="amixer set PCM 1%-"
Vol_Mute="amixer set PCM toggle"
if [ "$Vol_Stts" = "on" ]
then
display="%{T2}%{T1} $Vol_Lvl"
else
display="%{T2}%{T1}%{F#909090} $Vol_Lvl%{F-}"
fi
Vol_Mix="xfce4-terminal -x alsamixer"
echo "%{A1:$Vol_Mix:}%{A3:$Vol_Mute:}%{A4:$Vol_Plus:}%{A5:$Vol_Mns:}$display%{A}%{A}%{A}%{A}"
}
# Just clock + "cal" application in a terminal on a left click.
BarClock()
{
DATE=$(date "+%a, %d %b ")
TIME=$(date "+%H:%M")
# echo -n "%{T2}%{T1} %{F#909090}$DATE%{F-}"
Clock_display="%{T2}%{T1} %{F#d4d0c8}$TIME"
Clock_cmd="xfce4-terminal --hide-borders --geometry=22x9 -x bash -c 'ncal -Mb ; read'"
echo "%{A:$Clock_cmd:}$Clock_display%{A}"
}
# Stupid logout button that shows fancy dialog-based logout window lo a left click.
BarLogout()
{
Logout_display="%{T2} %{T1}"
Logout_cmd="xfce4-terminal --hide-borders --geometry=47x15 -x bbqexit.sh"
echo "%{A:$Logout_cmd:}$Logout_display%{A} "
}
# Summary of all things above piped to the lemonbar and to /bin/sh (for buttons/commands).
while true ; do
echo "%{l}$(BarDmenu)$(BarSprtr)$(BarTags)$(BarSprtr)\
%{r}$(BarMusak)$(BarSprtr)$(BarWeather)$(BarSprtr)$(BarKeyboard)$(BarSprtr)$(BarVolume)$(BarSprtr)$(BarClock)$(BarSprtr)$(BarLogout)"
sleep 0.5
done | lemonbar -d -a 20 -g $GEOMETRY -n 'lemonbar-top' -u 2 -B $BCKGRND -F $FRGRND -U $UNDRLN -f "$FONT_I" -f "$FONT_II" -p | sh &
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment