You are not logged in.
I have a computer battery life script that I'm using in my zsh prompt, but the problem is that it does not update when the battery life changes, only if I
run `source .zshrc` or spawn a new shell. I googled extensively for a solution, and the best I came up with was
this thread in the forums, post #95, where Xiong writes:
if you use %D{} to get your date, then it won't be stuck. Using $(date) gets the value, then substitutes it into the string that you set.
Unfortunately, there are no builtins for battery life so I need to use my script. Here is how I'm calling it (my rprompt has been truncated for the purpose
of this example):
local BATTPRCNT="$(batt.sh)"
RPROMPT="${dgray}Battery:%f ${PR_BATTERY}%f"The script:
acpi | awk 'NR==1 {print $4}' | sed 's/,//g' | sed 's/%//g'What can I do to make zsh auto-run the script, say, at least every minute, so that my prompt updates? I appreciate the help anyone can offer.
Last edited by Sara (2011-10-07 20:35:05)
Registed Linux User 483618
Offline
You can use one of the hook functions to set your prompt, see the zshmisc manpage:
periodic
If the parameter PERIOD is set, this function is executed every
$PERIOD seconds, just before a prompt. Note that if multiple
functions are defined using the array periodic_functions only
one period is applied to the complete set of functions, and the
scheduled time is not reset if the list of functions is altered.
Hence the set of functions is always called together.
precmd Executed before each prompt. Note that precommand functions are
not re-executed simply because the command line is redrawn, as
happens, for example, when a notification about an exiting job
is displayed.Offline
You can use one of the hook functions to set your prompt, see the zshmisc manpage
Thank you so much! I chose to use the precmd function, and copied the code for BATTPRCNT and RPROMPT into the precmd() function, so that it now remains
updated
.
Last edited by Sara (2011-10-07 20:40:44)
Registed Linux User 483618
Offline