Battery and Volume indicator scripts for xmobar

I wrote a couple of scripts that make text based icons that give info about battery and volume level. The part of the volume script that gets the value for the volume was based off of some script I found somewhere on the internet. These scripts were written for xmobar, but I suppose you can use them for pretty much any text-based status bar.

Script for volume level:

$ cat ~/bin/getvolume
-----------------------------------------------------------
#!/bin/bash

# Get L/R volume info
left=`amixer sget Master | grep Left:`
right=`amixer sget Master | grep Right:`
llevel=${left#*[}
llevel=${llevel%\%]*}
rlevel=${right#*[}
rlevel=${rlevel%\%]*}
active=${left##*[}
active=${active%]}

# Find average level
if [ $llevel == $rlevel ]
then
    level=$llevel
else
    level=$(($llevel + $rlevel))
    level=$(($level / 2))
fi

#Create displays
if [ $active == "off" ] || [ $level == "0" ]
then
    echo "Mute"
elif [ $level == "100" ]
then
    echo "))(("
elif [ $(($level <= 33)) == "1" ]
then
    echo "*)"
elif [ $(($level <= 66)) == "1" ]
then
    echo "*))"
else
    echo "*)))"
fi

Script for battery level:

$ cat ~/bin/battery
-----------------------------------------------------------
#!/bin/bash
# Echo battery level
function batt_indicator () {
if [ $(($1 <= 25)) == "1" ]
then
    echo "[-!-]"
elif [ $(($1 <= 50)) == "1" ]
then
    echo "[$2 ]"
elif [ $(($1 <= 75)) == "1" ]
then
    echo "[$2$2 ]"
else
    echo "[$2$2$2]"
fi
}
# Find level and state
str=`acpi -b`
batt_state=${str#Batt*:\ }
batt_state=${batt_state%%,*}
batt_level=${str#Batt*,\ }
batt_level=${batt_level%\%*}
# Determine output
if [ $batt_state == "Charging" ]
then
    batt_indicator $batt_level '+'
elif [ $batt_state == "Discharging" ]
then
    batt_indicator $batt_level '-'
else
    echo "[===]"
fi

Posted in Linux, xmonad, xmobar, Tiling windows manager, bash, Arch | Tagged , , , | Leave a comment

Hello world!

This blog will probably be boring. I’m basically doing this thing for myself for fun. I don’t really intend for anyone to read this, but you still can if you like.

Posted in Uncategorized | Leave a comment