Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Execute a Command in PS1 w/o Disturbing Previous Return Value?
- X-seq: zsh-users 7821
- From: Philippe Troin <phil@xxxxxxxx>
- To: Aaron Davies <agdavi01@xxxxxxxxxxxxxx>
- Subject: Re: Execute a Command in PS1 w/o Disturbing Previous Return Value?
- Date: 12 Aug 2004 21:52:06 -0700
- Cc: zsh-users@xxxxxxxxxx
- In-reply-to: <D0F204E0-ECD9-11D8-83BE-000502631FBD@xxxxxxxxxxxxxx>
- Mail-copies-to: nobody
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <D0F204E0-ECD9-11D8-83BE-000502631FBD@xxxxxxxxxxxxxx>
- Sender: Philippe Troin <phil@xxxxxxxx>
Aaron Davies <agdavi01@xxxxxxxxxxxxxx> writes:
> I'm trying to write a prompt that will do two things: include a file
> frequently re-downloaded from the web, and indicate the return status
> of the previous command. The problem is, if I cat out the file, it
> returns 0, overwriting the return status read by the %(0?%) directive,
> and guaranteeing that I will always get a prompt indicating
> success. What can I do about this?
>
> Here's the whole line. The breakdown is: current temperature, pwd, (if
> last command successful, a green smiley, else a red frowny), prompt
> char.
>
> export PS1='`cat /tmp/temperature`'" %m%~ %(0?."`echo
> '%{\e[1;32m%}:)%{\e[0m%}'`"."`echo \
> '%{\e[1;31m%}:(%{\e[0m%}'`") %# "
>
> (/tmp/temperature is refreshed every five minutes by a cron job, in
> case you were wondering.)
What about:
precmd() {
local r=$?
psvar=()
psvar=("$(< /tmp/temperature)")
(( $r )) && psvar=($psvar $r)
}
export PS1="$(print '%1v %m%~ %(2v,%{\e[1;31m%}:( [%2v]%{\e[0m%},%{\e[1;32m%}:%)%{\e[0m%}) %# ')"
I prefer "setopt printexitvalue" myself...
Phil.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author