way better git prompt
This commit is contained in:
parent
9c3e2ef023
commit
2c4322e10b
1 changed files with 29 additions and 15 deletions
|
|
@ -7,23 +7,39 @@ shopt -s histappend
|
||||||
# update the values of LINES and COLUMNS.
|
# update the values of LINES and COLUMNS.
|
||||||
shopt -s checkwinsize
|
shopt -s checkwinsize
|
||||||
|
|
||||||
parse_git_dirty() {
|
|
||||||
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "(*)"
|
|
||||||
}
|
|
||||||
|
|
||||||
parse_git_stash() {
|
|
||||||
[[ $(git stash list 2> /dev/null | tail -n1) != "" ]] && echo "(^)"
|
|
||||||
}
|
|
||||||
|
|
||||||
parse_git_branch () {
|
|
||||||
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1/"
|
|
||||||
}
|
|
||||||
|
|
||||||
BLACK="\[\033[0;38m\]"
|
BLACK="\[\033[0;38m\]"
|
||||||
RED="\[\033[0;31m\]"
|
RED="\[\033[0;31m\]"
|
||||||
RED_BOLD="\[\033[01;31m\]"
|
RED_BOLD="\[\033[01;31m\]"
|
||||||
BLUE="\[\033[01;34m\]"
|
BLUE="\[\033[01;34m\]"
|
||||||
GREEN="\[\033[0;32m\]"
|
GREEN="\[\033[0;32m\]"
|
||||||
|
YELLOW="\[\033[0;33m\]"
|
||||||
|
|
||||||
|
parse_git_branch() {
|
||||||
|
|
||||||
|
git rev-parse --git-dir &> /dev/null
|
||||||
|
git_status="$(git status 2> /dev/null)"
|
||||||
|
branch_pattern="^# On branch ([^${IFS}]*)"
|
||||||
|
remote_pattern="# Your branch is (.*) of"
|
||||||
|
diverge_pattern="# Your branch and (.*) have diverged"
|
||||||
|
if [[ ! ${git_status} =~ "working directory clean" ]]; then
|
||||||
|
state="${RED}!"
|
||||||
|
fi
|
||||||
|
# add an else if or two here if you want to get more specific
|
||||||
|
if [[ ${git_status} =~ ${remote_pattern} ]]; then
|
||||||
|
if [[ ${BASH_REMATCH[1]} == "ahead" ]]; then
|
||||||
|
remote="${YELLOW}↑"
|
||||||
|
else
|
||||||
|
remote="${YELLOW}↓"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
if [[ ${git_status} =~ ${diverge_pattern} ]]; then
|
||||||
|
remote="${YELLOW}↕"
|
||||||
|
fi
|
||||||
|
if [[ ${git_status} =~ ${branch_pattern} ]]; then
|
||||||
|
branch=${BASH_REMATCH[1]}
|
||||||
|
echo " $RED(${branch})${remote}${state} "
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
export CLICOLOR=1
|
export CLICOLOR=1
|
||||||
export EDITOR=/usr/bin/mvim
|
export EDITOR=/usr/bin/mvim
|
||||||
|
|
@ -75,6 +91,4 @@ if [ -f /opt/local/etc/bash_completion.d/git ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# configure my multi-line prompt
|
# configure my multi-line prompt
|
||||||
export PS1="
|
export PS1="\n$BLACK[ \u@$RED\h $GREEN\w$RED$(parse_git_branch)$BLACK]\n> "
|
||||||
$BLACK[ \u@$RED\h $GREEN\w $RED_BOLD{ \$(parse_git_branch) \$(parse_git_dirty)\$(parse_git_stash) } $BLACK]
|
|
||||||
> "
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue