Skip to content

Instantly share code, notes, and snippets.

@iamnewton
Created January 15, 2014 21:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iamnewton/8445359 to your computer and use it in GitHub Desktop.
Save iamnewton/8445359 to your computer and use it in GitHub Desktop.
Changes the prompt (PS1) to green text for a normal user, red for root, and yellow for any other user attained via sudo.
color_root=$(tput setaf 1)
color_user=$(tput setaf 2)
color_sudo=$(tput setaf 3)
color_reset=$(tput sgr0)
// root user
if (( EUID == 0 )); then
PS1="\\[$color_root\\]$PS1\\[$color_reset\\]"
// sudo user
elif [[ $SUDO_USER ]]; then
PS1="\\[$color_sudo\\]$PS1\\[$color_reset\\]"
// all other users
else
PS1="\\[$color_user\\]$PS1\\[$color_reset\\]"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment