Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: PS1='%?'
- X-seq: zsh-users 11899
- From: Atom Smasher <atom@xxxxxxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: PS1='%?'
- Date: Sun, 30 Sep 2007 03:14:27 +1200 (NZST)
- In-reply-to: <20070929120210.GB7515@xxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- Openpgp: id=0xB88D52E4D9F57808; algo=1 (RSA); size=4096; url=http://atom.smasher.org/pgp.txt
- References: <20070929112153.76128.qmail@xxxxxxxxxxx> <20070929120210.GB7515@xxxxxxxxxxxxxxx>
On Sat, 29 Sep 2007, Stephane Chazelas wrote:
On Sat, Sep 29, 2007 at 11:21:48PM +1200, Atom Smasher wrote:
if i have a '%?' in my command line, is there a way to "reset" it to
zero if i hit enter, but don't run a command?
[...]
If the shell were to behave like that, that would mean that in
cmd
if [ "$?" -ge 2 ]; ...
The test above would be useless because of the empty line above that
would have reset $? to 0.
What you could do is redefine the accept-line widget (called upon
<Return> key press) so that it runs the null command (":") if the edit
buffer is empty:
~$ accept-line() {
function> [[ -n $BUFFER ]] || BUFFER=:
function> zle .accept-line
function> }
~$ zle -N accept-line
~$ false
(1)~$ :
~$ :
But why do you want to reset $? in such a way?
====================
if a command returns non-zero, i see the return status in my prompt.
sometimes that can be a distraction, and i'd like to "clear" it by hitting
<return>.
i guess i can add a check for "${options[interactive]}" before resetting
the return status so i should be able to avoid the case you've pointed
out... but in the test i ran here it seems to not get have a problem with
that in a script.
######################
## clear the return status by pressing <return>
accept-line () {
if [ '0' != "${?}" ] && [ ! "${BUFFER}" ]
then
BUFFER=:
fi
zle .accept-line
}
zle -N accept-line
######################
this works, but aesthetically i'd prefer if it didn't put a ":" on the
command line... any ideas...?
--
...atom
________________________
http://atom.smasher.org/
762A 3B98 A3C3 96C9 C6B7 582A B88D 52E4 D9F5 7808
-------------------------------------------------
"I am somehow less interested in the weight and
convolutions of Einstein's brain than in the near
certainty that people of equal talent have lived and
died in cotton fields and sweatshops."
-- Stephen Jay Gould
Messages sorted by:
Reverse Date,
Date,
Thread,
Author