Created
February 15, 2024 00:06
-
-
Save colinmcintosh/ea5a4fa88f7d60a84ab2326dd2692226 to your computer and use it in GitHub Desktop.
bash smile 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
## Prompt | |
# Colors used for the prompt | |
# Regular text color | |
BLACK='\[\e[0;30m\]' | |
# Bold text color | |
BBLACK='\[\e[1;30m\]' | |
# Background color | |
BGBLACK='\[\e[40m\]' | |
RED='\[\e[0;31m\]' | |
BRED='\[\e[1;31m\]' | |
BGRED='\[\e[41m\]' | |
GREEN='\[\e[0;32m\]' | |
BGREEN='\[\e[1;32m\]' | |
BGGREEN='\[\e[1;32m\]' | |
YELLOW='\[\e[0;33m\]' | |
BYELLOW='\[\e[1;33m\]' | |
BGYELLOW='\[\e[1;33m\]' | |
BLUE='\[\e[0;34m\]' | |
BBLUE='\[\e[1;34m\]' | |
BGBLUE='\[\e[1;34m\]' | |
MAGENTA='\[\e[0;35m\]' | |
BMAGENTA='\[\e[1;35m\]' | |
BGMAGENTA='\[\e[1;35m\]' | |
CYAN='\[\e[0;36m\]' | |
BCYAN='\[\e[1;36m\]' | |
BGCYAN='\[\e[1;36m\]' | |
WHITE='\[\e[0;37m\]' | |
BWHITE='\[\e[1;37m\]' | |
BGWHITE='\[\e[1;37m\]' | |
PROMPT_COMMAND=smile_prompt | |
function smile_prompt | |
{ | |
if [ "$?" -eq "0" ]; then | |
#smiley | |
SC="${GREEN}:)" | |
else | |
#frowney | |
SC="${RED}:(" | |
fi | |
if test -z "$VIRTUAL_ENV" ; then | |
PYTHON_VIRTUALENV="" | |
else | |
PYTHON_VIRTUALENV="[`basename \"$VIRTUAL_ENV\"`] " | |
fi | |
GIT_BRANCH=$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/') | |
if ! test -z "$GIT_BRANCH" ; then | |
GIT_BRANCH=":$GIT_BRANCH" | |
fi | |
if [ $UID -eq 0 ]; then | |
#root user color | |
UC="${RED}" | |
else | |
#normal user color | |
UC="${BGREEN}" | |
fi | |
#environment colo | |
EC="${BCYAN}" | |
#hostname color | |
HC="${BGREEN}" | |
#regular color | |
RC="${BBLUE}" | |
#default color | |
DF='\[\e[0m\]' | |
PROMPT_DIRTRIM=3 | |
PS1="${DF}[${UC}\u${RC}@${HC}\h ${RC}\w${BYELLOW}${GIT_BRANCH}${DF}] ${SC}${DF} ${EC}${PYTHON_VIRTUALENV}${DF}" | |
echo -ne "\033]0;$(basename `pwd`)$GIT_BRANCH\a" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment