Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 146 lines (131 sloc) 3.4 KB
#!/bin/bash
### Herbstluftwm Dzen2 Status #########
# Version 20120715-1 by Scott Garrett #
# Wintervenom [(at)] archlinux.us #
#######################################
set -f
## Globals ##
show=(load:L mem:M batt:B temp:T)
sep=':'
clock=1
date_fmt=' %a %m%d:%H%M.%S'
interval=15
font_name='Fantasque Sans Mono'
font_height=10
font_width=$((font_height - (font_height / 4)))
hc='herbstclient'
declare -A tag_colors=(
[':']=$($hc get frame_border_active_color)
['#']=$($hc get window_border_active_color)
)
dzen=(
dzen2 -ta l -sa l
-bg black #"$($hc get frame_bg_normal_color)"
-fg "$($hc get frame_bg_active_color)"
-fn "${font_name}-${font_height}"
-e "button3=togglehide;button5=exec:$hc use_index -1;button4=exec:$hc use_index +1"
)
## Functions ##
cleanup () {
exec 9<&-
rm "$io" 2>/dev/null
kill $(jobs -p) 2>/dev/null
wait
exit
}
get_tags () {
for t in $($hc tag_status); do
[[ ${t:0:1} != '.' ]] &&
echo -n "^ca(1, $hc use ${t:1})[^fg(${tag_colors[${t:0:1}]})${t:1}^fg()]^ca()"
done
echo
}
update_stats () {
local k s stats IFS=':'
for k in "${show[@]}"; do
k=($k)
if type -t "status-$k" >/dev/null; then
IFS=$oifs
s=$("status-$k")
else
case "$k" in
load)
read -d' ' s < /proc/loadavg ;;
mem)
s=$(free -h | awk '/cache:/{print $3}') ;;
batt)
s=$(acpi -b | cut -d' ' -f4) ;;
temp)
s=$(acpi -t | cut -d' ' -f4) ;;
*)
continue ;;
esac
fi
[[ ${k[1]} ]] && s="${k[1]}$sep$s"
stats+=" $s"
done
[[ $1 ]] && stats="($1) $stats"
echo $'update_stats\t'"$stats" >&9
}
clock () {
echo $'clock\t'"$(date "+$date_fmt")"
}
## Main ##
conf_dir="$HOME/.config/hlwm-dzen2"
io="$conf_dir/io"
hooks='(focus|window_title|tag)_changed|update_stats|reload|quit_panel'
mkdir -p "$conf_dir/scripts"
[[ -f "$conf_dir/config" ]] && . "$conf_dir/config"
while read -r file; do
. "$file"
done < <(find "$conf_dir/scripts" -maxdepth 1 -type f \
-not -iregex ".*.\(swp\|tmp\|bak\|old\)\|~.*" | sort -u)
window_id=0
tags=$(get_tags)
oifs=$IFS
trap cleanup INT TERM HUP
rm "$io" 2>/dev/null
mkfifo "$io"
exec 9<&-
exec 9<>"$io"
$hc -i "$hooks" >&9 &
(
if [[ $clock == 1 ]]; then
clock
update_stats
while :; do
sleep 1
clock
((SECONDS % interval == 0)) && { update_stats & }
done
else
echo clock
while :; do
update_stats
sleep $interval
done
fi
) >&9 &
while IFS=$'\t' read -r hook p1 p2; do
if [[ $hook ]]; then
case "$hook" in
clock)
clock=$p1 ;;
tag_changed)
tags=$(get_tags) ;;
focus_changed)
window_id=$p1 window_title=$p2 ;;
window_title_changed)
[[ $p1 == $window_id ]] && window_title=$p2 ;;
update_stats)
stats=$p1
((p = font_width + (${#stats} + ${#clock}) * font_width))
stats="^p(_RIGHT)^p(-$p)$stats"
;;
reload|quit_panel)
break ;;
esac
fi
echo " $tags $window_title $stats$clock"
done <&9 | "${dzen[@]}"
cleanup