Advertisement
kainonergon

simplepanel.sh on dash

Feb 9th, 2017
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.49 KB | None | 0 0
  1. #! /bin/dash
  2. #
  3. # simplepanel.sh
  4. #
  5. # Simple panel script for bspwm with lemonbar
  6. # inspired by limepanel.
  7. #
  8.  
  9. # Set size and position
  10.  
  11. SP_WIDTH=
  12. SP_HEIGHT=28
  13. SP_POSITION=
  14.  
  15. # Set fonts
  16.  
  17. SP_FONT_1="xos4Terminus:pixelsize=18"
  18. SP_OFFSET_1=-6
  19.  
  20. SP_FONT_2="Symbola:pixelsize=30"
  21. SP_OFFSET_2=2
  22.  
  23. # Set colors
  24.  
  25. SP_BG_COLOR="#FFEFF0F1"
  26. SP_BG_COLOR_1="#FF3DAEE9"
  27. SP_FG_COLOR="#FF101010"
  28. SP_FG_COLOR_1="grey"
  29. SP_FG_COLOR_2="#FF5C616C"
  30.  
  31. # Set lemonbar format codes
  32.  
  33. BC="%{B-}"
  34. BC1="%{B$SP_BG_COLOR_1}"
  35. FC="%{F-}"
  36. FC1="%{F$SP_FG_COLOR_1}"
  37. FC2="%{F$SP_FG_COLOR_2}"
  38. SEPARATOR="$FC1$FC"
  39. CENTER="%{c}"
  40. RIGHT="%{r}"
  41.  
  42. # Set panel structure - provide a string with a list of modules.
  43. # Add your own modules as you wish.
  44.  
  45. sp_modules="
  46.  
  47. sp_spacer
  48. sp_main_menu
  49. sp_separator
  50. sp_bspwm_status
  51. sp_center
  52. sp_window_title
  53. sp_right
  54. sp_separator
  55. sp_conky_info
  56. sp_spacer
  57. "
  58.  
  59. # Module definitions - each module shoud print one line at a time.
  60. # Dynamic modules should print a line for every new value.
  61. # The panel updates every time a module prints a line.
  62.  
  63. sp_spacer()
  64. {
  65.     echo " " ;
  66. }
  67.  
  68. sp_main_menu()
  69. {
  70.     echo "$FC2%{A:morc_menu:}☰%{A}$FC" ;
  71. }
  72.  
  73. sp_separator()
  74. {
  75.     echo "$SEPARATOR" ;
  76. }
  77.  
  78. sp_center()
  79. {
  80.     echo "$CENTER" ;
  81. }
  82.  
  83. sp_right()
  84. {
  85.     echo "$RIGHT" ;
  86. }
  87.  
  88. sp_bspwm_status()
  89. {
  90.     IFS=':' ;
  91.     bspc subscribe \
  92.     | while read line ; do
  93.         set -- $line ;
  94.         while [ $# -gt 0 ] ; do
  95.             case $1 in
  96.                 O*|F*|U*)
  97.                     printf "%s %s %s" "$BC1" "${1#?}" "$BC" ;;
  98.                 o*|u*)
  99.                     printf " %s " "${1#?}" ;;
  100.             esac ;
  101.             shift ;
  102.         done ;
  103.         printf "\n" ;
  104.     done ;
  105. }
  106.  
  107. sp_window_title()
  108. {
  109.     xtitle -s -t -40 ;
  110. }
  111.  
  112. sp_clock()
  113. {
  114.     while true ; do
  115.         date +%R ;
  116.         sleep 60 ;
  117.     done ;
  118. }
  119.  
  120. sp_conky_info()
  121. {
  122. echo '
  123. conky.config = {
  124. out_to_x = false,
  125. out_to_console = true,
  126. use_spacer = "left",
  127. default_graph_width = 8,
  128. console_graph_ticks = " ,_,—,‾",
  129. out_to_stderr = false,
  130. cpu_avg_samples = 2,
  131. no_buffers = true,
  132. update_interval = 1
  133. };
  134. conky.text =
  135. [[
  136. CPU:\
  137. ${cpugraph}\
  138. ${cpu}%\
  139. '$SEPARATOR'\
  140. ${wireless_essid wlp2s0}\
  141. ${wireless_link_qual_perc wlp2s0}%\
  142. '$SEPARATOR'\
  143. ${time %T}
  144. ]]
  145. ' | conky -q -c - ;
  146. }
  147.  
  148. ########
  149. # MAIN #
  150. ########
  151.  
  152. # INITIALIZE PANEL
  153. sp_values="" ;
  154. for module in $sp_modules ; do # set initial values
  155.     sp_values="$sp_values\n" ;
  156. done ;
  157. i=0 ;
  158. for module in $sp_modules ; do # start modules
  159.     $module \
  160.     | while read line ; do
  161.         printf "%s/%s\n" "$i" "$line"; # add module index to the line
  162.     done & # spawn proccess for dynamic modules
  163.     i=$(($i+1)) ;
  164. done \
  165. | while read line ; do # UPDATE PANEL
  166.         index="${line%%/*}" ; # get index of module that needs update
  167.         new_value="${line#*/}" ; # get new value for that module
  168.         i=0 ;
  169.         sp_values_new="" ;
  170.         while [ -n "$sp_values" ] ; do # read old set of values
  171.             if [ $i -eq $index ] ; then
  172.                 value="$new_value" ;   # replace appropriate value
  173.                 else
  174.                 value="${sp_values%%\\n*}" ; # keep all other values
  175.             fi
  176.             sp_values="${sp_values#*\\n}" ; # remove old value
  177.             printf "%s" "$value" ;
  178.             sp_values_new="$sp_values_new$value\n" ; # write new set of values
  179.             i=$(($i+1)) ;
  180.         done ;
  181.         printf "\n" ;
  182.         sp_values="$sp_values_new" ; # replace old values with new ones
  183.         sleep 0.01 ; # a delay needed for smooth updates
  184.     done \
  185. | lemonbar \
  186.     -g ${SP_WIDTH}x${SP_HEIGHT}${SP_POSITION} \
  187.     -f $SP_FONT_1 \
  188.     -o $SP_OFFSET_1 \
  189.     -f $SP_FONT_2 \
  190.     -o $SP_OFFSET_2 \
  191.     -B $SP_BG_COLOR \
  192.     -F $SP_FG_COLOR \
  193. | while read line; do eval "$line"; done; # execute button commands
  194.  
  195. wait
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement