zsh-workers
 help / color / mirror / code / Atom feed
* Is there some postexec function?
@ 2011-07-06 15:39 Pascal Wittmann
  2011-07-06 15:48 ` Jérémie Roquet
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Pascal Wittmann @ 2011-07-06 15:39 UTC (permalink / raw)
  To: zsh-workers

Hi,

I wonder whether there exists a postexec function, a function that is
called, after a command is executed. I need something like that, because
I'm trying to print (redraw the prompt) the exit code of a program in
the prompt where it was called.

I've found some references¹ to such a function, but they didn't worked
on my system. I'm using zsh 4.3.12.


Thanks for your help,
Pascal Wittmann


[1] https://gist.github.com/47474


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

* Re: Is there some postexec function?
  2011-07-06 15:39 Is there some postexec function? Pascal Wittmann
@ 2011-07-06 15:48 ` Jérémie Roquet
  2011-07-06 17:01 ` ZyX
  2011-07-06 20:07 ` Bart Schaefer
  2 siblings, 0 replies; 6+ messages in thread
From: Jérémie Roquet @ 2011-07-06 15:48 UTC (permalink / raw)
  To: zsh-workers; +Cc: Pascal Wittmann

Hi,

2011/7/6 Pascal Wittmann <PascalWittmann@gmx.net>:
> I wonder whether there exists a postexec function, a function that is
> called, after a command is executed. I need something like that, because
> I'm trying to print (redraw the prompt) the exit code of a program in
> the prompt where it was called.

precmd is called before the next prompt is drawn, does it the trick?

Best regards,

-- 
Jérémie


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

* Re: Is there some postexec function?
  2011-07-06 15:39 Is there some postexec function? Pascal Wittmann
  2011-07-06 15:48 ` Jérémie Roquet
@ 2011-07-06 17:01 ` ZyX
  2011-07-06 20:07 ` Bart Schaefer
  2 siblings, 0 replies; 6+ messages in thread
From: ZyX @ 2011-07-06 17:01 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: Text/Plain, Size: 983 bytes --]

Reply to message «Is there some postexec function?», 
sent 19:39:43 06 July 2011, Wednesday
by Pascal Wittmann:

I personally use
    RPS1="%(?.."%{$'\033[33m\033[41m\033[1m'%}"%?"%{$'\033[0m'%}")"
, but it will draw the exit code only in next prompt (and only in the last one).

Can I ask how are you going to modify existing prompt? I know a way to modify 
the current line, but I don't know what to do if I want to modify the line after 
LF was fed to the terminal.

Original message:
> Hi,
> 
> I wonder whether there exists a postexec function, a function that is
> called, after a command is executed. I need something like that, because
> I'm trying to print (redraw the prompt) the exit code of a program in
> the prompt where it was called.
> 
> I've found some references¹ to such a function, but they didn't worked
> on my system. I'm using zsh 4.3.12.
> 
> 
> Thanks for your help,
> Pascal Wittmann
> 
> 
> [1] https://gist.github.com/47474

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

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

* Re: Is there some postexec function?
  2011-07-06 15:39 Is there some postexec function? Pascal Wittmann
  2011-07-06 15:48 ` Jérémie Roquet
  2011-07-06 17:01 ` ZyX
@ 2011-07-06 20:07 ` Bart Schaefer
  2011-07-06 20:28   ` Pascal Wittmann
  2 siblings, 1 reply; 6+ messages in thread
From: Bart Schaefer @ 2011-07-06 20:07 UTC (permalink / raw)
  To: Pascal Wittmann, zsh-workers

On Jul 6,  5:39pm, Pascal Wittmann wrote:
}
} I wonder whether there exists a postexec function, a function that is
} called, after a command is executed. I need something like that, because
} I'm trying to print (redraw the prompt) the exit code of a program in
} the prompt where it was called.

What does "in the prompt where it was called" mean, exactly?  Can you
give an example?

If it means what it appears to, you can't do it without subverting the
edit/execute paradigm.  The line editor is active, and thus the prompt
modifiable, right up until you commit to executing the command; then
the line editor exits, the command runs, and after the command is done
a new line editor starts up with a fresh prompt.

You could create a widget that runs the command, captures its status,
and updates the prompt, all within the line editor context, but that
would do odd things with job control and pipelines.  Or you could try
to play cursor movement games to overwrite the previous prompt with
something that was output with "print -P", but depending on what the
command does with the screen that may be impractical.

} I've found some references¹ to such a function, but they didn't worked
} on my system. I'm using zsh 4.3.12.

There's never been a postexec function, that must be someone's idiom
for something they've implemented another way (perhaps through precmd
as referenced by Jeremie).


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

* Re: Is there some postexec function?
  2011-07-06 20:07 ` Bart Schaefer
@ 2011-07-06 20:28   ` Pascal Wittmann
  2011-07-07  3:27     ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: Pascal Wittmann @ 2011-07-06 20:28 UTC (permalink / raw)
  To: zsh-workers

On 07/06/2011 10:07 PM, Bart Schaefer wrote:
> On Jul 6,  5:39pm, Pascal Wittmann wrote:
> }
> } I wonder whether there exists a postexec function, a function that is
> } called, after a command is executed. I need something like that, because
> } I'm trying to print (redraw the prompt) the exit code of a program in
> } the prompt where it was called.
> 
> What does "in the prompt where it was called" mean, exactly?  Can you
> give an example?
> 
> If it means what it appears to, you can't do it without subverting the
> edit/execute paradigm.  The line editor is active, and thus the prompt
> modifiable, right up until you commit to executing the command; then
> the line editor exits, the command runs, and after the command is done
> a new line editor starts up with a fresh prompt.
> 
> You could create a widget that runs the command, captures its status,
> and updates the prompt, all within the line editor context, but that
> would do odd things with job control and pipelines.  Or you could try
> to play cursor movement games to overwrite the previous prompt with
> something that was output with "print -P", but depending on what the
> command does with the screen that may be impractical.

Thanks for clearing things up! I didn't knew about the edit/execute
paradigm and I don't wont to subvert it, so I'll forget about my idea.


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

* Re: Is there some postexec function?
  2011-07-06 20:28   ` Pascal Wittmann
@ 2011-07-07  3:27     ` Bart Schaefer
  0 siblings, 0 replies; 6+ messages in thread
From: Bart Schaefer @ 2011-07-07  3:27 UTC (permalink / raw)
  To: zsh-workers

On Jul 6, 10:28pm, Pascal Wittmann wrote:
}
} Thanks for clearing things up! I didn't knew about the edit/execute
} paradigm and I don't wont to subvert it, so I'll forget about my idea.

If your goal is to have both the command that was executed and its exit
status visible at the same time, you can save the command text somewhere
(or just use the history, which saves it for you) and then put that into
the new prompt along with the status when the line editor starts again.

Have a look at Functions/Prompts/prompt_bart_setup for an example,
although it has a bunch of other stuff to interoperate with the prompt
theme system that you may not need to mess with.


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

end of thread, other threads:[~2011-07-07  3:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-06 15:39 Is there some postexec function? Pascal Wittmann
2011-07-06 15:48 ` Jérémie Roquet
2011-07-06 17:01 ` ZyX
2011-07-06 20:07 ` Bart Schaefer
2011-07-06 20:28   ` Pascal Wittmann
2011-07-07  3:27     ` Bart Schaefer

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