Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is there a way to change the prompt on a different directories on the same machine? For example, I want a simple prompt "[\W] \$" in development directories.

Ideas?

share|improve this question
1  
It depends on which shell you're using. –  Dennis Williamson Jan 1 '11 at 19:09

1 Answer 1

up vote 6 down vote accepted

You can put something like this in your .bashrc.

prompt-function() {
    case $PWD in
        /a/dev/dir\
        |/another/dev/dir) 
            PS1="[\W] \$"
            ;;
        *)
            # Change this to the default prompt
            PS1="\$ "
            ;;
     esac
}

PROMPT_COMMAND=prompt-function
share|improve this answer
    
+1 I would use a case statement instead of a series of elsif statements. You could even put the directories in an array and iterate over them with a for loop. You could use globbing patterns with any of those techniques or you could use regexes with [[ $PWD =~ $pattern ]]. –  Dennis Williamson Jan 1 '11 at 19:13
    
@Dennis: I edited my answer with a case statement. Thanks for the suggestion. –  Wuffers Jan 1 '11 at 19:16
    
If the action is the same, you can list the action once after alternative cases separated by pipe characters. foo|bar) action;; You can put the cases on separate lines by putting a backslash and newline before or after the pipe character. –  Dennis Williamson Jan 1 '11 at 21:47
    
@Dennis: Edited my answer accordingly, again. Thanks for the suggestion! –  Wuffers Jan 1 '11 at 21:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.