zsh-users
 help / color / mirror / code / Atom feed
* reinventing print_exit_value
@ 2005-07-03 21:56 Christian Taylor
  2005-07-03 22:32 ` Nikolai Weibull
  2005-07-04 14:32 ` Bart Schaefer
  0 siblings, 2 replies; 11+ messages in thread
From: Christian Taylor @ 2005-07-03 21:56 UTC (permalink / raw)
  To: zsh-users

Hi all,

I recently decided that I want the exit code of the last command (if it's 
greater than 0) displayed after invoking it, like the PRINT_EXIT_VALUE option 
does, but in my own format. (I don't want to include it in my prompt.)
I added the necessary code to the precmd function, which lead to the following 
undesired behaviour:

% false
(1)
% <just hitting enter>
(1)
%

To achieve the intended behaviour, I now let the preexec function set a 
variable to 1, and let the precmd function print the exit value only if this 
variable is set to 1 (afterwards setting it to 0). This works because the 
preexec function is only invoked if a real command is executed, not if you 
attempt to "execute" whitespace or nothing.

However: is there a simpler way to achieve this? My solution seems a bit 
inelegant to me.

Thanks,

Christian


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

* Re: reinventing print_exit_value
  2005-07-03 21:56 reinventing print_exit_value Christian Taylor
@ 2005-07-03 22:32 ` Nikolai Weibull
  2005-07-03 23:04   ` Christian Taylor
  2005-07-04 14:32 ` Bart Schaefer
  1 sibling, 1 reply; 11+ messages in thread
From: Nikolai Weibull @ 2005-07-03 22:32 UTC (permalink / raw)
  To: zsh-users

Christian Taylor wrote:

> I recently decided that I want the exit code of the last command (if it's 
> greater than 0) displayed after invoking it, like the PRINT_EXIT_VALUE option 
> does, but in my own format. (I don't want to include it in my prompt.)

Actually, you _do_ want to include it in your prompt.  Simply use

%(?..status: %?)

in your prompt, and it will only be displayed when there's something to
display (non-zero exit value in this case),
        nikolai

-- 
Nikolai Weibull: now available free of charge at http://bitwi.se/!
Born in Chicago, IL USA; currently residing in Gothenburg, Sweden.
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}


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

* Re: reinventing print_exit_value
  2005-07-03 22:32 ` Nikolai Weibull
@ 2005-07-03 23:04   ` Christian Taylor
  2005-07-03 23:35     ` Nikolai Weibull
  0 siblings, 1 reply; 11+ messages in thread
From: Christian Taylor @ 2005-07-03 23:04 UTC (permalink / raw)
  To: zsh-users

Nikolai Weibull wrote:
> Christian Taylor wrote:
> > I recently decided that I want the exit code of the last command (if it's
> > greater than 0) displayed after invoking it, like the PRINT_EXIT_VALUE
> > option does, but in my own format. (I don't want to include it in my
> > prompt.)
>
> Actually, you _do_ want to include it in your prompt. Simply use 
>
> %(?..status: %?)
>
> in your prompt, and it will only be displayed when there's something to
> display (non-zero exit value in this case),

I know, I tried it both in the left and the right prompt, but for some reason 
I just didn't like it. A PRINT_EXIT_VALUE-style output on an extra line suits 
me more.
This is really just cosmetics, but hey - everything else just works, where's 
the fun in that? :)

Christian


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

* Re: reinventing print_exit_value
  2005-07-03 23:04   ` Christian Taylor
@ 2005-07-03 23:35     ` Nikolai Weibull
  2005-07-04  0:09       ` Christian Taylor
  0 siblings, 1 reply; 11+ messages in thread
From: Nikolai Weibull @ 2005-07-03 23:35 UTC (permalink / raw)
  To: zsh-users

Christian Taylor wrote:

> I know, I tried it both in the left and the right prompt, but for some reason 
> I just didn't like it. A PRINT_EXIT_VALUE-style output on an extra line suits 
> me more.

You know that a prompt can be more than one line, right?  Use
$prompt_newline with the prompt module.  You can easily put the
exit status above or below the rest of the prompt,
        nikolai

-- 
Nikolai Weibull: now available free of charge at http://bitwi.se/!
Born in Chicago, IL USA; currently residing in Gothenburg, Sweden.
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}


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

* Re: reinventing print_exit_value
  2005-07-03 23:35     ` Nikolai Weibull
