Created
February 1, 2014 14:51
-
-
Save dafyddcrosby/8753293 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
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 | |
COLOUR="04;01;31m" | |
PATH_COLOUR="01;31m" | |
else | |
COLOUR="01;32m" | |
PATH_COLOUR="01;34m" | |
fi | |
BOLD_RED="01;31m" | |
BOLD_GREEN="01;32m" | |
BOLD_BLUE="01;34m" | |
PS1='${debian_chroot:+($debian_chroot)}\[\033[$COLOUR\]\u@\h\[\033[00m\]:\[\033[01;$PATH_COLOUR\]$(short_pwd)\[\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\]> ' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment