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

Re: zle clear-screen, exit status



On Oct 19, 11:32am, Brian Lewis wrote:
}
} My prompt displays $?, the program exit status. When I hit Ctrl-L, I'd
} like $? to be set to 0 somehow before the prompt is redisplayed.
} 
} I can't figure out how to do it. It is as if $? is saved before my
} widget is called, and restored after.

Yes, that's intentional.  Under normal circumstances the editor should
behave entirely independently of the input command stream.

On Oct 19, 11:53am, Brian Lewis wrote:
}
} On Tuesday, 19.10.10 at 17:47, Jérémie Roquet wrote:
} > bindkey -s "^L" "clear\n"
} > is enough :)
} 
} That's not quite as good as zle clear-screen:
} 
} $ asdf^Lclear
} zsh: command not found: asdfclear

This should almost do it:

function clear2 { zle -U $'clear\n'; zle push-line-or-edit }
zle -N clear2
bindkey '^L' clear2

Where that fails is for a multi-line buffer (i.e., you're at the PS2
prompt or deeper).  In that case push-line-or-edit simply moves up to
the PS1 prompt and the "zle -U" input is discarded, so you'll have to
press ^L a second time.

Optional tweak to avoid having "clear" in the shell history:

setopt hist_ignore_space
function clear2 { zle -U $' clear\n'; zle push-line-or-edit }

-- 



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