ed_is_my_name
ed_is_my_name

Reputation: 631

Linux: add command to another command in bashrc

I run a lot of commands(unit tests) that take a long time to finish. Is there a way to alter my .bashrc to add a 'beep' to the end of every command so I don't have to remember to add it myself?

ex: %phpunit yadayada ; beep

thanks.

Upvotes: 1

Views: 565

Answers (2)

Blitz
Blitz

Reputation: 5671

Pretty certain that it's not possible for every command, but you could create an alias to achieve this (using ping as the example)

#!/bin/bash
ping () { command ping "$@"; beep; }

[Edit:] that other guy's solution is much better, i've adapted mine...

Upvotes: 1

that other guy
that other guy

Reputation: 123460

The contents of PROMPT_COMMAND is executed before every prompt. You can therefore cause a beep after every command with

PROMPT_COMMAND='beep'

To just beep after one specific command, you can override it with a function:

phpunit() {
  command phpunit "$@"
  beep
}

It's also prudent to preserve phpunit's exit code, so that you can still do things like phpunit .. && doStuff to only doStuff when the tests pass:

phpunit() {
  command phpunit "$@"
  local r=$?
  beep
  return $r
}

Upvotes: 3

Related Questions