Advertisement
Guest User

Untitled

a guest
Aug 14th, 2012
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. # Functions needed for dwm statusbar
  3.  
  4. wlan_bar(){
  5.     # Measure signal strength in percent
  6.     sig_strength=$(cat /sys/class/net/wlan0/wireless/link)
  7.     # Calculate signal strength from 1-5
  8.     bar_value=$(( $sig_strength / 20 ))
  9.    
  10.     case $bar_value in
  11.         0)
  12.             echo -e "\x04[|\x01||||\x04]" ;;
  13.         1)
  14.             echo -e "\x04[||\x01|||\x04]" ;;
  15.         2)
  16.             echo -e "\x04[|||\x01||\x04]" ;;
  17.         3)
  18.             echo -e "\x04[||||\x01|\x04]" ;;
  19.         4)
  20.             echo -e "\x04[|||||]" ;;
  21.         5)
  22.             echo -e "\x04[|||||]" ;;
  23.     esac
  24. }
  25. battery_status(){
  26.     #raw_status=$(acpi -b | awk 'sub(/,/,"") {print $3, $4}')
  27.     # Check if battery is charging or discharging
  28.     charge_stat(){
  29.         if [ -e /sys/class/power_supply/BAT0/status ]
  30.         then
  31.             case $(cat /sys/class/power_supply/BAT0/status) in
  32.                 Charging)
  33.                     charge_status="+"
  34.                     ;;
  35.                 Discharging)
  36.                     charge_status="-"
  37.                     ;;
  38.             esac
  39.         fi
  40.     }
  41.     raw_status=$(acpi -b | cut -d, -f2 | egrep -o '[0-9][0-9]*[0-9]')  
  42.     if [ "x${raw_status}" = "x" ]
  43.     then
  44.         # No battery, must be AC
  45.         echo "\x04AC"
  46.     else
  47.         charge_stat
  48.         # Calculate status
  49.         calc_status=$(( $raw_status / 20 ))
  50.         # Make status
  51.         case $calc_status in
  52.             0)
  53.                 # under 19%: RED
  54.                 echo -e "\x06${raw_status}$charge_status" ;;
  55.             1)
  56.                 # under 39%: YELLOW
  57.                 echo -e "\x06${raw_status}$charge_status" ;;
  58.             2)
  59.                 # under 59%: NORMAL
  60.                 echo -e "\x04${raw_status}$charge_status" ;;
  61.             3)
  62.                 # under 79%: NORMAL
  63.                 echo -e "\x04${raw_status}$charge_status" ;;
  64.             4)
  65.                 # under 99%: NORMAL
  66.                 echo -e "\x04${raw_status}$charge_status" ;;
  67.             5)
  68.                 # 100%: NORMAL
  69.                 echo -e "\x04${raw_status}$charge_status" ;;
  70.         esac
  71.     fi
  72. }
  73.  
  74. # make sure directory exists
  75. mkdir -p /tmp/.dwm
  76.  
  77. # Make sure files exist
  78. touch /tmp/.dwm/{battery,ssid,wlan,volume}
  79.  
  80. # print all the things
  81. while true
  82. do
  83.     # Print battery percentage
  84.     battery_status > /tmp/.dwm/battery
  85.     # Print SSID to file
  86.     echo "$(iwconfig wlan0 | sed -e '/"/ s/"//g' -e 's/ //g' -ne '/ESSID/ p' | cut -d: -f2)" > /tmp/.dwm/ssid
  87.     # Print wlan-bar
  88.     wlan_bar > /tmp/.dwm/wlan
  89.     sleep 1m
  90. done &
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement