Advertisement
addy-dclxvi

panel-bspwm

Feb 25th, 2018
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.87 KB | None | 0 0
  1. #! /bin/sh
  2. # based on default example from bspwm github
  3.  
  4. PANEL_FIFO=/tmp/panel-fifo
  5. PANEL_HEIGHT=24
  6. PANEL_FONT_0="-lucy-tewi-medium-r-normal-*-11-90-100-100-c-60-iso10646-1"
  7. PANEL_FONT_1="-wuncon-siji-medium-r-normal-*-10-100-75-75-c-80-iso10646-1"
  8. PANEL_WM_NAME=bspwm_panel
  9.  
  10. COLOR_DEFAULT_FG="#474c57"
  11. COLOR_DEFAULT_BG="#ffffff"
  12. COLOR_MONITOR_FG="#474c57"
  13. COLOR_MONITOR_BG="#ffffff"
  14. COLOR_FOCUSED_MONITOR_FG="#474c57"
  15. COLOR_FOCUSED_MONITOR_BG="#f6bfc5"
  16. COLOR_FREE_FG="#dde1e8"
  17. COLOR_FREE_BG="#ffffff"
  18. COLOR_FOCUSED_FREE_FG="#474c57"
  19. COLOR_FOCUSED_FREE_BG="#ef6b7b"
  20. COLOR_OCCUPIED_FG="#474c57"
  21. COLOR_OCCUPIED_BG="#ffffff"
  22. COLOR_FOCUSED_OCCUPIED_FG="#474c57"
  23. COLOR_FOCUSED_OCCUPIED_BG="#ef6b7b"
  24. COLOR_URGENT_FG="#b48ead"
  25. COLOR_URGENT_BG="#ffffff"
  26. COLOR_FOCUSED_URGENT_FG="#b48ead"
  27. COLOR_FOCUSED_URGENT_BG="#504e4e"
  28. COLOR_STATE_FG="#ffffff"
  29. COLOR_STATE_BG="#ffffff"
  30. COLOR_SYS_FG="#474c57"
  31. COLOR_SYS_BG="#ffffff"
  32. COLOR_SYS_AC="#ef6b7b"
  33.  
  34. trap 'trap - TERM; kill 0' INT TERM QUIT EXIT
  35.  
  36. [ -e "$PANEL_FIFO" ] && rm "$PANEL_FIFO"
  37. mkfifo "$PANEL_FIFO"
  38.  
  39. ## format an icon
  40. icon() {
  41.     case $2 in
  42.         0) printf "%s" "%{F$COLOR_SYS_AC}${1}%{F-}";;
  43.         1) printf "%s" "%{F$COLOR_SYS_FG}${1}%{F-}";;
  44.     esac
  45. }
  46.  
  47. clock() {
  48.     while true; do
  49.         date +"S$(icon  0) %H:%M"
  50.         sleep 15
  51.     done
  52. }
  53.  
  54. music() {
  55.     while true; do
  56.         status=$(mpc status | sed -n '2p')
  57.         case "$status" in
  58.         \[play*)    echo 'M' "$(icon  0) $(mpc current)";;
  59.         \[paused*)  echo 'M' "$(icon  0) $(mpc current)";;
  60.         *)          echo 'M' "$(icon  0) Stopped";;
  61.         esac
  62.         sleep 4;
  63.     done
  64. }
  65.  
  66. wifi() {
  67.     while true; do
  68.         network_id=$(/sbin/iwgetid -r)
  69.         if [ -n "$network_id" ]
  70.         then
  71.         echo 'N' "$(icon  0) "$network_id"";
  72.         else
  73.         echo 'N' "$(icon  0) offline";
  74.         fi
  75.         sleep 15;
  76.     done
  77. }
  78.  
  79. battery() {
  80.     while true; do
  81.         battery_status=$(cat /sys/class/power_supply/BAT1/status)
  82.         battery_percent=$(cat /sys/class/power_supply/BAT1/capacity)
  83.         case "$battery_status" in
  84.             Charging) echo 'B' "$(icon  0) ${battery_percent}";;
  85.             Discharging)
  86.             if [ "$battery_percent" -gt 80 ]
  87.             then
  88.             echo 'B' "$(icon  0) ${battery_percent}"
  89.             elif [ "$battery_percent" -gt 30 ]
  90.             then
  91.             echo 'B' "$(icon  0) ${battery_percent}"
  92.             else
  93.             echo 'B' "$(icon  0) ${battery_percent}"
  94.             fi
  95.             ;;
  96.         Unknown|Full) echo 'B' "$(icon  0) 100%";;
  97.     esac
  98.     sleep 30;
  99.     done
  100. }
  101.  
  102. clock > "$PANEL_FIFO" &
  103. music > "$PANEL_FIFO" &
  104. wifi > "$PANEL_FIFO" &
  105. battery > "$PANEL_FIFO" &
  106. bspc subscribe report > "$PANEL_FIFO" &
  107.  
  108. num_mon=$(bspc query -M | wc -l)
  109.  
  110. panel_bar() {
  111. while read -r line ; do
  112.     case $line in
  113.         B*)
  114.             # bat
  115.             bat="%{F$COLOR_SYS_FG}%{B$COLOR_SYS_BG} ${line#?} %{B-}%{F-}";;
  116.         N*)
  117.             # net
  118.             net="%{F$COLOR_SYS_FG}%{B$COLOR_SYS_BG} ${line#?} %{B-}%{F-}";;
  119.         S*)
  120.             # clock output
  121.             sys="%{F$COLOR_SYS_FG}%{B$COLOR_SYS_BG} ${line#?} %{B-}%{F-}"
  122.             ;;
  123.         M*)
  124.             # music output
  125.             mus="%{F$COLOR_SYS_FG}%{B$COLOR_SYS_BG} ${line#?} %{B-}%{F-}"
  126.             ;;
  127.         W*)
  128.             # bspwm's state
  129.             wm=
  130.             IFS=':'
  131.             set -- ${line#?}
  132.             while [ $# -gt 0 ] ; do
  133.                 item=$1
  134.                 name=${item#?}
  135.                 case $item in
  136.                     [mM]*)
  137.                         case $item in
  138.                             m*)
  139.                                 # monitor
  140.                                 FG=$COLOR_MONITOR_FG
  141.                                 BG=$COLOR_MONITOR_BG
  142.                                 on_focused_monitor=
  143.                                 ;;
  144.                             M*)
  145.                                 # focused monitor
  146.                                 FG=$COLOR_FOCUSED_MONITOR_FG
  147.                                 BG=$COLOR_FOCUSED_MONITOR_BG
  148.                                 on_focused_monitor=1
  149.                                 ;;
  150.                         esac
  151.                         [ $num_mon -lt 2 ] && shift && continue
  152.                         wm="${wm}%{F${FG}}%{B${BG}}%{A:bspc monitor -f ${name}:} ${name} %{A}%{B-}%{F-}"
  153.                         ;;
  154.                     [fFoOuU]*)
  155.                         case $item in
  156.                             f*)
  157.                                 # free desktop
  158.                                 FG=$COLOR_FREE_FG
  159.                                 BG=$COLOR_FREE_BG
  160.                                 UL=$BG
  161.                                 ;;
  162.                             F*)
  163.                                 if [ "$on_focused_monitor" ] ; then
  164.                                     # focused free desktop
  165.                                     FG=$COLOR_FOCUSED_FREE_FG
  166.                                     BG=$COLOR_FOCUSED_FREE_BG
  167.                                     UL=$BG
  168.                                 else
  169.                                     # active free desktop
  170.                                     FG=$COLOR_FREE_FG
  171.                                     BG=$COLOR_FREE_BG
  172.                                     UL=$COLOR_FOCUSED_FREE_BG
  173.                                 fi
  174.                                 ;;
  175.                             o*)
  176.                                 # occupied desktop
  177.                                 FG=$COLOR_OCCUPIED_FG
  178.                                 BG=$COLOR_OCCUPIED_BG
  179.                                 UL=$BG
  180.                                 ;;
  181.                             O*)
  182.                                 if [ "$on_focused_monitor" ] ; then
  183.                                     # focused occupied desktop
  184.                                     FG=$COLOR_FOCUSED_OCCUPIED_FG
  185.                                     BG=$COLOR_FOCUSED_OCCUPIED_BG
  186.                                     UL=$BG
  187.                                 else
  188.                                     # active occupied desktop
  189.                                     FG=$COLOR_OCCUPIED_FG
  190.                                     BG=$COLOR_OCCUPIED_BG
  191.                                     UL=$COLOR_FOCUSED_OCCUPIED_BG
  192.                                 fi
  193.                                 ;;
  194.                             u*)
  195.                                 # urgent desktop
  196.                                 FG=$COLOR_URGENT_FG
  197.                                 BG=$COLOR_URGENT_BG
  198.                                 UL=$BG
  199.                                 ;;
  200.                             U*)
  201.                                 if [ "$on_focused_monitor" ] ; then
  202.                                     # focused urgent desktop
  203.                                     FG=$COLOR_FOCUSED_URGENT_FG
  204.                                     BG=$COLOR_FOCUSED_URGENT_BG
  205.                                     UL=$BG
  206.                                 else
  207.                                     # active urgent desktop
  208.                                     FG=$COLOR_URGENT_FG
  209.                                     BG=$COLOR_URGENT_BG
  210.                                     UL=$COLOR_FOCUSED_URGENT_BG
  211.                                 fi
  212.                                 ;;
  213.                         esac
  214.                         wm="${wm}%{F${FG}}%{B${BG}}%{U${UL}}%{+u}%{A:bspc desktop -f ${name}:} ${name} %{A}%{B-}%{F-}%{-u}"
  215.                         ;;
  216.                     [LTG]*)
  217.                         # layout, state and flags
  218.                         wm="${wm}%{F$COLOR_STATE_FG}%{B$COLOR_STATE_BG} ${name} %{B-}%{F-}"
  219.                         ;;
  220.                 esac
  221.                 shift
  222.             done
  223.             ;;
  224.     esac
  225.     printf "%s\n" "%{l}${wm}%{c}${mus}%{r}${net}${bat}${sys}"
  226. done
  227. }
  228.  
  229. 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 &
  230.  
  231. wid=$(xdo id -a "$PANEL_WM_NAME")
  232. xdo above -t "$(xdo id -N Bspwm -n root | sort | head -n 1)" "$wid"
  233.  
  234. wait
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement