Created
October 22, 2015 18:55
-
-
Save bartek/ce4c99f55c5bff5d52ec to your computer and use it in GitHub Desktop.
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 | |
RED="\[\033[0;31m\]" | |
PINK="\[\033[1;31m\]" | |
YELLOW="\[\033[1;33m\]" | |
GREEN="\[\033[0;32m\]" | |
LT_GREEN="\[\033[1;32m\]" | |
BLUE="\[\033[0;34m\]" | |
WHITE="\[\033[1;37m\]" | |
PURPLE="\[\033[1;35m\]" | |
CYAN="\[\033[1;36m\]" | |
BROWN="\[\033[0;33m\]" | |
COLOR_NONE="\[\033[0m\]" | |
LIGHTNING_BOLT="⚡" | |
UP_ARROW="↑" | |
DOWN_ARROW="↓" | |
UD_ARROW="↕" | |
FF_ARROW="→" | |
RECYCLE="♺" | |
MIDDOT="•" | |
PLUSMINUS="±" | |
function parse_git_branch { | |
branch_pattern="^# On branch ([^${IFS}]*)" | |
remote_pattern_ahead="# Your branch is ahead of" | |
remote_pattern_behind="# Your branch is behind" | |
remote_pattern_ff="# Your branch (.*) can be fast-forwarded." | |
diverge_pattern="# Your branch and (.*) have diverged" | |
git_status="$(git status 2> /dev/null)" | |
if [[ ! ${git_status} =~ ${branch_pattern} ]]; then | |
# Rebasing? | |
toplevel=$(git rev-parse --show-toplevel 2> /dev/null) | |
[[ -z "$toplevel" ]] && return | |
[[ -d "$toplevel/.git/rebase-merge" || -d "$toplevel/.git/rebase-apply" ]] && { | |
sha_file="$toplevel/.git/rebase-merge/stopped-sha" | |
[[ -e "$sha_file" ]] && { | |
sha=`cat ${sha_file}` | |
} | |
echo "${PINK}(rebase in progress)${COLOR_NONE} ${sha}" | |
} | |
return | |
fi | |
branch=${BASH_REMATCH[1]} | |
# Dirty? | |
if [[ ! ${git_status} =~ "working directory clean" ]]; then | |
[[ ${git_status} =~ "modified:" ]] && { | |
git_is_dirty="${RED}${LIGHTNING_BOLT}" | |
} | |
[[ ${git_status} =~ "Untracked files" ]] && { | |
git_is_dirty="${git_is_dirty}${WHITE}${MIDDOT}" | |
} | |
[[ ${git_status} =~ "new file:" ]] && { | |
git_is_dirty="${git_is_dirty}${LT_GREEN}+" | |
} | |
[[ ${git_status} =~ "deleted:" ]] && { | |
git_is_dirty="${git_is_dirty}${RED}-" | |
} | |
[[ ${git_status} =~ "renamed:" ]] && { | |
git_is_dirty="${git_is_dirty}${YELLOW}→" | |
} | |
fi | |
# Are we ahead of, beind, or diverged from the remote? | |
if [[ ${git_status} =~ ${remote_pattern_ahead} ]]; then | |
remote="${YELLOW}${UP_ARROW}" | |
elif [[ ${git_status} =~ ${remote_pattern_ff} ]]; then | |
remote_ff="${WHITE}${FF_ARROW}" | |
elif [[ ${git_status} =~ ${remote_pattern_behind} ]]; then | |
remote="${YELLOW}${DOWN_ARROW}" | |
elif [[ ${git_status} =~ ${diverge_pattern} ]]; then | |
remote="${YELLOW}${UD_ARROW}" | |
fi | |
echo "${remote}${remote_ff}${GREEN}(${branch})${COLOR_NONE}${git_is_dirty}${COLOR_NONE}" | |
} | |
function set_prompt { | |
[[ -n $HOMEBREW_DEBUG_INSTALL ]] && \ | |
homebrew_prompt="${BROWN}Homebrew:${COLOR_NONE} debugging ${HOMEBREW_DEBUG_INSTALL}\n" | |
git_prompt="$(parse_git_branch)" | |
if [ ! -z $VIRTUAL_ENV ]; then | |
venv_name="<${CYAN}venv:${VIRTUAL_ENV##*/}${COLOR_NONE}> " # last folder's name in a directory path | |
else | |
venv_name="" | |
fi | |
echo $git_is_dirty; | |
export GIT_PS1_SHOWDIRTYSTATE=1 # Show dirty! | |
export PS1="${venv_name}[\w] \[\e[0;32m\]$(__git_ps1 "(%s)") ${COLOR_NONE}\n${homebrew_prompt}\$ " | |
#export PS1=$'\[\e[0;36m\][\u@\h] \[\e[1;33m\]\w \[\e[0;32m\]$(__git_ps1 " (%s)")\[\e[0m\]\n \xe2\x86\xaa ' | |
} | |
export PROMPT_COMMAND=set_prompt | |
SHELL=`ps -ef | grep $$ | awk '{ print $8 }' | head -n1` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment