Created
October 29, 2019 13:08
-
-
Save ykshatroff/2511225a6610e1354bf3400b43ef0c99 to your computer and use it in GitHub Desktop.
Bash colored prompt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set up a colored prompt in Bash with green (32) and red (31) colors for regular and root users, respectively, | |
# instead of the standard: | |
# PS1='[\u@\h \W]\$ ' | |
# | |
# This prompt also allows Bash to take its length into consideration correctly | |
# for command line start offset calculation. | |
# Place this file in /etc/bashrc.d or wherever feasible for inclusion in ~/.bashrc . | |
_color='32' | |
_chr=':' | |
if [ "$USER" = "root" ]; then | |
_color='31' | |
_chr='#' | |
fi | |
PS1="\001\e[0;${_color}m\002\h \W${_chr}\001\e[;m\002 " | |
unset _color | |
unset _chr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment