Refactors git.zsh.

This commit is contained in:
LFDM 2014-01-05 05:08:11 +01:00
commit cd08a2ce90

View file

@ -10,28 +10,18 @@ function git_prompt_info() {
# Checks if working tree is dirty
parse_git_dirty() {
local SUBMODULE_SYNTAX=''
local GIT_STATUS=''
local CLEAN_MESSAGE='nothing to commit (working directory clean)'
if [[ "$(command git config --get oh-my-zsh.hide-status)" != "1" ]]; then
if [[ $POST_1_7_2_GIT -gt 0 ]]; then
SUBMODULE_SYNTAX="--ignore-submodules=dirty"
fi
if [[ "$DISABLE_UNTRACKED_FILES_DIRTY" == "true" ]]; then
GIT_STATUS=$(command git status -s ${SUBMODULE_SYNTAX} -uno 2> /dev/null | tail -n1)
else
GIT_STATUS=$(command git status -s ${SUBMODULE_SYNTAX} 2> /dev/null | tail -n1)
fi
if [[ -n $GIT_STATUS ]]; then
echo "$ZSH_THEME_GIT_PROMPT_DIRTY"
else
echo "$ZSH_THEME_GIT_PROMPT_CLEAN"
fi
[[ GIT_HIDE == 'true' ]] && return
if git_is_clean; then
echo $ZSH_THEME_GIT_PROMPT_CLEAN
else
echo "$ZSH_THEME_GIT_PROMPT_CLEAN"
echo $ZSH_THEME_GIT_PROMPT_DIRTY
fi
}
git_is_clean() {
[[ $(command git status -s $GIT_STATUS_OPTIONS 2> /dev/null) == '' ]]
}
# get the difference between the local and remote branches
git_remote_status() {
remote=${$(command git rev-parse --verify ${hook_com[branch]}@{upstream} --symbolic-full-name 2>/dev/null)/refs\/remotes\/}
@ -119,25 +109,39 @@ git_prompt_status() {
#compare the provided version of git to the version installed and on path
#prints 1 if installed version > input version
#prints -1 otherwise
function git_compare_version() {
local INPUT_GIT_VERSION=$1;
local INSTALLED_GIT_VERSION
INPUT_GIT_VERSION=(${(s/./)INPUT_GIT_VERSION});
INSTALLED_GIT_VERSION=($(command git --version 2>/dev/null));
INSTALLED_GIT_VERSION=(${(s/./)INSTALLED_GIT_VERSION[3]});
function is_recent_git_version() {
local not_recent_git
local installed_git
not_recent_git=(1 7 2);
installed_git=($(command git --version 2>/dev/null));
installed_git=(${(s/./)installed_git[3]});
for i in {1..3}; do
if [[ $INSTALLED_GIT_VERSION[$i] -gt $INPUT_GIT_VERSION[$i] ]]; then
echo 1
if [[ $installed_git[$i] -gt $not_recent_git[$i] ]]; then
return 0
fi
done
echo -1
return 1
}
function set_git_status_options() {
GIT_STATUS_OPTIONS=''
if is_recent_git_version; then
GIT_STATUS_OPTIONS+='--ignore-submodules=dirty'
fi
if [[ $DISABLE_UNTRACKED_FILES_DIRTY == 'true' ]]; then
GIT_STATUS_OPTIONS+=' -uno'
fi
}
function check_git_show_status() {
if [[ $(command git config --get oh-my-zsh.hide-status) != "1" ]]; then
# no need to set options if status is hidden anyway
set_git_status_options
else
GIT_HIDE='true'
fi
}
#this is unlikely to change so make it all statically assigned
POST_1_7_2_GIT=$(git_compare_version "1.7.2")
#clean up the namespace slightly by removing the checker function
unset -f git_compare_version
check_git_show_status