Want more features on Pastebin? Sign Up, it's FREE!
Guest

wmrun.sh

By: a guest on Mar 29th, 2014  |  syntax: Bash  |  size: 2.63 KB  |  views: 81  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/usr/bin/env bash
  2.  
  3. wm=monsterwm
  4. ff="/tmp/$RANDOM.monsterwm.fifo"
  5.  
  6. tags=('■' '■' '■' '■' '■')
  7. layouts=('' '' '' '' '')
  8.  
  9. [[ -p $ff ]] || mkfifo -m 600 "$ff"
  10.  
  11. function statusbar
  12. {
  13.         sdate=" \b0\f7\u0  \b0\f1\u0" date="$(date +"%H:%M")"
  14.  
  15.     music="$(mpc current -f "%artist% - [%title%|%file%]")"
  16.     if [ -z "$music" ]; then
  17.         music="" smusic=""
  18.     else
  19.         smusic="$(mpc | sed -rn '2s/\[([[:alpha:]]+)].*/\1/p')"
  20.         [ "$smusic" == "paused" ] && smusic=" \b0\f6\u0  \b0\f1\u0" || smusic=" \b0\f6\u0  \b0\f1\u0"
  21.     fi
  22.  
  23.     if [ "$(amixer get Master | sed -nr '$ s:.*\[(.+)]$:\1:p')" == "off" ]; then
  24.         vol="" svol=""
  25.     else
  26.         vol="$(amixer get Master | sed -nr '$ s:.*\[(.+%)].*:\1:p')"
  27.         if [ "${vol%\%}" -le 10 ]; then
  28.             svol=" \b0\f6\u0  \b0\f1\u0"
  29.         elif [ "${vol%\%}" -le 20 ]; then
  30.             svol=" \b0\f6\u0  \b0\f1\u0"
  31.         else
  32.             svol=" \b0\f6\u0  \b0\f1\u0"
  33.         fi
  34.     fi
  35.  
  36.     mem=$(free -m | awk '/buffers\/cache/ {print $3 MB}')
  37.     if [ $mem -ge 1500 ]; then
  38.         mem="$mem MB" smem="\b0\f3\u0  \b0\f1\u3"
  39.     elif [ $mem -ge 800 ]; then
  40.         mem="$mem MB" smem="\b0\f6\u0  \b0\f1\u0"
  41.     else
  42.         mem=""
  43.     fi
  44.       win=$(xdotool getactivewindow getwindowname)
  45.  
  46.     echo -n "$win \r  $smem$mem$svol$vol$smusic$music$sdate$date "
  47. }
  48.  
  49. while read -t "0.1" -r wmout || true; do
  50.     if [[ $wmout =~ ^(([[:digit:]]+:)+[[:digit:]]+ ?)+$ ]]; then
  51.         read -ra desktops <<< "$wmout"
  52.  
  53.         tmp=
  54.         for desktop in "${desktops[@]}"; do
  55.             IFS=':' read -r d w m c u <<< "$desktop"
  56.             # Tags labels
  57.             label=${tags[$d]}
  58.             # Current desktop color and enclosing char (yes/no)
  59.             ((c)) && fg="7" bg="2" lc="\u7 " rc=" \ur" && layout=${layouts[$m]} || fg="1" bg="0" lc=" " rc=" "
  60.             # Has windows ?
  61.             ((w == 1)) && ((! c)) &&
  62.               fg="6" lc="\u0 " rc=" \ur"
  63.             ((w == 2)) && ((! c)) &&
  64.               fg="5" lc="\u0 " rc=" \ur"
  65.             ((w == 3)) && ((! c)) &&
  66.               fg="4" lc="\u0 " rc=" \ur"
  67.             ((w >= 4)) && ((! c)) &&
  68.               fg="3" lc="\u0 " rc=" \ur"
  69.             # Urgent windows ?
  70.             ((u)) && fg="3" bg="1" lc="\u3 " rc=" \ur"
  71.  
  72.             tmp+="\f$fg\b$bg$lc$label$rc\fr\br"
  73.         done
  74.         # Merge the clients indications and the tile mode
  75.         tmp+=" \u0\f7\b0|\u0\b0\f1 $layout \u0\b0\f7|\u0\b0\f1 "
  76.     fi
  77.     echo "$tmp $(statusbar)"
  78. done < "$ff" | bar &
  79.  
  80. #while :; do "$wm" || break; done | tee -a "$ff"
  81. $wm > "$ff"
  82.  
  83. rm $ff
clone this paste RAW Paste Data