Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Use Growl to monitor long-running shell commands' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Use Growl to monitor long-running shell commands
Authored by: sentience on Nov 07, '08 12:22:32AM
Finally got this to work on Leopard after some fiddling. First, as a previous commenter noted, if you have a .profile file in your home directory, bash will ignore a .bashrc file. You must put the script into your .profile instead. Second, the script as written does not deal well with certain commands because the scripter left out some quotes. Here is the script as it works for me in my .profile file:
. ~/.preexec.bash

# called before each command and starts stopwatch
function preexec () {
	export PREEXEC_CMD="$BASH_COMMAND"
	export PREEXEC_TIME=$(date +'%s')
}

# called after each command, stops stopwatch
# and notifies if time elpsed exceeds threshold
function precmd () {
	stop=$(date +'%s')
	start=${PREEXEC_TIME:-$stop}
	let elapsed=$stop-$start
	max=${PREEXEC_MAX:-10}

	if [ $elapsed -gt $max ]; then
		growlnotify -n "Terminal" -m "took $elapsed secs" "${PREEXEC_CMD:-Terminal Command}"
	fi
}

preexec_install


[ Reply to This | # ]