Skip to content

Instantly share code, notes, and snippets.

@hospadar
Last active March 15, 2018 18:00
Show Gist options
  • Save hospadar/91f1f0104d862d6fc996 to your computer and use it in GitHub Desktop.
Save hospadar/91f1f0104d862d6fc996 to your computer and use it in GitHub Desktop.
Luke's Ultimate Prompt v3
#Luke's Ultimate Prompt
#displays shortened time, username, shortened absolute path, git branch status colored red if dirty, colored smiley face indicating return code of previous command
#also includes a colored mortal kombat PS2 for those long commands.
#Written by Luke Hospadaruk with lots of help from the internet
find_git_branch() {
# Based on: http://stackoverflow.com/a/13003854/170413
local branch
if branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null); then
if [[ "$branch" == "HEAD" ]]; then
echo -n ' detached*'
fi
echo -n " $branch"
else
echo -n ""
fi
}
find_git_dirty() {
local status=$(git status --porcelain 2> /dev/null)
if [[ "$status" != "" ]]; then
return 0
else
return 1
fi
}
#show kubernetes environment in PS1 prompt
kube_env() {
if [ ! -z "$(which kubectl)" ]
then
local env=$(kubectl config current-context)
case "$env" in
prod) printf ' \e[1;91mp\e[49;39;0m';;
test) printf ' \e[1;92mt\e[49;39;0m';;
*) printf ' \e[1;95m?\e[0;39m';;
esac
else
echo -n ' \e[1;95m?\e[0;39m'
fi
}
PS1="\$(RETCODE=\$?; echo -n '\[\033[01;31m\]'; echo -n \`date +%H:%M\`; echo -n '\[\033[01;00m\]|\[\033[01;33m\]\h\[\033[00m\]:'; echo -n '\[\033[01;34m\]'; echo -n \`pwd | sed 's|/\([^/]\)[^/]*|/\1|g' | sed 's|[^/]*$||g'\`; echo -n '\W\[\033[00m\]'; if [ ! -z \`which kubectl\` ]; then if [ \"\`cat ~/.kube/config | egrep '^current-context:' | cut -f2 -d: | tr -d '[:space:]'\`\" = prod ]; then echo -n ' \[\033[1;91m\]p\[\033[0m\]'; elif [ \"\`cat ~/.kube/config | egrep '^current-context:' | cut -f2 -d: | tr -d '[:space:]'\`\" = test ]; then echo -n ' \[\033[1;92m\]t\[\033[0m\]'; else echo -n ' \[\033[1;95m\]?\[\033[0m\]'; fi; fi; if find_git_dirty; then echo -n \"\[\e[91m\]\";find_git_branch; else echo -n \"\[\e[36m\]\";find_git_branch; fi; if [[ \$RETCODE == 0 ]]; then echo -n \"\[\e[36m\] :)\"; else echo -n \"\[\e[91m\] :(\"; fi; echo -n '\[\033[00m\]';) "
PS2='\[\033[91m\]FINISH HIM! > \[\033[00m\]'
bind '"\e[A":history-search-backward'
bind '"\e[B":history-search-forward'
unset color_prompt force_color_prompt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment