Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Functions
- wlan_bar(){
- # Measure signal strength in percent
- sig_strength=$(cat /sys/class/net/wlan0/wireless/link)
- # Calculate signal strength from 1-5
- bar_value=$(( $sig_strength / 20 ))
- case $bar_value in
- 0)
- echo -e "\x04[|\x01||||\x04]" ;;
- 1)
- echo -e "\x04[||\x01|||\x04]" ;;
- 2)
- echo -e "\x04[|||\x01||\x04]" ;;
- 3)
- echo -e "\x04[||||\x01|\x04]" ;;
- 4)
- echo -e "\x04[|||||]" ;;
- 5)
- echo -e "\x04[|||||]" ;;
- esac
- }
- battery_status(){
- #raw_status=$(acpi -b | awk 'sub(/,/,"") {print $3, $4}')
- # Check if battery is charging or discharging
- charge(){
- if [ -e /sys/class/power_supply/BAT0/status ]
- then
- case $(cat /sys/class/power_supply/BAT0/status) in
- Charging)
- charge_status="+"
- ;;
- Discharging)
- charge_status="-"
- ;;
- esac
- fi
- }
- raw_status=$(acpi -b | cut -d, -f2 | egrep -o '[0-9][0-9]*[0-9]')
- if [ "x${raw_status}" = "x" ]
- then
- # No battery, must be AC
- echo "\x04AC"
- else
- charge
- # Calculate status
- calc_status=$(( $raw_status / 20 ))
- # Make status
- case $calc_status in
- 0)
- # under 19%: RED
- echo -e "\x06${raw_status}$charge_status" ;;
- 1)
- # under 39%: YELLOW
- echo -e "\x06${raw_status}$charge_status" ;;
- 2)
- # under 59%: NORMAL
- echo -e "\x04${raw_status}$charge_status" ;;
- 3)
- # under 79%: NORMAL
- echo -e "\x04${raw_status}$charge_status" ;;
- 4)
- # under 99%: NORMAL
- echo -e "\x04${raw_status}$charge_status" ;;
- 5)
- # 100%: NORMAL
- echo -e "\x04${raw_status}$charge_status" ;;
- esac
- fi
- }
- # make sure directory exists
- mkdir -p /tmp/.dwm
- # Make sure files exist
- touch /tmp/.dwm/{battery,ssid,wlan,volume}
- # Write battery-status to file every minute
- while true
- do
- battery_status > /tmp/.dwm/battery
- sleep 1m
- done &
- # Write wlan_bar to file every 10s
- while true
- do
- # Print SSID to file
- echo "$(iwconfig wlan0 | sed -e '/"/ s/"//g' -e 's/ //g' -ne '/ESSID/ p' | cut -d: -f2)" > /tmp/.dwm/ssid
- wlan_bar > /tmp/.dwm/wlan
- sleep 10s
- done &
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement