6

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)

0

1 Answer 1

4

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.

2
  • 2
    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. Commented May 31, 2016 at 22:19
  • 1
    The second option from @Gilles should be local_options.
    – Wieland
    Commented Jun 1, 2016 at 15:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .