#!/bin/bash # CONFIG ## get colors source "$HOME/.config/herbstluftwm/scripts/colors" cFG=${color["white"]}; cBG=${color["black"]}; ## icon dir iDir="$HOME/.config/herbstluftwm/scripts/icons" 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]} width=${geometry[2]} height=16 font="-*-terminus-*-*-*-*-14-*-*-*-*-*-*-*" sep="^fg(${color['gray']})^ro(1x$height)^fg()" align="left" # l, c, r hci="$HOME/.config/herbstluftwm/hci" long_string_cutoff=45 hfsdir="$HOME/.config/herbstluftwm/scripts" # MODULES icon() { # $1=| $2=color if [ ${#1} -eq 1 ]; then # allow also to input letters echo -n "^fg(${color[${2}]})^bg($cBG)${1}^bg()^fg()"; else echo -n "^fg(${color[${2}]})^bg($cBG)^i(${iDir}/${1}.xbm)^bg()^fg()"; fi } herbstags() { local tFG=${color["black"]} # normal tag local tBG=${color["black"]} local tAfg=${color["brightcyan"]} # active tag local tAbg=${color["black"]} local tPfg=${color["gray"]} # populated tag local tPbg=${color["black"]} local tNfg=${color["brightred"]} # urgent (notice) tag local tNbg=${color["black"]} echo -n "$(icon t brightmagenta)[" TAGS=( $(herbstclient tag_status $monitor) ) for i in "${TAGS[@]}"; do local click="^ca(1,herbstclient use ${i:1})" case ${i:0:1} in '#') echo -n "^fg($tAfg)^bg($tAbg)$click${i:1}" ;; ':') echo -n "^fg($tPfg)^bg($tPbg)$click${i:1}" ;; '!') echo -n "^fg($tNfg)^bg($tNbg)$click${i:1}" ;; *) echo -n "" #echo -n "^fg($tFG)^bg($tBG)${i:1}" ;; esac echo -n "^fg()^bg()^ca()" done echo -n "]" } wintitle() { local title="$(xprop -id $(xprop -root _NET_ACTIVE_WINDOW | cut -d' ' -f5) _NET_WM_NAME | sed 's/_NET_WM_NAME.*= "\(.*\)"/\1/')" echo -n "$(cut -c -$long_string_cutoff <<<$title)" } m() { mpc -f %$1% current | sed 's/ä/ae/g' | sed 's/ö/oe/g' | sed 's/ü/ue/g' } tunes() { echo -n "^ca(1,urxvtc -e ncmpcpp)" case "$(mpc | head -2 | tail -1 | awk '{print $1}' | sed 's/\[\(.*\)\]/\1/g')" in playing) local icon="$(icon note brightblue)" local before="[^fg(${color['magenta']})" local playing="$(m artist) | $(m title) | $(m album)]" local after="^fg()]";; paused) local icon="$(icon stop brightblue)" local before="[^fg(${color['gray']})" local playing="$(m artist) | $(m title) | $(m album)" local after="^fg()]";; *) local icon="$(icon note brightblue)" local playing="[]";; esac echo -n "$icon$before$(cut -c -$long_string_cutoff <<<$playing)$after^ca()" } volume() { # $1=channel local stat=$(amixer sget $1 | awk '/\[on\]/{print $4}') if [ -z $stat ]; then local iVol=$(icon spkr_02 white) local stat="^fg(${color["gray"]})$(amixer sget $1 | awk '/\[off\]/{print $4}')^fg()" else local iVol=$(icon spkr_01 brightyellow) fi echo -n "^ca(1,$hfsdir/volume.sh Master toggle)$iVol$stat^ca()" } bat() { local status=$(acpi | awk '{print $3}' | sed 's/,//') local percent=$(acpi | awk '{print $4}' | sed 's/[,%]//g') case $status in Discharging) power_color="brightmagenta"; pwr_sign="-" ;; Charging) power_color="brightgreen"; pwr_sign="+";; Full) power_color="brightblue"; pwr_sign="";; esac local lo_power=15; local hi_power=75; if [ $percent -le $lo_power ]; then power_icon="bat_empty_01"; elif [ $percent -gt $lo_power ] && [ $percent -le $hi_power ]; then power_icon="bat_low_01" elif [ $percent -gt $hi_power ] && [ $percent -lt 100 ]; then power_icon="bat_full_01" elif [ $percent -eq 100 ]; then power_icon="ac_01" fi echo -n "$(icon ${power_icon} ${power_color})[$pwr_sign$percent%]" } wifi() { # $1=interface iwconfig $1 | awk '/Quality/ {print $2}' | sed 's/.*=//' | \ awk -F"/" '{printf("%.0f%%\n", $1/$2*100)}' } eth() { # (internet) $1=interface ifconfig $1 | awk -F: '/inet addr:/ {print $2}' | sed 's/[^0-9.]//g' } net() { local prog="urxvtc -e wicd-curses" if [ -n "$(wifi wlan0)" ]; then local Net="$(icon wifi_02 brightyellow)[$(wifi wlan0)]"; elif [ -n "$(eth eth0)" ]; then local Net="$(icon net_wired brightblue)[$(eth eth0)]"; else local Net="$(icon i brightred)[]"; fi echo -n "^ca(1,$prog)$Net^ca()" } mail() { # $1=user $2=pass local prog="urxvt -c mutt" local mail_feed="https://mail.google.com/mail/feed/atom" local new=$(curl -u "$1":"$2" --silent $mail_feed | grep "" | \ sed 's/<\/\?\w\+>//g') if [[ $new -gt 0 && "$(net)" != "$(icon i brightred)[]" ]]; then echo -n "^ca(1,$prog)$(icon mail brightcyan)[$new]^ca()"; else echo -n ""; fi } # GETTING THINGS DONE function uniq_linebuffered() { awk '$0 != l { print ; l=$0 ; fflush(); }' "$@" } herbstclient pad $monitor $height ( while true ; do date +"date $(icon clock brightgreen)[$(date +"%H.%M %a.%d")]" mpcshow="$(tunes)" echo "mpc $mpcshow $sep" Bat="$(bat)" echo "bat $Bat $sep" Net="$(net) " echo "net $Net" Mail="$(mail user pass)" echo "mail $Mail $sep" sleep 1 || break done | uniq_linebuffered & herbstclient --idle & )|( Tag="$(herbstags) $sep" date="" mpcshow="" Title="" Volume="$(volume Master) $sep" while true; do #echo -n "$Tag $Title $mpcshow $Volume $Bat $Net$Mail $date" echo -n "$Tag $Title" # right alignment right="" for func in $mpcshow $Volume $Bat $Net $Mail $date; do right="${right} ${func}" done 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 "^p(_RIGHT)^p(-$width)$right" echo # listen for events read line || break cmd=( $line ) case "$cmd[0]" in date*) date="${cmd[@]:1}" ;; tag*) Tag="$(herbstags) $sep" ;; mpc*) mpcshow="${cmd[@]:1}" ;; focus*|*title*) Title="$(wintitle)" ;; volume*) Volume="$(volume Master) $sep" ;; bat*) Bat="${cmd[@]:1}" ;; net*) Net="${cmd[@]:1} " ;; mail*) Mail="${cmd[@]:1}" ;; quit_panel*) exit 0 ;; reload*) exit 0 ;; esac done )|dzen2 -w $width -h $height -x $x -y $y -fn "$font" \ -ta $align -bg "$cBG" -fg "$cFG"