Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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

How would I change this

[Sat Jun 02 14:24:12 vivek@server:~ ] $

to [Sat Jun 02 14:24:12 vivek@server:myDirectory! ] $

while "myDirectory!" is customized string that only shows up when I am in my home Directory. I believe, i'd have to do that in this format $ PS1="[\d \t \u@\h:\w ] $ ". I may be wrong.

PS: I don't have linux to fiddle around. I practice in my school.

share|improve this question

migrated from stackoverflow.com Feb 11 '12 at 21:39

This question came from our site for professional and enthusiast programmers.

Bash provides an environment variable called PROMPT_COMMAND. The contents of this variable are executed as a regular Bash command just before Bash displays a prompt.

http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x264.html

Insert an if/then statement into PROMPT_COMMAND to change your PS1 variable. Add this line to your .bashrc:

PROMPT_COMMAND='if [ $PWD == $HOME ]; then PS1="[\d \t \u@\h:myDirectory! ] $ "; else PS1="[\d \t \u@\h:\w ] $ "; fi'
share|improve this answer

You must log in to answer this question.

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