Advertisement
Guest User

statusbar_input

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