summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugues Hiegel <hugues@hiegel.fr>2009-01-27 14:34:44 +0100
committerHugues Hiegel <hugues@hiegel.fr>2009-01-27 14:34:44 +0100
commita0e603bb21c919192cabdfa85dd919c230336c80 (patch)
treed02c1bfe42d036391ab55f7e47c0e5154c4ac72a
parentcb09265b096ad0fecd1e94232cd60a141a76f44b (diff)
[PROMPT] battery support
-rw-r--r--11_Colors.zsh7
-rw-r--r--12_Prompts.zsh46
2 files changed, 50 insertions, 3 deletions
diff --git a/11_Colors.zsh b/11_Colors.zsh
index 9e69c34..d072e55 100644
--- a/11_Colors.zsh
+++ b/11_Colors.zsh
@@ -7,7 +7,7 @@
## You are encouraged to use, modify, and redistribute
## these files with or without this notice.
##
-typeset -A prompt_colors git_colors mail_colors correct_colors
+typeset -A prompt_colors git_colors mail_colors correct_colors battery_colors
# I hate kik00l0l colorized prompts, so I'm using a way to
# give a dominant color for each part of the prompt, each of
@@ -66,6 +66,11 @@ set_prompt_colors ()
prompt_colors[cmd]="$color[none]" # command prompt
prompt_colors[exec]="$color[none]" # command output
+ battery_colors[charging]="$color[cyan];$color[bold]"
+ battery_colors[full]="$color[none]"
+ battery_colors[uncharging]="$color[normal];$color[bold]"
+ battery_colors[critical]="$color[red];$color[bold]"
+
mail_colors[unread]="$color[yellow];$color[bold]" # mail received
mail_colors[listes]="$my_generic;$color[bold]" # less important mail received
diff --git a/12_Prompts.zsh b/12_Prompts.zsh
index ae9da85..4a02cb1 100644
--- a/12_Prompts.zsh
+++ b/12_Prompts.zsh
@@ -98,9 +98,51 @@ update_prompt()
MAILSTATSIZE=${#MAILSTATEXPAND}
[ "$DEBUG" = "yes" ] && echo
+
+ if [ -e /proc/pmu/battery_0 ]
+ then
+ [ "$DEBUG" = "yes" ] && echo -n " Battery..."
+ ## Time
+ BATTERY_TIME=$(grep "^time rem" /proc/pmu/battery_0 | cut -c14- )
+ BATTERY=$(( $BATTERY_TIME / 3600 ))
+ BATTERY=$BATTERY"h"$(( ($BATTERY_TIME - ( $BATTERY * 3600 )) / 60 ))"m"
+ BATTERYTMP="-"$BATTERY
+ BATTERYSIZE=${#BATTERYTMP}
+
+ BATTERYCHARGING=$(grep "^current" /proc/pmu/battery_0 | cut -c14- )
+ if [ $BATTERYCHARGING -gt 0 ]
+ then
+ BATTERY="$C_$battery_colors[charging]$_C"$BATTERY
+ BATTERY="$C_$prompt_colors[bar]$_C"-"$BATTERY"
+ else
+ if [ $BATTERYCHARGING -lt 0 ]
+ then
+ if [ $BATTERY_TIME -lt 600 ]
+ then
+ BATTERY="$C_$battery_colors[critical]$_C"$BATTERY
+ else
+ BATTERY="$C_$battery_colors[uncharging]$_C"$BATTERY
+ fi
+ BATTERY="$C_$prompt_colors[bar]$_C"-"$BATTERY"
+ else
+ ## Battery full
+ BATTERY=""
+ BATTERYSIZE=0
+ fi
+ fi
+ ## Percentage
+ #BATTERY=$(( $(grep "^charge" /proc/pmu/battery_0 | cut -c14- ) * 100 / $(grep "^max_charge" /proc/pmu/battery_0 |cut -c14-) ))
+ #BATTERY="-$BATTERY%"
+ #BATTERYSIZE=${#BATTERY}
+ #BATTERY="$C_$prompt_colors[bar]$_C""$BATTERY%"
+ [ "$DEBUG" = "yes" ] && echo
+ else
+ BATTERY=
+ fi
+
[ "$DEBUG" = "yes" ] && echo -n " Horizontal bar..."
# First line of prompt, calculation of the remaining place
- spaceleft=$(($COLUMNS - $ERRORSIZE - $MAILSTATSIZE - $DATESIZE))
+ spaceleft=$(($COLUMNS - $ERRORSIZE - $MAILSTATSIZE - $DATESIZE - $BATTERYSIZE))
unset HBAR
for h in {1..$spaceleft}
@@ -183,7 +225,7 @@ redisplay_prompt ()
# Affiche l'user, l'host, le tty et le pwd. Rien que ça...
# Note que pour le pwd, on n'affiche que les 4 derniers dossiers pour éviter
# de pourrir le fenêtre de terminal avec un prompt à rallonge.
- PS1="$MAILSTAT""$ERROR"$C_$prompt_colors[bar]$_C"$HBAR""$DATE
+ PS1="$MAILSTAT""$ERROR""$BATTERY"$C_$prompt_colors[bar]$_C"$HBAR""$DATE
"$C_$prompt_colors[user]$_C"%n"$C_$prompt_colors[arob]$_C"@"$C_$prompt_colors[host]$_C"%m $CURDIR$SVNREV$GITBRANCH "$C_$prompt_colors[dies]$_C"%#"$C_$prompt_colors[cmd]$_C" "
}