Last active
December 21, 2015 06:29
-
-
Save natronics/6264297 to your computer and use it in GitHub Desktop.
My simple version of a bash prompt that shows current git info.
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
## git status in prompt | |
find_git_status() { | |
local c_red='\[\e[31m\]' | |
local c_green='\[\e[32m\]' | |
local c_clear='\[\e[0m\]' | |
ps1pc_start="$1" | |
ps1pc_end="$2" | |
local branch | |
if branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null); then | |
if [[ "$branch" == "HEAD" ]]; then | |
branch='detached*' | |
fi | |
git_branch="$branch" | |
else | |
git_branch="" | |
fi | |
if [[ "$git_branch" != "" ]]; then | |
git_sha=$(git rev-parse --short HEAD 2> /dev/null) | |
local status=$(git status --porcelain 2> /dev/null) | |
if [[ "$status" != "" ]]; then | |
git_message=" ($c_red$git_sha@$git_branch*$c_clear)" | |
else | |
git_message=" ($c_green$git_sha@$git_branch$c_clear)" | |
fi | |
else | |
git_message='' | |
fi | |
## Virtual env | |
if test -z "$VIRTUAL_ENV" ; then | |
PYTHON_VIRTUALENV="" | |
else | |
PYTHON_VIRTUALENV="(`basename $VIRTUAL_ENV`)" | |
fi | |
export PS1=$ps1pc_start$git_message$ps1pc_end | |
} | |
PROMPT_COMMAND='find_git_status "$PYTHON_VIRTUALENV\u@\h:\w" "\\\$ "' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment