To change the shell prompt, change the variable $PS1 the .bashrc (depends on the shell you use)
\u : user name
\h : hostname
\w : the current absolute path (use /W if you only want to relative path)
\n : new line
To add color to the prompt
\e[ : start to add colorx;ym : set the color to x;y
\e[m : end to add color
another format to add color
For example, green string 'HelloWorld'
.bashrc
# the color code for green is 01;32m
PS1='\e[01;32mHelloWorld\e[m'
Another example:Green user name (spencer)
purple directory (~) in a pair of bracket ([XXXX])
ending up with a dollar sign ($) and leave a space.
.bashrc
PS1='\e[01;32m\u:\e[m\e[11;35m[\w]$\e[m '
# 01;32m = green, 11;35m = purple
# use one pair of declaration for one color
Update Jan. 24, 2014:
It seems that using the purple color (11;35m) may result in a bug, choose another color, for example blue (01:34).
No comments:
Post a Comment