Guest User

Untitled

a guest
Jun 13th, 2014
329
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env sh
  2.  
  3. # expects a line from monsterwm's output as argument ("$1")
  4. # prints formatted output to be used as input for bar
  5. # reference: bar by LemonBoy -- https://github.com/LemonBoy/bar
  6.  
  7. # desktop status
  8. for desk; do
  9. d="${desk%%:*}" desk="${desk#*:}" # desktop id
  10. w="${desk%%:*}" desk="${desk#*:}" # window count
  11. l="${desk%%:*}" desk="${desk#*:}" # layout mode
  12. c="${desk%%:*}" desk="${desk#*:}" # is current desktop
  13. u="$desk" # has urgent hint
  14.  
  15. # desktop id
  16. case "$d" in
  17. 0) d=" \f2\\fr term" ;; 1) d=" \f4\\fr web" ;;
  18. 2) d=" \f3\\fr japan " ;; 3) d=" \f1\\fr files " ;;
  19. esac
  20.  
  21. # current desktop
  22. if [ $c -ne 0 ]
  23. then bg="\b0" un="\u6" fg="\f9"
  24. case "$l" in
  25. 0) s="" ;; 1) s="" ;; 2) s="" ;;
  26. 3) s="" ;; 4) s="" ;; 5) s="" ;;
  27. esac && s="\b8\u8 $s \br\ur"
  28. fi
  29.  
  30. # has urgent hint or no windows
  31. [ $u -ne 0 ] && un="\u2"
  32. [ $w -eq 0 ] && w="-"
  33.  
  34. in="$in$bg$fg$un $d \f5[$w] \ur\br\fr"
  35. unset bg fg un
  36. done
  37.  
  38. # torrent status
  39. torrent_status="$(transmission-remote -l | awk '$2!="100%"&&$5~/^[[:digit:]]+$/{t=$5" "$6;s=$(11);for(i=12; i<=NF; ++i)s=s" "$i;exit}END{if(s)print t" :: "s}')"
  40. [ -z "$torrent_status" ] && torrent_status="Idle"
  41.  
  42. # music status
  43. music=$(cmus-remote -Q | awk '$2 == "artist"{a=substr($0,12)} $2 == "title"{t=substr($0,11); exit} END{printf("%s - %s\n",a,t); exit(!t)}')
  44. [ $? -ne 0 ] && mstat="\f3\fr" music="Not playing" || mstat="\f3\fr"
  45.  
  46.  
  47. # volume status
  48. if [ "$(amixer get Master | sed -nr '$ s:.*\[(.+)]$:\1:p')" == "off" ]
  49. then vol="[m]" vstat="volume:"
  50. else
  51. vol="$(amixer get PCM | sed -nr '$ s:.*\[(.+%)].*:\1:p')"
  52. if [ "${vol%\%}" -le 10 ]; then vstat=""
  53. elif [ "${vol%\%}" -le 20 ]; then vstat="";
  54. else vstat=""; fi
  55. fi
  56.  
  57. # window title
  58. wname=$(xtitle)
  59.  
  60.  
  61. # date and time
  62. date="$(date +"%a %d %b %R")" dstat="\f6\fr"
  63.  
  64. # symbols
  65. arrow=""
  66. tor="\f4\fr"
  67.  
  68. # left statusbar info
  69. printf '\\l'
  70. printf '%s ' "$in" "$arrow" "$s"
  71.  
  72. # center statusbar info
  73. printf '\\c'
  74. printf '\\b7\\u7 %s \\br\\ur\\fr' "$wname"
  75.  
  76. # right statusbar info
  77. printf '\\r'
  78. printf '\\b7\\u0\\f1 %s \\br\\ur\\fr %s ' \
  79. "$tor" "$torrent_status" \
  80. "$mstat" "$music" \
  81. "$vstat" "$vol" \
  82. "$dstat" "$date"
  83.  
  84. # end of statusbar info
  85. printf '\n'
RAW Paste Data