Advertisement
kainonergon

simplepanel.sh in dash - fixed

Feb 9th, 2017
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.61 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. sp_main_menu
  47. sp_separator
  48. sp_bspwm_status
  49. sp_center
  50. sp_window_title
  51. sp_right
  52. sp_separator
  53. sp_conky_info
  54. sp_spacer
  55. "
  56.  
  57. # Module definitions - each module shoud print one line at a time.
  58. # Dynamic modules should print a line for every new value.
  59. # The panel updates every time a module prints a line.
  60.  
  61. sp_spacer()
  62. {
  63.     echo " " ;
  64. }
  65.  
  66. sp_main_menu()
  67. {
  68.     echo "$FC2%{A:morc_menu:}☰%{A}$FC" ;
  69. }
  70.  
  71. sp_separator()
  72. {
  73.     echo "$SEPARATOR" ;
  74. }
  75.  
  76. sp_center()
  77. {
  78.     echo "$CENTER" ;
  79. }
  80.  
  81. sp_right()
  82. {
  83.     echo "$RIGHT" ;
  84. }
  85.  
  86. sp_bspwm_status()
  87. {
  88.     IFS=':' ;
  89.     bspc subscribe \
  90.     | while read line ; do
  91.         set -- $line ;
  92.         while [ $# -gt 0 ] ; do
  93.             case $1 in
  94.                 O*|F*|U*)
  95.                     printf "%s %s %s" "$BC1" "${1#?}" "$BC" ;;
  96.                 o*|u*)
  97.                     printf " %s " "${1#?}" ;;
  98.             esac ;
  99.             shift ;
  100.         done ;
  101.         printf "\n" ;
  102.     done ;
  103. }
  104.  
  105. sp_window_title()
  106. {
  107.     xtitle -s -t -40 ;
  108. }
  109.  
  110. sp_clock()
  111. {
  112.     while true ; do
  113.         date +%R ;
  114.         sleep 60 ;
  115.     done ;
  116. }
  117.  
  118. sp_conky_info()
  119. {
  120. echo '
  121. conky.config = {
  122. out_to_x = false,
  123. out_to_console = true,
  124. use_spacer = "left",
  125. default_graph_width = 8,
  126. console_graph_ticks = " ,_,—,‾",
  127. out_to_stderr = false,
  128. cpu_avg_samples = 2,
  129. no_buffers = true,
  130. update_interval = 1
  131. };
  132. conky.text =
  133. [[
  134. CPU:\
  135. ${cpugraph}\
  136. ${cpu}%\
  137. '$SEPARATOR'\
  138. ${wireless_essid wlp2s0}\
  139. ${wireless_link_qual_perc wlp2s0}%\
  140. '$SEPARATOR'\
  141. ${time %T}
  142. ]]
  143. ' | conky -q -c - ;
  144. }
  145.  
  146. ########
  147. # MAIN #
  148. ########
  149.  
  150. # INITIALIZE PANEL
  151. sp_values="" ;
  152. for module in $sp_modules ; do # set initial values
  153.     sp_values="$sp_values\n" ; # one line for each module
  154. done ;
  155. i=0 ;
  156. for module in $sp_modules ; do # start modules
  157.     "$module" \
  158.     | while { IFS=":" ; read line ; } ; do # IFS to keep spaces
  159.         printf "%s/%s/\n" "$i" "$line"; # add module index to the line
  160.     done & # spawn processes for dynamic modules
  161.     i=$(($i+1)) ;
  162. done \
  163. | while read line ; do # UPDATE PANEL
  164.         index="${line%%/*}" ; # get index of module that needs update
  165.         i=0 ;
  166.         sp_values_new="" ;
  167.         while [ -n "$sp_values" ] ; do # read old set of values
  168.             if [ $i -eq $index ] ; then
  169.                 value="$line" ;   # replace appropriate value
  170.                 else
  171.                 value="${sp_values%%\\n*}" ; # keep all other values
  172.             fi
  173.             sp_values="${sp_values#*\\n}" ; # remove old value
  174.             sp_values_new="$sp_values_new$value\n" ; # store new value
  175.             value="${value#*/}" ; # remove index from line
  176.             printf "%s" "${value%?}" ; # print new value without last character
  177.             i=$(($i+1)) ;
  178.         done ;
  179.         printf "\n" ; # end the line in order to update lemonbar
  180.         sp_values="$sp_values_new" ; # replace old set of values with new
  181.         sleep 0.01 ; # a delay needed for smooth updates
  182.     done \
  183. | lemonbar \
  184.     -g ${SP_WIDTH}x${SP_HEIGHT}${SP_POSITION} \
  185.     -f $SP_FONT_1 \
  186.     -o $SP_OFFSET_1 \
  187.     -f $SP_FONT_2 \
  188.     -o $SP_OFFSET_2 \
  189.     -B $SP_BG_COLOR \
  190.     -F $SP_FG_COLOR \
  191. | while read line; do eval "$line"; done; # execute button commands
  192.  
  193. wait
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement