Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PS1='%?'



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?

-- 
Stéphane



Messages sorted by: Reverse Date, Date, Thread, Author