Advertisement
Guest User

bar.sh

a guest
Jul 20th, 2015
532
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.68 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3.  
  4. color_std="#cccccc"
  5. color_waring="#cc0000"
  6.  
  7.  
  8. get_brg() {
  9.     brg=`cat /sys/class/backlight/intel_backlight/brightness`
  10.     brg_max=`cat /sys/class/backlight/intel_backlight/max_brightness`
  11.     brg_lvl=`echo "scale = 2; $brg / $brg_max * 100"\
  12.             | bc\
  13.             | sed -r 's/\..+//'`
  14.  
  15.     brg="{\"full_text\":\" BRG: $brg_lvl% \",\"color\":\"$color_std\"},"
  16. }
  17.  
  18.  
  19. init_csq() {
  20.     /bin/sudo killall csq.sh
  21.     /bin/sudo $HOME/.i3/csq.sh "/dev/ttyUSB2" &
  22. }
  23.  
  24. get_csq() {
  25.     csq=`cat /tmp/csq.txt`
  26.     csq="{\"full_text\":\" CSQ: $csq% \",\"color\":\"$color_std\"},"
  27. }
  28.  
  29.  
  30. get_capslock() {
  31.     capslock=`xset q\
  32.             | grep "Caps Lock:"\
  33.             | awk '{print($4)}'\
  34.             | tr a-z A-Z`
  35.  
  36.     capslock="{\"full_text\":\" CPS: $capslock \",\"color\":\"$color_std\"},"
  37. }
  38.  
  39.  
  40. get_lng() {
  41.     lng=`skb noloop\
  42.             | head -c 2\
  43.             | tr a-z A-Z`
  44.  
  45.     lng="{\"full_text\":\" $lng \",\"color\":\"$color_std\"},"
  46. }
  47.  
  48.  
  49. get_numlock() {
  50.     numlock=`xset q\
  51.             | grep "Num Lock:"\
  52.             | awk '{print($8)}'\
  53.             | tr a-z A-Z`
  54.  
  55.     numlock="{\"full_text\":\" NUM: $numlock \",\"color\":\"$color_std\"},"
  56. }
  57.  
  58.  
  59. get_cputemp() {
  60.     sensors=`sensors\
  61.             | grep Core\
  62.             | sed 's/\..*//g;s/.*+//g'`
  63.  
  64.     cputemp=0
  65.  
  66.     for core in $sensors; do
  67.         cputemp=$(($cputemp + $core))
  68.     done
  69.  
  70.     # у меня 4 ядра
  71.     cputemp=$(($cputemp / 4))
  72.  
  73.     cputemp_color=$color_std
  74.     if (( "$cputemp" >= "70" )); then
  75.         cputemp_color=$color_waring
  76.     fi
  77.  
  78.     cputemp="{\"full_text\":\" CPU: $cputemp°C \",\"color\":\"$cputemp_color\"},"
  79. }
  80.  
  81.  
  82. get_snd() {
  83.     sndlvl=`amixer get Master\
  84.             | grep 'Mono:'\
  85.             | sed 's/\].*$//;s/^.*\[//'`
  86.  
  87.     snd_state=`amixer get Master\
  88.             | grep 'Mono:'\
  89.             | awk '{print($6);}'\
  90.             | tr a-z A-Z`
  91.  
  92.     snd="{\"full_text\":\" SND$snd_state: $sndlvl \",\"color\":\"$color_std\"},"
  93. }
  94.  
  95.  
  96. get_battlvl() {
  97.     battlvl=`cat /sys/class/power_supply/BAT0/capacity`
  98.  
  99.     batt_color=$color_std
  100.     if (( "$battlvl" <= "10" )); then
  101.         batt_color=$color_waring
  102.     fi
  103.  
  104.     battlvl="{\"full_text\":\" BAT: $battlvl% \",\"color\":\"$batt_color\"},"
  105. }
  106.  
  107.  
  108. get_date() {
  109.     date=`date +%a\ %d.%m.%Y\
  110.             | tr a-z A-Z`
  111.  
  112.     date="{\"full_text\":\" $date \",\"color\":\"$color_std\"},"
  113. }
  114.  
  115.  
  116. get_time() {
  117.     time=`date +%H:%M:%S`
  118.     time="{\"full_text\":\" $time \", \"color\":\"$color_std\"}"
  119. }
  120.  
  121.  
  122. blocks=(
  123.     [10]=lng
  124.     [20]=numlock
  125. #   [30]=capslock
  126. #   [40]=csq
  127.     [50]=cputemp
  128. #   [60]=brg
  129.     [70]=snd
  130.     [80]=battlvl
  131.     [90]=date
  132.     [100]=time
  133. )
  134.  
  135. unset func_list
  136. bar='['
  137. for block in ${blocks[@]}; do
  138.     init_$block 2> /dev/null
  139.     func_list+=" get_$block"
  140.     bar+='${'$block':-}'
  141. done
  142. bar+="],"
  143.  
  144.  
  145. echo '{"version":1}['
  146. while [ 1 ]; do
  147.     for func in $func_list; do
  148.         $func
  149.     done
  150.     eval echo -e \"${bar//\\/\\\\}\" || exit 3
  151.  
  152.     sleep 0.5
  153. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement