Created
May 7, 2014 09:16
-
-
Save a3linux/04ffde63a37c3ad735e1 to your computer and use it in GitHub Desktop.
Git PS1 Prompt
This file contains hidden or 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
function parse_git_branch { | |
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1) /' | |
} | |
function git_unadded_new { | |
if git rev-parse --is-inside-work-tree &> /dev/null | |
then | |
if [[ -z $(git ls-files --other --exclude-standard 2> /dev/null) ]] | |
then | |
echo "" | |
else | |
echo "@ " | |
fi | |
fi | |
} | |
function git_needs_commit { | |
if [[ "git rev-parse --is-inside-work-tree &> /dev/null)" != 'true' ]] && git rev-parse --quiet --verify HEAD &> /dev/null | |
then | |
git diff-index --cached --quiet --ignore-submodules HEAD 2> /dev/null | |
(( $? && $? != 128 )) && echo "@ " | |
fi | |
} | |
function git_modified_files { | |
if [[ "git rev-parse --is-inside-work-tree &> /dev/null)" != 'true' ]] && git rev-parse --quiet --verify HEAD &> /dev/null | |
then | |
git diff --no-ext-diff --ignore-submodules --quiet --exit-code || echo "@ " | |
fi | |
} | |
function short_pwd { | |
echo $PWD | sed "s:${HOME}:~:" | sed "s:/\(.\)[^/]*:/\1:g" | sed "s:/[^/]*$:/$(basename $PWD):" | |
} | |
if [ `id -u` = 0 ]; then | |
COLOR="04;01;31m" | |
PATH_COLOR="01;31m" | |
else | |
COLOR="01;32m" | |
PATH_COLOR="01;34m" | |
fi | |
BOLD_RED="01;31m" | |
BOLD_GREEN="01;32m" | |
BOLD_BLUE="01;34m" | |
export PS1='\[\033[$COLOR\]\u@\h\[\033[00m\]:\[\033[01;$PATH_COLOR\]\W\[\033[00m\]\[\033[01;35m\]$(parse_git_branch)\[\033[00m\]\[\033[$BOLD_RED\]$(git_unadded_new)\[\033[00m\]\[\033[$BOLD_GREEN\]$(git_needs_commit)\[\033[00m\]\[\033[$BOLD_BLUE\]$(git_modified_files)\[\033[00m\]> ' | |
# vim: tabstop=4 shiftwidth=4 autoindent |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment