2

I'm looking to setup visual alerts when working within certain directories within mac osx terminal.

Specifically, I have several projects running within the same framework which can easily lead to mistakes. I end up running a pwd before other commands if I've been away for the terminal windows for more than a few moments. Seems like a dumb extra step.

All resources I've found are just about setting up color profiles in my bash profile :(

UPDATED Here is the answer so far (does bark a note, doesn't work for color). Read below for why.

#! /bin/bash -i

# Add this to ~/.bash_profile
# PROMPT_COMMAND=/usr/local/bin/coloraware

PROJECT1='projectfolder/'
PROJECT2='projectfolder2/'
PROJECT3='projectfolder3/'
PWD=`pwd`

case "$PWD/" in
    *$PROJECT1*)
        export PS1='\[\e[1;31m\][\u@\h \W]\$\[\e[0m\] '
        echo "Project #1"
        ;;
    *$PROJECT2*)
        export PS1='\[\e[1;34m\][\u@\h \W]\$\[\e[0m\] '
        echo "Project #2"
        ;;
    *$PROJECT3*)
        export PS1='\[\e[1;35m\][\u@\h \W]\$\[\e[0m\] '
        echo "Project #3"
        ;;
esac
2

1 Answer 1

1

You can change the color of your terminal session as explained in @DanielBeck's answer here.

You could wrap the call to osascript in a shell script that pulls your current working directory, then put that shell script somewhere into your $PATH, or possibly even into your command prompt PS1.

For example, if the basename of the working directory is my home folder, then run the AppleScript command to change colors (or, in this case, just nag me with a dialog).

#!/bin/sh
if [ $(basename $PWD) = "werner" ]; then
  osascript -e 'tell app "Finder" to display dialog "foo"'
fi
5
  • Thanks for the color link and getting me on target with comparisons. Don't understand how this gets called automatically while in a folder to do the chirping or coloring. (Tried placing a direct link to the script into my $PATH in .bash_profile)
    – doublejosh
    Apr 24, 2012 at 21:37
  • Found the answer here: stackoverflow.com/questions/4585397/…
    – doublejosh
    Apr 24, 2012 at 21:48
  • @doublejosh Ah, fair enough — maybe just post your answer here and mark it as accepted yourself :)
    – slhck
    Apr 24, 2012 at 21:51
  • Still dealing within settings the PS1 within a script. Added #! /bin/bash -i to my header, but can't seem to set the color within the script. Will post the final result for sure!
    – doublejosh
    Apr 24, 2012 at 22:09
  • These folks seem to be doing so in a script, but I just can't get it to stick. serverfault.com/questions/4889/… Assume it's because the script swapped the color and parent shell stayed the same. Seems like the answer might be in here: stackoverflow.com/questions/9905524/… or here linux.die.net/man/1/bash with --rcfile
    – doublejosh
    Apr 25, 2012 at 1:14

You must log in to answer this question.

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