Question

I find myself running some long scripts/commands and I don't want to wait looking at it until it finishes. On the other hand, I would like to know right away when it ends. I know you can do the trick with &&, but it seems like a lot of typing.

Is there a way to do this by actually putting a post-execution hook in bash? I know this is Bash related and not so much OS X but maybe there is something hidden in OS X.

Was it helpful?

Solution

There's no post-execution hook, only a pre-execution hook: if set, the value of shell variable PROMPT_COMMAND is executed prior to issuing the prompt. See man bash for details.

An option would be to create a function that tells Terminal to beep after the long command is run, so you know when it finishes. Such a function would be:

$ function r { $@; beep; yourscript; }

Your script will be automatically launched after Terminal makes a beep.

Use the function to run those long commands like this:

$ r longcommand

You can add the function to your .bashrc file to avoid defining it every time.

If you're not a fan of audible bells you can tell Terminal to flash instead:

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with apple.stackexchange
scroll top