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

Re: PS1='%?'



very cool... thanks!

i like that better than messing around with zle.


On Sat, 29 Sep 2007, Matthew Wozniski wrote:

Here's (a very watered down version of) how I do that:

# Set up RPS1 to display $psvar[3], rather than $?
RPS1='%3v'

# When executing a command, set a flag saying that we want $? shown
function preexec {
 shownexterr=1
}

# Before drawing the prompt, set $psvar[3] to be "[$?]" or "",
# depending on whether the flag to show it is set and the return was
# non-zero.  Then, reset the flag, so the next time precmd runs the
# exit status won't be show.
function precmd {
 local exitstatus=$?  # Need a local, since other cmds change $?

 if [[ "$exitstatus" -gt 0 && "$shownexterr" -gt 0 ]]; then
   psvar[3]="[${exitstatus}]"
 else
   psvar[3]=""
 fi
 shownexterr=0;
}



--
        ...atom

 ________________________
 http://atom.smasher.org/
 762A 3B98 A3C3 96C9 C6B7 582A B88D 52E4 D9F5 7808
 -------------------------------------------------

	"I've always thought that underpopulated countries in
	 Africa are vastly under-polluted."
		-- Lawrence Summers,
		chief economist of the World Bank,
		explaining why we should export toxic wastes
		to Third World countries




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