@ 2005-07-04  0:09       ` Christian Taylor
  2005-07-04 12:29         ` Nikolai Weibull
  0 siblings, 1 reply; 11+ messages in thread
From: Christian Taylor @ 2005-07-04  0:09 UTC (permalink / raw)
  To: zsh-users

Nikolai Weibull wrote:
> Christian Taylor wrote:
> > I know, I tried it both in the left and the right prompt, but for some
> > reason I just didn't like it. A PRINT_EXIT_VALUE-style output on an extra
> > line suits me more.
>
> You know that a prompt can be more than one line, right?  Use
> $prompt_newline with the prompt module.  You can easily put the
> exit status above or below the rest of the prompt,

Yes, I could also achieve the desired output using a multi-lined prompt, but I 
would still have to perform the same check using the preexec-function that I 
mentioned in my original posting. (After just hitting enter, the exit status 
is not reset, and so it would be displayed a second time.)
The behaviour I want (and get, using the preexec-check) is:

% false
(1)
% <just hitting enter>
%

Thanks nonetheless,

Christian


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

* Re: reinventing print_exit_value
  2005-07-04  0:09       ` Christian Taylor
@ 2005-07-04 12:29         ` Nikolai Weibull
  2005-07-04 13:24           ` J
  2005-07-04 14:29           ` Christian Taylor
  0 siblings, 2 replies; 11+ messages in thread
From: Nikolai Weibull @ 2005-07-04 12:29 UTC (permalink / raw)
  To: zsh-users

Christian Taylor wrote:

> Yes, I could also achieve the desired output using a multi-lined
> prompt, but I would still have to perform the same check using the
> preexec-function that I mentioned in my original posting. (After just
> hitting enter, the exit status is not reset, and so it would be
> displayed a second time.)

OK, I missed that, sorry.  Still, how much of a problem is this?
Perhaps you should just stop hitting <Enter> a bunch of times after a
non-zero exit status? ;-),
        nikolai

-- 
Nikolai Weibull: now available free of charge at http://bitwi.se/!
Born in Chicago, IL USA; currently residing in Gothenburg, Sweden.
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}


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

* Re: reinventing print_exit_value
  2005-07-04 12:29         ` Nikolai Weibull
@ 2005-07-04 13:24           ` J
  2005-07-04 13:25             ` J
  2005-07-04 14:29           ` Christian Taylor
  1 sibling, 1 reply; 11+ messages in thread
From: J @ 2005-07-04 13:24 UTC (permalink / raw)
  To: zsh-users

On 7/4/05, Nikolai Weibull
<mailing-lists.zsh-users@rawuncut.elitemail.org> wrote:
> Christian Taylor wrote:
> 
> > Yes, I could also achieve the desired output using a multi-lined
> > prompt, but I would still have to perform the same check using the
> > preexec-function that I mentioned in my original posting. (After just
> > hitting enter, the exit status is not reset, and so it would be
> > displayed a second time.)
> 
> OK, I missed that, sorry.  Still, how much of a problem is this?
> Perhaps you should just stop hitting <Enter> a bunch of times after a
> non-zero exit status? ;-),
>         nikolai
> 
> -- 
> Nikolai Weibull: now available free of charge at http://bitwi.se/!
> Born in Chicago, IL USA; currently residing in Gothenburg, Sweden.
> main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}
> 


-- 
J
"If you wish to leave a record of your call,
 please state your messij at the sound of the tone."


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

* Re: reinventing print_exit_value
  2005-07-04 13:24           ` J
@ 2005-07-04 13:25             ` J
  0 siblings, 0 replies; 11+ messages in thread
From: J @ 2005-07-04 13:25 UTC (permalink / raw)
  To: zsh-users

Oops, seems like I shit myself with my MUA interface. Sorry for the noise.

-- 
J
"If you wish to leave a record of your call,
 please state your messij at the sound of the tone."


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

