Skip to content

Instantly share code, notes, and snippets.

@ykshatroff
Created October 29, 2019 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ykshatroff/2511225a6610e1354bf3400b43ef0c99 to your computer and use it in GitHub Desktop.
Save ykshatroff/2511225a6610e1354bf3400b43ef0c99 to your computer and use it in GitHub Desktop.
Bash colored prompt
# 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