BrT

Musings about technology and other neat stuff

BrT random header image

Adding growl notification to Raymond Page’s bash prompt code

September 8th, 2008 · No Comments

Update (2008/09/10): Giles Orr kindly pointed out that he is not the author of the bash prompt package I use, I have updated to give proper credit to the author, Raymond Page.

For some time I have used Raymond Page’s bash prompt code (heavily based on the work by Giles Orr in the Bash Prompt HOWTO, you can get it at http://gentoo-wiki.com/TIP_Prompt_Magic or http://code.google.com/p/homenix/source/browse/, you need to get .prompt, .prompt_functions and .prompt_config from the trunk/ directory), which I like very much because it is highly customizable, and although a lot of the functions are Linux-specific, it can easily be made to work on Mac OS X. It features context-dependent prompt colorization (e.g. based on whether the current directory is writable and on the machine load), automatic shortening of the prompt based on window width, and many other features.

More recently, I came across this hint for producing Growl notifications for shell commands that run for more than a predefined length of time, which I find extremely useful for knowing when those commands have finished.

Because both rely on some of the same mechanisms in bash, merging them is not completely straightforward. Here’s what I did:

  1. Download and install .preexec.bash as instructed in the hint.
  2. Add the preexec() function and preexec_install call to your .bashrc or .bash_login file (as instructed)
  3. Add the code from the precmd() function in the hint to the preexisting precmd() function in the .prompt file. I added it at the end. This is the main difference from what is described in the hint. I added it at the very end of the function.

That’s it – a nice bash prompt with growl notifications for long-running commands.

Posted by email from zzamboni’s posterous

Tags: · · · · ·