Commit f558a460 authored by Marc Cornellà's avatar Marc Cornellà
Browse files

Merge pull request #4709 from mcornella/fix-local-vars-in-git-prompt

Put `local var` declaration in its own line in lib/git.zsh
parents 30ddf25f 08423849
...@@ -75,7 +75,8 @@ function git_current_branch() { ...@@ -75,7 +75,8 @@ function git_current_branch() {
# Gets the number of commits ahead from remote # Gets the number of commits ahead from remote
function git_commits_ahead() { function git_commits_ahead() {
if $(echo "$(command git log @{upstream}..HEAD 2> /dev/null)" | grep '^commit' &> /dev/null); then if $(echo "$(command git log @{upstream}..HEAD 2> /dev/null)" | grep '^commit' &> /dev/null); then
local COMMITS=$(command git log @{upstream}..HEAD | grep '^commit' | wc -l | tr -d ' ') local COMMITS
COMMITS=$(command git log @{upstream}..HEAD | grep '^commit' | wc -l | tr -d ' ')
echo "$ZSH_THEME_GIT_COMMITS_AHEAD_PREFIX$COMMITS$ZSH_THEME_GIT_COMMITS_AHEAD_SUFFIX" echo "$ZSH_THEME_GIT_COMMITS_AHEAD_PREFIX$COMMITS$ZSH_THEME_GIT_COMMITS_AHEAD_SUFFIX"
fi fi
} }
...@@ -105,12 +106,14 @@ function git_prompt_remote() { ...@@ -105,12 +106,14 @@ function git_prompt_remote() {
# Formats prompt string for current git commit short SHA # Formats prompt string for current git commit short SHA
function git_prompt_short_sha() { function git_prompt_short_sha() {
local SHA=$(command git rev-parse --short HEAD 2> /dev/null) && echo "$ZSH_THEME_GIT_PROMPT_SHA_BEFORE$SHA$ZSH_THEME_GIT_PROMPT_SHA_AFTER" local SHA
SHA=$(command git rev-parse --short HEAD 2> /dev/null) && echo "$ZSH_THEME_GIT_PROMPT_SHA_BEFORE$SHA$ZSH_THEME_GIT_PROMPT_SHA_AFTER"
} }
# Formats prompt string for current git commit long SHA # Formats prompt string for current git commit long SHA
function git_prompt_long_sha() { function git_prompt_long_sha() {
local SHA=$(command git rev-parse HEAD 2> /dev/null) && echo "$ZSH_THEME_GIT_PROMPT_SHA_BEFORE$SHA$ZSH_THEME_GIT_PROMPT_SHA_AFTER" local SHA
SHA=$(command git rev-parse HEAD 2> /dev/null) && echo "$ZSH_THEME_GIT_PROMPT_SHA_BEFORE$SHA$ZSH_THEME_GIT_PROMPT_SHA_AFTER"
} }
# Get the status of the working tree # Get the status of the working tree
...@@ -165,11 +168,10 @@ function git_prompt_status() { ...@@ -165,11 +168,10 @@ function git_prompt_status() {
# Outputs -1, 0, or 1 if the installed version is less than, equal to, or # Outputs -1, 0, or 1 if the installed version is less than, equal to, or
# greater than the input version, respectively. # greater than the input version, respectively.
function git_compare_version() { function git_compare_version() {
local INPUT_GIT_VERSION=$1; local INPUT_GIT_VERSION INSTALLED_GIT_VERSION
local INSTALLED_GIT_VERSION INPUT_GIT_VERSION=(${(s/./)1})
INPUT_GIT_VERSION=(${(s/./)INPUT_GIT_VERSION}); INSTALLED_GIT_VERSION=($(command git --version 2>/dev/null))
INSTALLED_GIT_VERSION=($(command git --version 2>/dev/null)); INSTALLED_GIT_VERSION=(${(s/./)INSTALLED_GIT_VERSION[3]})
INSTALLED_GIT_VERSION=(${(s/./)INSTALLED_GIT_VERSION[3]});
for i in {1..3}; do for i in {1..3}; do
if [[ $INSTALLED_GIT_VERSION[$i] -gt $INPUT_GIT_VERSION[$i] ]]; then if [[ $INSTALLED_GIT_VERSION[$i] -gt $INPUT_GIT_VERSION[$i] ]]; then
...@@ -187,4 +189,4 @@ function git_compare_version() { ...@@ -187,4 +189,4 @@ function git_compare_version() {
# This is unlikely to change so make it all statically assigned # This is unlikely to change so make it all statically assigned
POST_1_7_2_GIT=$(git_compare_version "1.7.2") POST_1_7_2_GIT=$(git_compare_version "1.7.2")
# Clean up the namespace slightly by removing the checker function # Clean up the namespace slightly by removing the checker function
unset -f git_compare_version unfunction git_compare_version
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment