Last active
August 29, 2015 14:17
-
-
Save reedacartwright/c92cbf49e6ba828932c0 to your computer and use it in GitHub Desktop.
Shell Commands for Colorizing Shell Prompt and including error information
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
# Taken from https://github.com/reedacartwright/shell-config | |
# | |
# The following commands will produce a prompt that includes the error code of the | |
# last command run if it is not zero. E.g. | |
# [user@host dir $?=123]$ | |
# If the user is not root, the prompt is green, except the error information which is red. | |
# If the user is root, the prompt is read, except the error information which is green. | |
# If the last commend exited with a 0, then the prompt looks normal. E.g. | |
# [user@host dir]$ | |
# | |
#### BASH #### | |
# Add the following to your .bashrc | |
if [[ $EUID -ne 0 ]]; then | |
# Green for users | |
PS1='\[\e[1;32m\][\u@\h \W\[\e[0m\]`[ $? == 0 ] || echo " \[\e[1;91m\]\\\\$?=$?\[\e[0m\]"`\[\e[1;32m\]]\$\[\e[0m\] ' | |
else | |
# Red for root | |
PS1='\[\e[1;31m\][\u@\h \W\[\e[0m\]`[ $? == 0 ] || echo " \[\e[1;92m\]\\\\$?=$?\[\e[0m\]"`\[\e[1;31m\]]\$\[\e[0m\] ' | |
fi | |
#### TCSH #### | |
# Add the following to your .cshrc | |
if( `id -u` == "0") then | |
# Red for root | |
alias precmd 'set prompt="%{\033[1;31m%}[%n@%m %c`test $? = 0 || echo %\{\\033[1\;92m\\ \\044\\077%\}=%\?%\{\\033[1\;31m%\}`]%#%{\033[0m%} "' | |
else | |
# Green for users | |
alias precmd 'set prompt="%{\033[1;32m%}[%n@%m %c`test $? = 0 || echo %\{\\033[1\;91m\\ \\044\\077%\}=%\?%\{\\033[1\;32m%\}`]%#%{\033[0m%} "' | |
endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment