Thursday, September 4, 2008

Colored bash prompt

The following will set a bash prompt to highlight the name of the directory in yellow, and in bold.

export PS1="[\u@\h \[\033[1;33m\]\w\[\033[0m\]]$ "
This will also work:
export PS1='[\u@\h \[\e[1;33m\]\w\[\e[0m\]]$ '
The escapes have to be in single quotes, however.

During a previous attempt, I wasn't terminating everything correctly, and so when my command exceeded the length of the row, it wouldn't wrap around and start a new line. It was not just a Mac OS X Terminal problem; I tried it in rxvt (installed via MacPorts) as well as the xterm that came standard with Leopard's X11.

blog comments powered by Disqus