#!/usr/bin/env bash wm=monsterwm ff="/tmp/$RANDOM.monsterwm.fifo" tags=('■' '■' '■' '■' '■') layouts=('' '' '' '' '') [[ -p $ff ]] || mkfifo -m 600 "$ff" function statusbar { sdate=" \b0\f7\u0  \b0\f1\u0" date="$(date +"%H:%M")" music="$(mpc current -f "%artist% - [%title%|%file%]")" if [ -z "$music" ]; then music="" smusic="" else smusic="$(mpc | sed -rn '2s/\[([[:alpha:]]+)].*/\1/p')" [ "$smusic" == "paused" ] && smusic=" \b0\f6\u0  \b0\f1\u0" || smusic=" \b0\f6\u0  \b0\f1\u0" fi if [ "$(amixer get Master | sed -nr '$ s:.*\[(.+)]$:\1:p')" == "off" ]; then vol="" svol="" else vol="$(amixer get Master | sed -nr '$ s:.*\[(.+%)].*:\1:p')" if [ "${vol%\%}" -le 10 ]; then svol=" \b0\f6\u0  \b0\f1\u0" elif [ "${vol%\%}" -le 20 ]; then svol=" \b0\f6\u0  \b0\f1\u0" else svol=" \b0\f6\u0  \b0\f1\u0" fi fi mem=$(free -m | awk '/buffers\/cache/ {print $3 MB}') if [ $mem -ge 1500 ]; then mem="$mem MB" smem="\b0\f3\u0  \b0\f1\u3" elif [ $mem -ge 800 ]; then mem="$mem MB" smem="\b0\f6\u0  \b0\f1\u0" else mem="" fi win=$(xdotool getactivewindow getwindowname) echo -n "$win \r $smem$mem$svol$vol$smusic$music$sdate$date " } while read -t "0.1" -r wmout || true; do if [[ $wmout =~ ^(([[:digit:]]+:)+[[:digit:]]+ ?)+$ ]]; then read -ra desktops <<< "$wmout" tmp= for desktop in "${desktops[@]}"; do IFS=':' read -r d w m c u <<< "$desktop" # Tags labels label=${tags[$d]} # Current desktop color and enclosing char (yes/no) ((c)) && fg="7" bg="2" lc="\u7 " rc=" \ur" && layout=${layouts[$m]} || fg="1" bg="0" lc=" " rc=" " # Has windows ? ((w == 1)) && ((! c)) && fg="6" lc="\u0 " rc=" \ur" ((w == 2)) && ((! c)) && fg="5" lc="\u0 " rc=" \ur" ((w == 3)) && ((! c)) && fg="4" lc="\u0 " rc=" \ur" ((w >= 4)) && ((! c)) && fg="3" lc="\u0 " rc=" \ur" # Urgent windows ? ((u)) && fg="3" bg="1" lc="\u3 " rc=" \ur" tmp+="\f$fg\b$bg$lc$label$rc\fr\br" done # Merge the clients indications and the tile mode tmp+=" \u0\f7\b0|\u0\b0\f1 $layout \u0\b0\f7|\u0\b0\f1 " fi echo "$tmp $(statusbar)" done < "$ff" | bar & $wm > "$ff" rm $ff