From f2d32d2a164d9fe8b850aa26405a251757a518dd Mon Sep 17 00:00:00 2001 From: 10sr <8slashes+git@gmail.com> Date: Sun, 11 Mar 2012 00:59:51 +0900 Subject: [PATCH] modify battery function --- bashrc | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/bashrc b/bashrc index f8e86e0..3105387 100755 --- a/bashrc +++ b/bashrc @@ -311,7 +311,8 @@ __my_prompt_function(){ # used by PS1 local date=$(LANG=C __try_exec date +"%a, %d %b %Y %T %z") fi local svn=$(type svn >/dev/null 2>&1 && __try_exec __my_svn_ps1 [SVN:%s]) - printf " [${c1}${pwd}${cdef}<${c3}${oldpwd}${cdef}]${git}${svn}\n" + # local battery=$(battery-status "[%s]" | sed -e 's"%"%%"g') # very slow + printf " [${c1}${pwd}${cdef}<${c3}${oldpwd}${cdef}]${git}${svn}${battery}\n" printf "${c2}${USER}@${HOSTNAME}${cdef} ${date} ${BASH} ${BASH_VERSION}\n" printf "shlv:${SHLVL} jobs:${jobnum} last:${lastreturn} " } @@ -378,12 +379,21 @@ winln(){ battery-status(){ local dir=/sys/class/power_supply/BAT0 - st=$(cat $dir/status) - full=$(cat $dir/charge_full) - now=$(cat $dir/charge_now) - # . $dir/uevent - # rate=$(expr $POWER_SUPPLY_CHARGE_NOW \* 100 / $POWER_SUPPLY_CHARGE_FULL) - rate=$(expr $now \* 100 / $full) - echo ${st}:${rate}\% + if test -d $dir + then + local st=$(cat $dir/status) + local full=$(cat $dir/charge_full) + local now=$(cat $dir/charge_now) + local rate=$(expr $now \* 100 / $full) + printf $1 "${st}:${rate}%" + fi +} +alias bat='battery-status %s\\n' + +battery-status2(){ + local dir=/sys/class/power_supply/BAT0 + . $dir/uevent + local rate=$(expr $POWER_SUPPLY_CHARGE_NOW \* 100 / $POWER_SUPPLY_CHARGE_FULL) + echo ${POWER_SUPPLY_STATUS}:${rate}% }