4

I have recently moved to zsh from bash (on OSX). I have an bash alias I have used to run one program then another (even if previous program exits with error) on bash. I can't work out how to replicate this in zsh.

bash alias I would like to replicate is:

gulp ; say "Gulp has crashed"

Does anyone know how to rewrite this in zsh?

Edit:

The difference between zsh and bash I'm getting is that; with Bash pressing ctrl-c when gulp is running, stops gulp and then goes on to the next command.

in Zsh pressing ctrl-c seems to stop whole command line.

The purpose of my use of this line is to get an audible warning when gulp stops running in the background. (for non-mac users the say command is a text to speach converter)

3

I propose to use a function instead:

mygulp () { trap : INT; gulp || say "Gulp has crashed"; }

The trap will catch Ctrl-C ("interrupt" signal) and run : command (ie. nothing).

Notice also || instead of ; - this way if gulp exits normally (you didn't press ctrl-c) then nothing happens, but if exit code is not zero then say command will start.

This function should work both in bash and zsh, in the later you can remove last ; before closing right bracket.

  • Watch out that the trap will still be in place when the function exits. To avoid this portably, use mygulp () (…) to run the function code in a subshell. In zsh, alternatively, run setopt local_traps local_opions in the function. – Gilles May 31 '16 at 22:19
  • The second option from @Gilles should be local_options. – Wieland Jun 1 '16 at 15:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.