Advertisement
bklaase

panel_bar

Sep 22nd, 2017
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.05 KB | None | 0 0
  1. #! /bin/sh
  2. #
  3. # BSPWM panel for lemonbar
  4.  
  5. source ~/dotfiles/wm_config/wm_config
  6.  
  7. num_mon=$(bspc query -M | wc -l)
  8.  
  9.  
  10. ## start reading lines from stdin
  11. while read -r line ; do
  12.     case $line in
  13.         S*)
  14.             # clock output
  15.             sys="${line#?} "
  16.             ;;
  17.         T*)
  18.             # xtitle output
  19.             title="%{F-} ${line#?} "
  20.             ;;
  21.         W*)
  22.             # bspwm's state. Begin with some state variables
  23.             wm="%{F$PANEL_ICON_COLOR}  "
  24.             curMonActive=true
  25.  
  26.             nodeState="%{F$PANEL_ICON_COLOR}%{F-} -"
  27.             flagState=""
  28.  
  29.             IFS=':'
  30.             set -- ${line#?}
  31.             while [ $# -gt 0 ] ; do
  32.                 item=$1
  33.                 name=${item#?}
  34.                 case $item in
  35.                     [mM]*)
  36.                         [ $num_mon -lt 2 ] && shift && continue
  37.                         case $item in
  38.                             m*)
  39.                                 # monitor
  40.                                 FG=$PANEL_ICON_COLOR
  41.                                 BG="-"
  42.                                 curMonActive=false
  43.                                 ;;
  44.                             M*)
  45.                                 # focused monitor
  46.                                 FG=$PANEL_HIGHLIGHT_COLOR
  47.                                 BG="-"
  48.                                 curMonActive=true
  49.                                 ;;
  50.                         esac
  51.                         wm="${wm}%{F${FG}}%{B${BG}}%{A:bspc monitor -f ${name}:} ${name} %{A}%{B-}%{F-}"
  52.                         ;;
  53.                     [fFoOuU]*)
  54.                         case $item in
  55.                             f*)
  56.                                 # free desktop
  57.                                 FG=$PANEL_DIM_COLOR
  58.                                 BG="-"
  59.                                 label=""
  60.                                 ;;
  61.                             F*)
  62.                                 # focused free desktop
  63.                                 FG=$PANEL_HIGHLIGHT_COLOR
  64.                                 BG="-"
  65.                                 label=""
  66.                                 ;;
  67.                             o*)
  68.                                 # occupied desktop
  69.                                 FG=$PANEL_DIM_COLOR
  70.                                 BG="-"
  71.                                 label=""
  72.                                 ;;
  73.                             O*)
  74.                                 # focused occupied desktop
  75.                                 FG=$PANEL_HIGHLIGHT_COLOR
  76.                                 BG="-"
  77.                                 label=""
  78.                                 ;;
  79.                             u*)
  80.                                 # urgent desktop
  81.                                 FG=$PANEL_ICON_COLOR
  82.                                 BG="-"
  83.                                 label=""
  84.                                 ;;
  85.                             U*)
  86.                                 # focused urgent desktop
  87.                                 FG=$PANEL_HIGHLIGHT_COLOR
  88.                                 BG="-"
  89.                                 label=""
  90.                                 ;;
  91.                         esac
  92.                         wm="${wm}%{F${FG}}%{B${BG}}%{A:bspc desktop -f ${name}:}$label%{A}%{B-}%{F-}"
  93.                         ;;
  94.                     [LTG]*)
  95.                         # layout, state and flags
  96.                         #ignore for inactive monitors
  97.                         if [ "$curMonActive" = false ] ; then
  98.                             shift && continue
  99.                         fi
  100.                         case $item in
  101.                             L*)
  102.                                 # Layout of monitor (Tiling, Max)
  103.                                 monitorState="%{F$PANEL_HIGHLIGHT_COLOR}%{F-} ${name}"
  104.                                 ;;
  105.                             T*)
  106.                                 #State of focused node (Tiled, Pseudo, Fullscreen)
  107.                                 nodeState="%{F$PANEL_ICON_COLOR}%{F-} ${name}"
  108.                                 ;;
  109.                             G*)
  110.                                 #Flags
  111.                                 [[ -z $name ]] || flagState=" %{F$PANEL_HIGHLIGHT_COLOR}%{F-} ${name}"
  112.                                 ;;
  113.                         esac
  114.                         ;;
  115.                 esac
  116.                 shift
  117.             done
  118.             #number of clients
  119.             numnodes="%{F$PANEL_HIGHLIGHT_COLOR} %{F-}$(timeout 1 bspc query --nodes -n '.window.!sticky' --desktop focused | wc -l)"
  120.             #[ $numnodes -gt 0 ] &&
  121.  
  122.             wm="${wm} $monitorState $nodeState$flagState $numnodes"
  123.  
  124.             ## redundantly update title also when wmchanges happen:
  125.             title=$(xtitle)
  126.  
  127.             ;; ##end of WM part
  128.     esac
  129.  
  130.     # print the three parts, starting with the center. If it gets to long, this way lemonbar will draw left and right over it.
  131.     printf "%s\n" "%{c}${title}%{l}${wm}   %{r}   ${sys}"
  132. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement