Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Click here to return to the 'Another bash prompt trick' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Another bash prompt trick
Authored by: dougc on Dec 22, '01 11:10:55AM

This is a cool tip, but I've never liked so much stuff in the prompt, so I split it up and put some into the title bar. My prompt is simply two lines:

export PS1='$USER@$HOST:{!}=>'

This line should be obvious. It will set your prompt to user@host and also display the command number. The command number is handy for executing a previous command. For example, !25 will execute command 25 in the history.

export PROMPT_COMMAND='echo -n "^[]1;$PWD^G"'

This line is a little tricky. What is not obvious are the characters in between the " ". The first character is a literal escape character. It is input in vi by typing ^V then pressing the escape key. These two keystrokes will produce the two characters ^[ . The next characters are just regular characters: ]1'$PWD . But the last character is a literal ^G. It is entered the same way as the escape, in vi type ^V then ^G. What all of this work will get you, is the current path (or whatever $PWD is set to) in the title bar of your terminal window.

[ Reply to This | # ]
Another bash prompt trick
Authored by: dlandrith on Dec 22, '01 11:54:35AM

This one rocks. Definitely better than what I posted.

[ Reply to This | # ]
Another bash prompt trick
Authored by: dougc on Dec 24, '01 06:28:27PM

Naw... It's nothing really. This is just old xterm stuff that I've never forgot.

BTW, thanks for pushing bash. I don't know how anyone can use csh based shells any more.

[ Reply to This | # ]
Setting the Terminal window title from tcsh
Authored by: thinkyhead on Dec 30, '01 05:18:54AM
To set the title of the Terminal window from tcsh you do pretty much the same thing, except tcsh uses an alias to do its magic: alias cwdcmd 'echo -n "^[]1;$PWD^G"'

[ Reply to This | # ]
Another bash prompt trick
Authored by: packy on Jan 29, '02 02:08:10PM
It's even easier than you guys are making it out to be. I set my bash prompt with the following:
PS1="\[\033]0;\u @ \h: \w\007\]\$ "
This sets my widow title to be "<username> @ <hostname>: <path> (ttyp?)".

[ Reply to This | # ]