* PS1='%?'
@ 2007-09-29 11:21 Atom Smasher
2007-09-29 12:02 ` PS1='%?' Stephane Chazelas
0 siblings, 1 reply; 7+ messages in thread
From: Atom Smasher @ 2007-09-29 11:21 UTC (permalink / raw)
To: zsh-users
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?
thanks...
--
...atom
________________________
http://atom.smasher.org/
762A 3B98 A3C3 96C9 C6B7 582A B88D 52E4 D9F5 7808
-------------------------------------------------
"To invent, you need a good imagination and a pile of junk."
-- Thomas Edison
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: PS1='%?'
2007-09-29 11:21 PS1='%?' Atom Smasher
@ 2007-09-29 12:02 ` Stephane Chazelas
2007-09-29 15:14 ` PS1='%?' Atom Smasher
0 siblings, 1 reply; 7+ messages in thread
From: Stephane Chazelas @ 2007-09-29 12:02 UTC (permalink / raw)
To: Atom Smasher; +Cc: zsh-users
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?
--
Stéphane
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: PS1='%?'
2007-09-29 12:02 ` PS1='%?' Stephane Chazelas
@ 2007-09-29 15:14 ` Atom Smasher
2007-09-29 21:09 ` PS1='%?' Matthew Wozniski
0 siblings, 1 reply; 7+ messages in thread
From: Atom Smasher @ 2007-09-29 15:14 UTC (permalink / raw)
To: zsh-users
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: PS1='%?'
2007-09-29 15:14 ` PS1='%?' Atom Smasher
@ 2007-09-29 21:09 ` Matthew Wozniski
2007-09-30 11:23 ` PS1='%?' Atom Smasher
2007-09-30 16:10 ` not running precmd - was: PS1='%?' Atom Smasher
0 siblings, 2 replies; 7+ messages in thread
From: Matthew Wozniski @ 2007-09-29 21:09 UTC (permalink / raw)
To: Atom Smasher; +Cc: zsh-users
On Sun, Sep 30, 2007 at 03:14:27AM +1200, Atom Smasher wrote:
> 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>.
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;
}
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: PS1='%?'
2007-09-29 21:09 ` PS1='%?' Matthew Wozniski
@ 2007-09-30 11:23 ` Atom Smasher
2007-09-30 16:10 ` not running precmd - was: PS1='%?' Atom Smasher
1 sibling, 0 replies; 7+ messages in thread
From: Atom Smasher @ 2007-09-30 11:23 UTC (permalink / raw)
To: zsh-users
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* not running precmd - was: Re: PS1='%?'
2007-09-29 21:09 ` PS1='%?' Matthew Wozniski
2007-09-30 11:23 ` PS1='%?' Atom Smasher
@ 2007-09-30 16:10 ` Atom Smasher
2007-10-01 9:50 ` Peter Stephenson
1 sibling, 1 reply; 7+ messages in thread
From: Atom Smasher @ 2007-09-30 16:10 UTC (permalink / raw)
To: zsh-users
while experimenting with displaying the previous command's return status
as part of my prompt, i came across a test case that didn't work and made
no sense at first:
return n>0
after some experimenting, i found that after running 'return', precmd is
not executed. that kind of makes sense, but it still seems kind of buggy.
should i think of this as a bug or an edge case that's a little over the
edge?
--
...atom
________________________
http://atom.smasher.org/
762A 3B98 A3C3 96C9 C6B7 582A B88D 52E4 D9F5 7808
-------------------------------------------------
"99 Decision Street, 99 ministers meet
To worry, worry, super-scurry
Call the troops out in a hurry
This is what we've waited for
This is it boys, this is war
The president is on the line
As 99 red balloons go by."
-- Nena
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: not running precmd - was: Re: PS1='%?'
2007-09-30 16:10 ` not running precmd - was: PS1='%?' Atom Smasher
@ 2007-10-01 9:50 ` Peter Stephenson
0 siblings, 0 replies; 7+ messages in thread
From: Peter Stephenson @ 2007-10-01 9:50 UTC (permalink / raw)
To: zsh-users
On Mon, 1 Oct 2007 05:10:00 +1300 (NZDT)
Atom Smasher <atom@smasher.org> wrote:
> after some experimenting, i found that after running 'return', precmd is
> not executed. that kind of makes sense, but it still seems kind of buggy.
> should i think of this as a bug or an edge case that's a little over the
> edge?
That's probably fixed by this.
2007-09-26 Peter Stephenson <pws@csr.com>
* users/11883: Src/init.c: "return" at top level caused
following precommand functions to return immediately.
--
Peter Stephenson <pws@csr.com> Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2007-10-01 9:50 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-09-29 11:21 PS1='%?' Atom Smasher
2007-09-29 12:02 ` PS1='%?' Stephane Chazelas
2007-09-29 15:14 ` PS1='%?' Atom Smasher
2007-09-29 21:09 ` PS1='%?' Matthew Wozniski
2007-09-30 11:23 ` PS1='%?' Atom Smasher
2007-09-30 16:10 ` not running precmd - was: PS1='%?' Atom Smasher
2007-10-01 9:50 ` Peter Stephenson
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).