Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.


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

You can put something like this in your .bashrc.

prompt-function() {
    case $PWD in
            PS1="[\W] \$"
            # Change this to the default prompt
            PS1="\$ "

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


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.