On Sat, Jan 22, 2011 at 11:28:20AM -0500, Eitan Goldshtrom wrote:
> Hi. I'm trying to print out a progress bar sort of thing that
> represents my remaining battery life. 

Why use python? dc and printf suffice.


Patrick

percent=$1
buckets=10
# annoying math
decimal=$( dc -e "5 k $buckets $percent * 100 / p")
count=$( dc -e "0 k $decimal 1 / p" )
remainder=$( dc -e "5 k $decimal $count - p" )
offset=$( dc -e "0 k $remainder 8 * 1 / p" )
char_hex="0000200A" # unicode space
test $offset != 0 && {
        # see http://www.fileformat.info/info/unicode/char/258f/index.htm
        char_dec=$( dc -e "0 k 9616 $offset - p" )
        char_hex=$( printf "%08x" $char_dec )
}

for y in $( yes | head -n $count)  ; do 
        $( which printf ) "\U00002588"
done
$( which printf ) "\U${char_hex}\n"


Reply via email to