Created
November 1, 2012 13:13
-
-
Save radiosilence/3993562 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
ICONPATH=$HOME/.dzen | |
source ~/.colors | |
get_now_playing() { | |
local state | |
local updating | |
local update | |
local string | |
local mpc_2 | |
string=$(mpc -f '^fg(grey85)%title% ^fg(grey40)by ^fg(grey70)%artist% ^fg(grey40)on ^fg(grey70)^fg(grey60)%album%' | head -n 1) | |
mpc_2=$(mpc | head -n 2 | tail -n 1) | |
update=$(mpc | head -n 3 | tail -n 1 | grep 'Updating DB') | |
updating=$? | |
if [ $updating -eq 0 ]; then | |
update=" [updating]" | |
fi | |
state=$(echo $mpc_2 | sed 's/\[\(.*\)\].*/\1/g') | |
case $state in | |
playing) | |
echo -n "^fg(grey70)^i(${ICONPATH}/mpd.xbm)^fg(grey50)^fg(${COLOR3})^p(3)^i(${ICONPATH}/play.xbm)${string}^fg(${COLOR13})$update" | |
;; | |
paused) | |
echo -n "^fg(grey70)^i(${ICONPATH}/mpd.xbm)^fg(grey50)^fg(${COLOR3})^p(3)^i(${ICONPATH}/pause.xbm)${string}^fg(${COLOR13})$update" | |
;; | |
*) | |
echo -n "^fg(grey40)^i(${ICONPATH}/mpd.xbm)^fg(grey60) ^fg(${COLOR13})^p(2)^r(7x7)^p(2)^fg(grey60)" | |
;; | |
esac | |
} | |
# disable path name expansion or * will be expanded in the line | |
# cmd=( $line ) | |
set -f | |
monitor=${1:-0} | |
geometry=( $(herbstclient monitor_rect "$monitor") ) | |
if [ -z "$geometry" ] ;then | |
echo "Invalid monitor $monitor" | |
exit 1 | |
fi | |
# geometry has the format: WxH+X+Y | |
x=${geometry[0]} | |
y=${geometry[1]} | |
panel_width=${geometry[2]} | |
panel_height=18 | |
#font="-*-fixed-medium-*-*-*-12-*-*-*-*-*-*-*" | |
#font="-*-unifont-*-*-*-*-16-*-*-*-*-*-*-*" | |
font="-*-terminus-*-*-*-*-12-*-*-*-*-*-iso10646-*" | |
bgcolor=$(herbstclient get frame_border_normal_color) | |
selbg=$(herbstclient get window_border_active_color) | |
selfg='#101010' | |
#### | |
# Try to find textwidth binary. | |
# In e.g. Ubuntu, this is named dzen2-textwidth. | |
if [ -e "$(which textwidth 2> /dev/null)" ] ; then | |
textwidth="textwidth"; | |
elif [ -e "$(which dzen2-textwidth 2> /dev/null)" ] ; then | |
textwidth="dzen2-textwidth"; | |
else | |
echo "This script requires the textwidth tool of the dzen2 project." | |
exit 1 | |
fi | |
#### | |
# true if we are using the svn version of dzen2 | |
dzen2_version=$(dzen2 -v 2>&1 | head -n 1 | cut -d , -f 1|cut -d - -f 2) | |
if [ -z "$dzen2_version" ] ; then | |
dzen2_svn="true" | |
else | |
dzen2_svn="" | |
fi | |
function uniq_linebuffered() { | |
awk '$0 != l { print ; l=$0 ; fflush(); }' "$@" | |
} | |
herbstclient pad $monitor $panel_height | |
{ | |
# events: | |
mpc idleloop & | |
while true ; do | |
date +'date ^fg(#efefef)%A %B %d, %Y ^fg(#909090)@ ^fg(#efefef)%H:%M' | |
sleep 1 || break | |
done > >(uniq_linebuffered) & | |
# while true ; do | |
# echo "EVENT" | |
# sleep 1 | |
# done | |
childpid=$! | |
herbstclient --idle | |
kill $childpid | |
} 2> /dev/null | { | |
TAGS=( $(herbstclient tag_status $monitor) ) | |
visible=true | |
date="" | |
windowtitle="" | |
while true ; do | |
bordercolor="#26221C" | |
separator="^bg()^fg($selbg)|" | |
# draw tags | |
for i in "${TAGS[@]}" ; do | |
case ${i:0:1} in | |
'#') | |
echo -n "^bg($selbg)^fg($selfg)" | |
;; | |
'+') | |
echo -n "^bg(#9CA668)^fg(#141414)" | |
;; | |
':') | |
echo -n "^bg()^fg(#ffffff)" | |
;; | |
'!') | |
echo -n "^bg(#FF0675)^fg(#141414)" | |
;; | |
*) | |
echo -n "^bg()^fg(#ababab)" | |
;; | |
esac | |
if [ ! -z "$dzen2_svn" ] ; then | |
echo -n "^ca(1,herbstclient focus_monitor $monitor && "'herbstclient use "'${i:1}'") '"${i:1} ^ca()" | |
else | |
echo -n " ${i:1} " | |
fi | |
done | |
echo -n "$separator " | |
get_now_playing | |
echo -n " $separator" | |
echo -n "^bg()^fg() ${windowtitle//^/^^}" | |
# small adjustments | |
right="$separator^bg() $date" | |
right_text_only=$(echo -n "$right"|sed 's.\^[^(]*([^)]*)..g') | |
# get width of right aligned text.. and add some space.. | |
width=$($textwidth "$font" "$right_text_only ") | |
echo -n "^pa($(($panel_width - $width)))$right" | |
# wait for next event | |
echo | |
read line || break | |
cmd=( $line ) | |
# find out event origin | |
case "${cmd[0]}" in | |
tag*) | |
#echo "reseting tags" >&2 | |
TAGS=( $(herbstclient tag_status $monitor) ) | |
;; | |
date) | |
#echo "reseting date" >&2 | |
date="${cmd[@]:1}" | |
;; | |
quit_panel) | |
killall mpc | |
exit | |
;; | |
togglehidepanel) | |
echo "^togglehide()" | |
if $visible ; then | |
visible=false | |
herbstclient pad $monitor 0 | |
else | |
visible=true | |
herbstclient pad $monitor $panel_height | |
fi | |
;; | |
reload) | |
killall mpc | |
exit | |
;; | |
focus_changed|window_title_changed) | |
windowtitle="${cmd[@]:2}" | |
;; | |
# player) | |
# ;; | |
esac | |
done | |
} 2> /dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment