summaryrefslogtreecommitdiff
path: root/herbstluftwm/panel.bar.sh
diff options
context:
space:
mode:
Diffstat (limited to 'herbstluftwm/panel.bar.sh')
-rwxr-xr-xherbstluftwm/panel.bar.sh157
1 files changed, 157 insertions, 0 deletions
diff --git a/herbstluftwm/panel.bar.sh b/herbstluftwm/panel.bar.sh
new file mode 100755
index 0000000..88f7ab1
--- /dev/null
+++ b/herbstluftwm/panel.bar.sh
@@ -0,0 +1,157 @@
+#!/bin/bash
+
+# todo: fontello icons
+
+# disable path name expansion or * will be expanded in the line
+# cmd=( $line )
+set -f
+
+function uniq_linebuffered() {
+ awk -W interactive '$0 != l { print ; l=$0 ; fflush(); }' "$@"
+}
+function get_mpd_song() {
+ # use mpc to get currently playing song, uppercase it
+ song=$(mpc current -f %title%)
+ # let's skip ft. parts, etc. to get some more space
+ echo $song
+}
+
+monitor=${1:-0}
+
+separator="\f3 | \fr"
+song=$(get_mpd_song)
+windowtitle=""
+
+herbstclient pad $monitor 18
+{
+ # events:
+ # mpc events
+ mpc idleloop player &
+ mpc_pid=$!
+
+ # date
+ while true ; do
+ date +'date_day %A %e. '
+ date +'date_min %H:%M '
+ sleep 1 || break
+ done > >(uniq_linebuffered) &
+ date_pid=$!
+
+ while true
+ do
+ $HOME/scripts/battery-parse
+ sleep 2m || break
+ done &
+ battery_pid=$!
+
+ while true
+ do
+ $HOME/scripts/nm-connected-device
+ sleep 3m || break
+ done &
+ nm_status_pid=$!
+
+ # hlwm events
+ herbstclient --idle
+
+ # exiting; kill stray event-emitting processes
+ kill $date_pid $mpd_pid $battery_pid $nm_status_pid
+} 2> /dev/null | {
+ TAGS=( $(herbstclient tag_status $monitor) )
+ #unset TAGS[${#TAGS[@]}-1]
+ date_day=""
+ date_min=""
+ Battery=""
+ network_status=""
+ visible=true
+
+ while true ; do
+ # align left
+ echo -n "\l"
+ if [[ $windowtitle ]]
+ then
+ if [ ${#windowtitle} -gt 55 ]
+ then
+ windowtitle="$(echo -n $windowtitle | cut -c1-55)..."
+ fi
+ echo -n "\ur\fr$windowtitle$separator"
+ fi
+
+ # Align center
+ echo -n "\c"
+ for i in "${TAGS[@]}" ; do
+ case ${i:0:1} in
+ '#') # current tag
+ echo -n "\u4\b4\fr"
+ ;;
+ '+') # active on other monitor
+ echo -n "\u7\b7\f8"
+ ;;
+ ':')
+ # Tag with windows
+ echo -n "\ur\br\f4"
+ ;;
+ '!') # urgent tag
+ echo -n "\u1\br\f1"
+ ;;
+ *)
+ echo -n "\ur\br\fr"
+ ;;
+ esac
+ echo -n " ${i:1} " # | tr '[:lower:]' '[:upper:]'
+ done
+
+ # align right
+ echo -n "\r\ur\fr\br"
+ # display song and separator only if something's playing
+ if [[ $song ]]; then
+ if [ ${#song} -gt 30 ]
+ then
+ song="$(echo -n $song | cut -c1-30)..."
+ fi
+ echo -n "\ur\fr$song$separator"
+ fi
+ echo -n "$network_status"
+ echo -n "$separator"
+ echo -n "$Battery"
+ echo -n "$separator"
+ echo -n "$date_day" | tr '[:lower:]' '[:upper:]'
+ echo -n " \f2"
+ echo -n "$date_min " | tr '[:lower:]' '[:upper:]'
+ echo
+ # wait for next event
+ read line || break
+ cmd=( $line )
+ # find out event origin
+ case "${cmd[0]}" in
+ tag*)
+ TAGS=( $(herbstclient tag_status $monitor) )
+ #unset TAGS[${#TAGS[@]}-1]
+ ;;
+ date_day)
+ date_day="${cmd[@]:1}"
+ ;;
+ date_min)
+ date_min="${cmd[@]:1}"
+ ;;
+ player)
+ song=$(get_mpd_song)
+ ;;
+ focus_changed|window_title_changed)
+ windowtitle="${cmd[@]:2}"
+ ;;
+ Battery)
+ Battery="${cmd[1]} ${cmd[2]}"
+ ;;
+ network)
+ network_status="${cmd[1]} ${cmd[2]}"
+ ;;
+ quit_panel)
+ exit
+ ;;
+ reload)
+ exit
+ ;;
+ esac
+ done
+} 2> /dev/null | bar $1