zsh-users
 help / color / mirror / code / Atom feed
* $? being clobbered?
@ 2003-07-14 17:35 Phil!Gregory
  2003-07-14 17:57 ` Michał Politowski
  2003-07-14 19:25 ` Bart Schaefer
  0 siblings, 2 replies; 4+ messages in thread
From: Phil!Gregory @ 2003-07-14 17:35 UTC (permalink / raw)
  To: zsh-users

I'm having a problem with zsh, and am not sure if it's a bug or a
feature.  If I have a program executed in my prompt, its return status
clobbers the value of $?, which isn't really what I want.  Example:

> PROMPT='> '
> perl -e 'exit 42'
> echo $?
42
> PROMPT='%{$(echoti cub 80)%}> '
> perl -e 'exit 42'
> echo $?
0

Is there some way to fix this?

(zsh 4.0.7, Sven.)

-- 
...computer contrarian of the first order... / http://aperiodic.net/phil/
PGP: 026A27F2  print: D200 5BDB FC4B B24A 9248  9F7A 4322 2D22 026A 27F2
--- --
This is a one line proof... if we start sufficiently far to the left.
                       -- Cambridge University math professor
---- --- --


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: $? being clobbered?
  2003-07-14 17:35 $? being clobbered? Phil!Gregory
@ 2003-07-14 17:57 ` Michał Politowski
  2003-07-14 19:25 ` Bart Schaefer
  1 sibling, 0 replies; 4+ messages in thread
From: Michał Politowski @ 2003-07-14 17:57 UTC (permalink / raw)
  To: zsh-users

On Mon, 14 Jul 2003 13:35:56 -0400, Phil!Gregory wrote:
> I'm having a problem with zsh, and am not sure if it's a bug or a
> feature.  If I have a program executed in my prompt, its return status
> clobbers the value of $?, which isn't really what I want.  Example:
> 
> > PROMPT='> '
> > perl -e 'exit 42'
> > echo $?
> 42
> > PROMPT='%{$(echoti cub 80)%}> '
> > perl -e 'exit 42'
> > echo $?
> 0
> 
> Is there some way to fix this?

You can hack around this with
$(R=$?;echoti cub 80;return $R)

-- 
Michał Politowski -- mpol@charybda.icm.edu.pl
Warning: this is a memetically modified message


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: $? being clobbered?
  2003-07-14 17:35 $? being clobbered? Phil!Gregory
  2003-07-14 17:57 ` Michał Politowski
@ 2003-07-14 19:25 ` Bart Schaefer
  2003-07-14 19:51   ` Phil!Gregory
  1 sibling, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2003-07-14 19:25 UTC (permalink / raw)
  To: zsh-users

On Jul 14,  1:35pm, Phil!Gregory wrote:
} Subject: $? being clobbered?
}
} I'm having a problem with zsh, and am not sure if it's a bug or a
} feature.  If I have a program executed in my prompt, its return status
} clobbers the value of $?, which isn't really what I want.

There's code in the precmd handler to preserve and restore $? but nothing
similar is done during prompt expansion.

Is there some reason to execute the command every time the prompt is
printed?  That is, does the command change from one prompt to the next?
If not, I suggest:

    unsetopt promptsubst
    PROMPT="%{$(echoti cub 80)%}> "	# Note double quotes

Otherwise I suggest using precmd:

    unsetopt promptsubst
    PROMPT='> '
    function precmd {
      echoti cub 80
    }

I feel compelled to remark that moving 80 columns left seems an odd way of
achieving 'setopt promptcr'.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: $? being clobbered?
  2003-07-14 19:25 ` Bart Schaefer
@ 2003-07-14 19:51   ` Phil!Gregory
  0 siblings, 0 replies; 4+ messages in thread
From: Phil!Gregory @ 2003-07-14 19:51 UTC (permalink / raw)
  To: zsh-users

* Bart Schaefer <schaefer@brasslantern.com> [2003-07-14 19:25 +0000]:
> There's code in the precmd handler to preserve and restore $? but nothing
> similar is done during prompt expansion.

I think my best approach is to move all program execution to precmd.

> Is there some reason to execute the command every time the prompt is
> printed?  That is, does the command change from one prompt to the next?

Yes, because it's actually $(echoti cub $COLUMNS) and I wish it to
work even when the terminal is resized.

> I feel compelled to remark that moving 80 columns left seems an odd way of
> achieving 'setopt promptcr'.

...which is even on by default.  The existing stuff is left over from my
old bash prompt; didn't realize zsh did it for me.  (Actually, the full
code did a clear-to-end-of-display, too, which zsh also appears to do by
default.)

I still have an invocation of apm while I'll have to move.

-- 
...computer contrarian of the first order... / http://aperiodic.net/phil/
PGP: 026A27F2  print: D200 5BDB FC4B B24A 9248  9F7A 4322 2D22 026A 27F2
--- --
Too many people are thinking of security instead of opportunity.  They
seem more afraid of life than death.
                       -- James F. Byrnes
---- --- --


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2003-07-14 19:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-14 17:35 $? being clobbered? Phil!Gregory
2003-07-14 17:57 ` Michał Politowski
2003-07-14 19:25 ` Bart Schaefer
2003-07-14 19:51   ` Phil!Gregory

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).