addy-dclxvi

lemonbar

Dec 21st, 2017
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.67 KB | None | 0 0
  1. #! /bin/sh
  2.  
  3. PANEL_FIFO=/tmp/panel-fifo
  4. PANEL_HEIGHT=24
  5. PANEL_FONT_0="-lucy-tewi-medium-r-normal-*-11-90-100-100-c-60-iso10646-1"
  6. PANEL_FONT_1="-wuncon-siji-medium-r-normal-*-10-100-75-75-c-80-iso10646-1"
  7. PANEL_WM_NAME=bspwm_panel
  8.  
  9. COLOR_DEFAULT_FG="#d8dee8"
  10. COLOR_DEFAULT_BG="#2f343f"
  11. COLOR_MONITOR_FG="#d8dee8"
  12. COLOR_MONITOR_BG="#2f343f"
  13. COLOR_FOCUSED_MONITOR_FG="#bf616a"
  14. COLOR_FOCUSED_MONITOR_BG="#144b6c"
  15. COLOR_FREE_FG="#737171"
  16. COLOR_FREE_BG="#2f343f"
  17. COLOR_FOCUSED_FREE_FG="#bf616a"
  18. COLOR_FOCUSED_FREE_BG="#504e4e"
  19. COLOR_OCCUPIED_FG="#d8dee8"
  20. COLOR_OCCUPIED_BG="#2f343f"
  21. COLOR_FOCUSED_OCCUPIED_FG="#bf616a"
  22. COLOR_FOCUSED_OCCUPIED_BG="#504e4e"
  23. COLOR_URGENT_FG="#b48ead"
  24. COLOR_URGENT_BG="#2f343f"
  25. COLOR_FOCUSED_URGENT_FG="#b48ead"
  26. COLOR_FOCUSED_URGENT_BG="#504e4e"
  27. COLOR_STATE_FG="#2f343f"
  28. COLOR_STATE_BG="#2f343f"
  29. COLOR_SYS_FG="#d8dee8"
  30. COLOR_SYS_BG="#2f343f"
  31. COLOR_SYS_AC="#bf616a"
  32.  
  33. trap 'trap - TERM; kill 0' INT TERM QUIT EXIT
  34.  
  35. [ -e "$PANEL_FIFO" ] && rm "$PANEL_FIFO"
  36. mkfifo "$PANEL_FIFO"
  37.  
  38. ## format an icon
  39. icon() {
  40.     case $2 in
  41.         0) printf "%s" "%{F$COLOR_SYS_AC}${1}%{F-}";;
  42.         1) printf "%s" "%{F$COLOR_SYS_FG}${1}%{F-}";;
  43.     esac
  44. }
  45.  
  46. clock() {
  47.     while true; do
  48.         date +"S$(icon  0) %H:%M"
  49.         sleep 15
  50.     done
  51. }
  52.  
  53. music() {
  54.     while true; do
  55.             status=$(mpc status | sed -n '2p')
  56.         case "$status" in
  57.         \[play*)    echo 'M' "$(icon  0) $(mpc current)";;
  58.         \[paused*)  echo 'M' "$(icon  0) $(mpc current)";;
  59.         *)          echo 'M' "$(icon  0) Stopped";;
  60.         esac
  61.         sleep 4;
  62.     done
  63. }
  64.  
  65. clock > "$PANEL_FIFO" &
  66. music > "$PANEL_FIFO" &
  67. bspc subscribe report > "$PANEL_FIFO" &
  68.  
  69. num_mon=$(bspc query -M | wc -l)
  70.  
  71. panel_bar() {
  72. while read -r line ; do
  73.     case $line in
  74.         S*)
  75.             # clock output
  76.             sys="%{F$COLOR_SYS_FG}%{B$COLOR_SYS_BG} ${line#?} %{B-}%{F-}"
  77.             ;;
  78.         M*)
  79.             # music output
  80.             mus="%{F$COLOR_SYS_FG}%{B$COLOR_SYS_BG} ${line#?} %{B-}%{F-}"
  81.             ;;
  82.         W*)
  83.             # bspwm's state
  84.             wm=
  85.             IFS=':'
  86.             set -- ${line#?}
  87.             while [ $# -gt 0 ] ; do
  88.                 item=$1
  89.                 name=${item#?}
  90.                 case $item in
  91.                     [mM]*)
  92.                         case $item in
  93.                             m*)
  94.                                 # monitor
  95.                                 FG=$COLOR_MONITOR_FG
  96.                                 BG=$COLOR_MONITOR_BG
  97.                                 on_focused_monitor=
  98.                                 ;;
  99.                             M*)
  100.                                 # focused monitor
  101.                                 FG=$COLOR_FOCUSED_MONITOR_FG
  102.                                 BG=$COLOR_FOCUSED_MONITOR_BG
  103.                                 on_focused_monitor=1
  104.                                 ;;
  105.                         esac
  106.                         [ $num_mon -lt 2 ] && shift && continue
  107.                         wm="${wm}%{F${FG}}%{B${BG}}%{A:bspc monitor -f ${name}:} ${name} %{A}%{B-}%{F-}"
  108.                         ;;
  109.                     [fFoOuU]*)
  110.                         case $item in
  111.                             f*)
  112.                                 # free desktop
  113.                                 FG=$COLOR_FREE_FG
  114.                                 BG=$COLOR_FREE_BG
  115.                                 UL=$BG
  116.                                 ;;
  117.                             F*)
  118.                                 if [ "$on_focused_monitor" ] ; then
  119.                                     # focused free desktop
  120.                                     FG=$COLOR_FOCUSED_FREE_FG
  121.                                     BG=$COLOR_FOCUSED_FREE_BG
  122.                                     UL=$BG
  123.                                 else
  124.                                     # active free desktop
  125.                                     FG=$COLOR_FREE_FG
  126.                                     BG=$COLOR_FREE_BG
  127.                                     UL=$COLOR_FOCUSED_FREE_BG
  128.                                 fi
  129.                                 ;;
  130.                             o*)
  131.                                 # occupied desktop
  132.                                 FG=$COLOR_OCCUPIED_FG
  133.                                 BG=$COLOR_OCCUPIED_BG
  134.                                 UL=$BG
  135.                                 ;;
  136.                             O*)
  137.                                 if [ "$on_focused_monitor" ] ; then
  138.                                     # focused occupied desktop
  139.                                     FG=$COLOR_FOCUSED_OCCUPIED_FG
  140.                                     BG=$COLOR_FOCUSED_OCCUPIED_BG
  141.                                     UL=$BG
  142.                                 else
  143.                                     # active occupied desktop
  144.                                     FG=$COLOR_OCCUPIED_FG
  145.                                     BG=$COLOR_OCCUPIED_BG
  146.                                     UL=$COLOR_FOCUSED_OCCUPIED_BG
  147.                                 fi
  148.                                 ;;
  149.                             u*)
  150.                                 # urgent desktop
  151.                                 FG=$COLOR_URGENT_FG
  152.                                 BG=$COLOR_URGENT_BG
  153.                                 UL=$BG
  154.                                 ;;
  155.                             U*)
  156.                                 if [ "$on_focused_monitor" ] ; then
  157.                                     # focused urgent desktop
  158.                                     FG=$COLOR_FOCUSED_URGENT_FG
  159.                                     BG=$COLOR_FOCUSED_URGENT_BG
  160.                                     UL=$BG
  161.                                 else
  162.                                     # active urgent desktop
  163.                                     FG=$COLOR_URGENT_FG
  164.                                     BG=$COLOR_URGENT_BG
  165.                                     UL=$COLOR_FOCUSED_URGENT_BG
  166.                                 fi
  167.                                 ;;
  168.                         esac
  169.                         wm="${wm}%{F${FG}}%{B${BG}}%{U${UL}}%{+u}%{A:bspc desktop -f ${name}:} ${name} %{A}%{B-}%{F-}%{-u}"
  170.                         ;;
  171.                     [LTG]*)
  172.                         # layout, state and flags
  173.                         wm="${wm}%{F$COLOR_STATE_FG}%{B$COLOR_STATE_BG} ${name} %{B-}%{F-}"
  174.                         ;;
  175.                 esac
  176.                 shift
  177.             done
  178.             ;;
  179.     esac
  180.     printf "%s\n" "%{l}${wm}%{c}${mus}%{r}${sys}"
  181. done
  182. }
  183.  
  184. panel_bar < "$PANEL_FIFO" | lemonbar -a 32 -u 2 -n "$PANEL_WM_NAME" -g 1066x$PANEL_HEIGHT+150+8 -f "$PANEL_FONT_0" -f "$PANEL_FONT_1" -F "$COLOR_DEFAULT_FG" -B "$COLOR_DEFAULT_BG" | sh &
  185.  
  186. wid=$(xdo id -a "$PANEL_WM_NAME")
  187. xdo above -t "$(xdo id -N Bspwm -n root | sort | head -n 1)" "$wid"
  188.  
  189. wait
Advertisement
Add Comment
Please, Sign In to add comment