bash Prompt
Making the Standard bash Prompt a Little Friendlier
For many new Linux users, the idea that the command line is the best
way to get many tasks done is daunting. On Red Hat based systems,
the default prompt is pretty basic:
[userid@hostname current_dir]$
or [root@hostname current_dir]#
At a glance there isn't a great deal between the regluar user account and the superuser (root) account. I like to create a small script into /etc/profile.d/bashprompt.sh
The script keeps the same format, it just applies color to the prompt, so standard user ids are blue, root is red, the hostname is green and the current directory is yellow.
#!/bin/bash
RESET="\[\e[0m\]"
RED="\[\e[0;91m\]"
GREEN="\[\e[0;92m\]"
BLUE="\[\e[0;96m\]"
YELLOW="\[\e[0;93m\]"
if [[ ${EUID} == 0 ]] ; then
PS1="[$RED\u$RESET@$GREEN\h$RESET $YELLOW\W$RESET]\\$ "
else
PS1="[$BLUE\u$RESET@$GREEN\h$RESET $YELLOW\W$RESET]\\$ "
fi
If you use git on Fedora (and other rpm based systems), there is a git-prompt.sh file that provides some basic status on you local repo. To add it to your colorized prompt, use the following as your /etc/profile.d/bashprompt.sh.
#!/bin/bash
if [[ -f /usr/share/git-core/contrib/completion/git-prompt.sh ]]; then
source /usr/share/git-core/contrib/completion/git-prompt.sh
GITPS=1
fi
RESET='\[\e[0m\]'
RED='\[\e[0;91m\]'
GREEN='\[\e[0;92m\]'
BLUE='\[\e[0;96m\]'
YELLOW='\[\e[0;93m\]'
WHITE='\[\e[0;97m\]'
if [[ ${GITPS} == 1 ]]; then
if [[ ${EUID} == 0 ]]; then
PS1="$WHITE[$RED\u$RESET@$BLUE\h$RESET $YELLOW\W$RESET"'$(__git_ps1 " (%s)")'"$WHITE]$RESET\\$ "
else
PS1="$WHITE[$GREEN\u$RESET@$BLUE\h$RESET $YELLOW\W$RESET"'$(__git_ps1 " (%s)")'"$WHITE]$RESET\\$ "
fi
else
if [[ ${EUID} == 0 ]]; then
PS1="$WHITE[$RED\u$RESET@$BLUE\h$RESET $YELLOW\W$WHITE]$RESET\\$ "
else
PS1="$WHITE[$GREEN\u$RESET@$BLUE\h$RESET $YELLOW\W$WHITE]$RESET\\$ "
fi
fi
Finally, the bashprompt.sh file should be world readable and executable, but not world writeable (use either file mode 775 or 755).