Bash prompts¶
Quite often hosting providers by default will give a really stripped down bash prompt that isn't very helpful. A good example of this is UKFast.
Below is a fairly standard bash prompt that can be used instead, to give a more helpful output. This will need to be put in your users ~/.bashrc
file, and can also be set just for the session by just running the command in the terminal with a prefix of export
.
PS1="\e[0;37m[\u@\h \W]\$ \e[m "
In the above, the number 37 refers to the colour of the prompt, here's a list of colours:
- Red: 31
- Yellow: 33
- Green: 32
- White: 37
so for a red version of the above prompt, you would use PS1="\e[0;31m[\u@\h \W]\$ \e[m "
You can also make interactive prompts like this one below:
RESET="\[\017\]"
NORMAL="\[\033[0m\]"
RED="\[\033[31;1m\]"
YELLOW="\[\033[33;1m\]"
GREEN="\[\033[32;1m\]"
WHITE="\[\033[37;1m\]"
SMILEY="${WHITE}:)${NORMAL}"
FROWNY="${RED}:(${NORMAL}"
SELECT="if [ \$? = 0 ]; then echo \"${SMILEY}\"; else echo \"${FROWNY}\"; fi"
PS1="${RESET}${RED}\u${NORMAL}@${YELLOW}\h${NORMAL} ${white}\w${NORMAL} \`${SELECT}\` ${YELLOW}>${NORMAL}"