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

Re: PS1='%?'



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