[GLLUG] bash PS1 commands...

Sean picasso@madflower.com
Thu, 15 May 2003 21:40:18 -0400 (EDT)


And in case you need to remember this when you don't have Matt's great 
examples and expertise around. The Bash man page under PROMPTING 
lists all the flags. (but not the cool control charactors like Matts 
examples contain.) 



On Thu, 15 May 2003, Matt Graham wrote:

> Several folks asked about customizing the prompt when using bash.  This 
> is at least one way to do it:
> 
> export PS1='\[\033[01;32m\]\h:\[\033[01;34m\]\w\$ \[\033[00m\]'
> 
> ...looks ugly.  Let's dissect it.
> 
> \[\033[01;32m\]
> 
> The \[ and \] are delimiters which tell bash that whatever's enclosed in 
> them is a nonprinting sequence of characters.  The \033[01;32m is an 
> escape code sequence that says "set the foreground color to light 
> green".  "man console_codes" for info on all the escape sequences you 
> can use.
> 
> \h:
> 
> "\h" gets expanded to the hostname of the machine you're currently on.  
> ":" just prints a : .
> 
> \[\033[01;34m\]
> 
> Another escape sequence that sets the foreground color to blue.
> 
> \w\$
> 
> \w expands to the current working directory.  \$ expands to a $ sign if 
> you're a normal user, and a # sign if you're root.
> 
> \[\033[00m\]
> 
> A final escape code sequence that sets the foreground and backgrouns 
> colors to their defaults.  If you left this off, whatever you typed at 
> the prompt would be blue!  Don't leave this off if you've decided to 
> mess with colors.
> 
> Other things you can embed into PS1 include:
> 
> \A  current time
> \u  current username
> \d  current date
> \W  current working directory (short form)
> 
> http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/index.html for more than you 
> ever wanted to know about this subject.
> 
>