* Re: reinventing print_exit_value
  2005-07-04 12:29         ` Nikolai Weibull
  2005-07-04 13:24           ` J
@ 2005-07-04 14:29           ` Christian Taylor
  1 sibling, 0 replies; 11+ messages in thread
From: Christian Taylor @ 2005-07-04 14:29 UTC (permalink / raw)
  To: zsh-users

Nikolai Weibull wrote:
> Still, how much of a problem is this? 
> Perhaps you should just stop hitting <Enter> a bunch of times after a
> non-zero exit status? ;-),

Well, it's not exactly a hobby of mine :)
I accidentally did it once, and then I just had to "fix" the script...

Christian


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

* Re: reinventing print_exit_value
  2005-07-03 21:56 reinventing print_exit_value Christian Taylor
  2005-07-03 22:32 ` Nikolai Weibull
@ 2005-07-04 14:32 ` Bart Schaefer
  2005-07-04 22:32   ` Christian Taylor
  1 sibling, 1 reply; 11+ messages in thread
From: Bart Schaefer @ 2005-07-04 14:32 UTC (permalink / raw)
  To: zsh-users

On Jul 3, 11:56pm, Christian Taylor wrote:
}
} However: is there a simpler way to achieve this? My solution seems a bit 
} inelegant to me.

How about this way of putting it into the prompt?

PS1="%{%(0?..$(echotc DO 1)$(echotc sc)
$(echotc rc)$(echotc UP 1))%}%# %{%(0?..$(echotc sc)
(%?%)$(echotc rc))%}"

Translation:

Counting no size for this output -
- if $? is 0, output nothing
- else, try to move down one line, then save the cursor position, output
  a newline, restore the cursor position and try to move up one line.
Output a percent or pound character followed by a space.
Counting no size for this output -
- if $? is 0, output nothing
- else, save the cursor position, emit a newline and the value of $? in
  parens and restore the cursor.

What this does is cause an extra line to be added BELOW the regular prompt,
rather than above it, which contains the nonzero exit status.  Each time
you hit enter at the prompt, the new prompt covers up the previous result
and displays it again, so it's always visible but never occupies more than
one vertical line of your screen.

You may need to adjust that first part for your terminal; it's intended
to handle vt100/xterm save/restore cursor behavior at any line of the
screen, including the last line where emitting a newline scrolls the text
but does not change the saved position.  It doesn't always work properly
when NO_PROMPT_CR is set because ZLE may reposition the cursor again after
the prompt has been printed.  (This may be an issue only in 4.0.x rather
than 4.2.x.)


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

* Re: reinventing print_exit_value
  2005-07-04 14:32 ` Bart Schaefer
@ 2005-07-04 22:32   ` Christian Taylor
  0 siblings, 0 replies; 11+ messages in thread
From: Christian Taylor @ 2005-07-04 22:32 UTC (permalink / raw)
  To: zsh-users

Bart Schaefer wrote:
> On Jul 3, 11:56pm, Christian Taylor wrote:
> }
> } However: is there a simpler way to achieve this? My solution seems a bit
> } inelegant to me.
>
> How about this way of putting it into the prompt?
>
> PS1="%{%(0?..$(echotc DO 1)$(echotc sc)
> $(echotc rc)$(echotc UP 1))%}%# %{%(0?..$(echotc sc)
> (%?%)$(echotc rc))%}"

Thanks, I didn't know about echotc (and echoti), in fact it didn't occur to me 
that I could manipulate the cursor position directly. This has given me 
something new to play with :)

Christian


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

end of thread, other threads:[~2005-07-04 22:33 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-03 21:56 reinventing print_exit_value Christian Taylor
2005-07-03 22:32 ` Nikolai Weibull
2005-07-03 23:04   ` Christian Taylor
2005-07-03 23:35     ` Nikolai Weibull
2005-07-04  0:09       ` Christian Taylor
2005-07-04 12:29         ` Nikolai Weibull
2005-07-04 13:24           ` J
2005-07-04 13:25             ` J
2005-07-04 14:29           ` Christian Taylor
2005-07-04 14:32 ` Bart Schaefer
2005-07-04 22:32   ` Christian Taylor

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).