Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I know zsh has a preexec hook that fires before the command is executed, but is there one that fires after the command has been initiated but before the output is displayed to the screen? I ask because I want to display something based on if there was/will be actual output.

For example:
cd dir does not output anything
ls dir outputs stuff

In that example, I want to display: Output:\n before the ls directory display but not when cd is run since it doesn't have a display. I want it to look like:

~ $: cd dir
~/dir $: ls .
total 464
drwxr-xr-x+  55 eddie  staff   1.8K May  2 11:07 .
drwxr-xr-x    6 root   admin   204B Apr 22 13:48 ..
~/dir $

I don't just want to wrap cd and ls. Those were examples. I want it to be for every command.

share|improve this question
zsh cannot tell if there is going to be output because in order to do so it would have to give the command a pipe instead of the tty which would interfere with interactive programs. – Random832 May 2 '13 at 19:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.