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.

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.

1 Answer 1

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

Your Answer

 
discard

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