Advertisement
kainonergon

simplepanel.sh

Feb 8th, 2017
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.48 KB | None | 0 0
  1. #! /bin/sh
  2. #
  3. # simplepanel.sh
  4. #
  5.  
  6. SP_WIDTH=
  7. SP_HEIGHT=28
  8. SP_POSITION=
  9.  
  10. SP_FONT="xos4Terminus:size=12"
  11. SP_OFFSET=0
  12.  
  13. SP_BG_COLOR="#FFEFF0F1"
  14. SP_BG_COLOR_1="#FF3DAEE9"
  15. SP_FG_COLOR="#FF101010"
  16. SP_FG_COLOR_1="grey"
  17.  
  18. SP_INIT_DELAY=0.02
  19.  
  20. # lemonbar format codes
  21.  
  22. BC="%{B-}"
  23. BC1="%{B$SP_BG_COLOR_1}"
  24. FC="%{F-}"
  25. FC1="%{F$SP_FG_COLOR_1}"
  26. SEPARATOR=" $FC1$FC "
  27. CENTER="%{c}"
  28. RIGHT="%{r}"
  29.  
  30. # panel structure
  31.  
  32. sp_modules=(
  33.     sp_spacer
  34.     sp_main_menu
  35.     sp_separator
  36.     sp_bspwm_status
  37.     sp_separator
  38.     sp_center
  39.     sp_window_title
  40.     sp_right
  41.     sp_separator
  42.     sp_conky_info
  43.     sp_separator
  44.     sp_clock
  45.     sp_separator
  46.     sp_button_hello
  47.     sp_spacer
  48. )
  49.  
  50. # number of modules
  51.  
  52. sp_mod_count=${#sp_modules[@]}
  53.  
  54. # module definitions
  55.  
  56. sp_spacer()
  57. {
  58.     echo " "
  59. }
  60.  
  61. sp_main_menu()
  62. {
  63.     echo "%{A:morc_menu:} Menu %{A}"
  64. }
  65.  
  66. sp_separator()
  67. {
  68.     echo "$SEPARATOR"
  69. }
  70.  
  71. sp_center()
  72. {
  73.     echo "$CENTER"
  74. }
  75.  
  76. sp_right()
  77. {
  78.     echo "$RIGHT"
  79. }
  80.  
  81. sp_bspwm_status()
  82. {
  83.     IFS=':'
  84.     bspc subscribe \
  85.     | while read line; do
  86.         set -- $line
  87.         while [ $# -gt 0 ] ; do
  88.             case $1 in
  89.                 O*|F*|U*) printf "%s %s %s" $BC1 ${1#?} $BC ;;
  90.                 o*|u*) printf " %s " ${1#?} ;;
  91.                 *) ;;
  92.             esac
  93.             shift
  94.         done
  95.         printf "\n";
  96.     done
  97. }
  98.  
  99. sp_window_title()
  100. {
  101.     xtitle -s -t -40
  102. }
  103.  
  104. sp_conky_info()
  105. {
  106. echo '
  107. conky.config = {
  108. out_to_x = false,
  109. out_to_console = true,
  110. use_spacer = "no",
  111. default_graph_width = 8,
  112. console_graph_ticks = " ,_,▁,▂,▃,▄,▅,▆,▇,█",
  113. out_to_stderr = false,
  114. cpu_avg_samples = 2,
  115. no_buffers = true,
  116. update_interval = 1
  117. };
  118. conky.text =
  119. [[
  120. CPU: \
  121. ${cpu}%\
  122. '$SEPARATOR'\
  123. ${wireless_essid wlp2s0} \
  124. ${wireless_link_qual_perc wlp2s0}%
  125. ]]
  126. ' | conky -q -c -
  127. }
  128.  
  129. sp_clock()
  130. {
  131.     while true; do
  132.         date +%T
  133.         sleep 1;
  134.     done
  135. }
  136.  
  137. sp_button_hello()
  138. {
  139.     echo "%{A:notify-send Hello!:} Click me! %{A}"
  140. }
  141.  
  142.  
  143. # initialize panel
  144.  
  145. sp_panel_init()
  146. {
  147.     for (( i=0; i<$sp_mod_count; i++ )); do
  148.         ${sp_modules[$i]} \
  149.         | while read; do
  150.             printf "%s/%s\n" "$i" "$REPLY"
  151.             sleep $SP_INIT_DELAY;
  152.         done &
  153.         sleep $SP_INIT_DELAY;
  154.     done
  155. }
  156.  
  157. # update panel
  158.  
  159. sp_panel_update()
  160. {
  161.     while read; do
  162.         sp_value[${REPLY%%/*}]=${REPLY#*/}
  163.         for (( i=0; i<$sp_mod_count; i++ )); do
  164.             printf "%s" "${sp_value[$i]}";
  165.         done
  166.         printf "\n"
  167.     done
  168. }
  169.  
  170. # main
  171.  
  172. sp_panel_init \
  173. | sp_panel_update \
  174. | lemonbar \
  175.     -g ${SP_WIDTH}x${SP_HEIGHT}${SP_POSITION} \
  176.     -f $SP_FONT \
  177.     -o $SP_OFFSET \
  178.     -B $SP_BG_COLOR \
  179.     -F $SP_FG_COLOR \
  180. | while read; do eval "$REPLY"; done;
  181.  
  182. wait
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement