A Legend of Zelda like health-bar battery meter for Shell prompts.
Before you even comment on the code or practices used by this project, keep one very important thing in mind: I wrote this for me; not you.
If you see something weird like goto
statements instead of for-loops remember where this application is being used. It is for use in shell prompts, where it needs to be lightning fast: I don't want my Shell prompt to take any longer to load than it does for me to wonder if it's taking too long to load, and because it was, admittedly, fun to find ways of making ZBatt unnecesssarily faster.
Because I wanted to be able to keep a constant tab on my laptop's power-level without having to look away from the command-line or running a command, thought it would be neat thing to do, and because I could.
Kernels >= 2.6.24 are supported; support for older kernels is on the way.
Most BSDs should be supported: as long as you have sysctlbyname
, you should be fine. BSD systems known to work:
- DragonFly BSD
- FreeBSD
I don't own a Mac. However, if I gain access to one, unless I can port ZBatt without using bullcrap like Swift, then I'm not going to port it.
If you're using Solaris, I'm sorry; it's not gonna happen, ever. I have better things to do.
- GNU Autotools
- C99 compliant C compiler
autoreconf -i
./configure
make
Just place zbatc
(zbatt-color) and zbatt
(zbatt-text) where ever you want them and add the appropriate stuff to your terminal prompt.
./zbatc -c 32; ./zbatt -p -f +; ./zbatc -c 31; ./zbatt -m -e -
PROMPT="%{$(./zbatc)%}$(./zbatt)%{�[0;0m%} %m%# "
## run TRAPALRM every $TMOUT seconds
TMOUT=60 # refresh the terminal prompt every 60 seconds
TRAPALRM () {
zle reset-prompt # refreshs the terminal prompt
}
PS1='\[$(./zbatc)\]$(./zbatt)\[\033[0;0m\] [\h \W]\$ '
PS1=$'$(./zbatc)'$(./zbatt)$'\033[0;0m'\ ["$(hostname)"]\
set prompt="%{`./zbatc`%}`./zbatt` %{\033[0;0m%}%m "
As long as you use the TMOUT
and TRAPALRM
/zle reset-prompt
stuff, your Zsh prompt should refresh itself every 60 seconds.
AFAIK there is no way to periodically refresh a bash prompt without either running clear
/Ctrl-L
or pressing enter, which causes the prompt to be redrawn.