Skip to content

Instantly share code, notes, and snippets.

@lamont-granquist
Last active September 17, 2017 21:30
Show Gist options
  • Save lamont-granquist/587ced18dc502d157944ed986c1ea1f6 to your computer and use it in GitHub Desktop.
Save lamont-granquist/587ced18dc502d157944ed986c1ea1f6 to your computer and use it in GitHub Desktop.
% source ~/.zsh-backup/functions/update_current_git_vars
+-zsh:7> source /Users/lamont/.zsh-backup/functions/update_current_git_vars
+/Users/lamont/.zsh-backup/functions/update_current_git_vars:1> unset __CURRENT_GIT_BRANCH
+/Users/lamont/.zsh-backup/functions/update_current_git_vars:2> unset __CURRENT_GIT_BRANCH_STATUS
+/Users/lamont/.zsh-backup/functions/update_current_git_vars:3> unset __CURRENT_GIT_BRANCH_IS_DIRTY
+/Users/lamont/.zsh-backup/functions/update_current_git_vars:4> unset __CURRENT_GIT_PARENT
+/Users/lamont/.zsh-backup/functions/update_current_git_vars:5> unset __CURRENT_GIT_BASENAME
+/Users/lamont/.zsh-backup/functions/update_current_git_vars:7> set -x
+/Users/lamont/.zsh-backup/functions/update_current_git_vars:9> hub status
+/Users/lamont/.zsh-backup/functions/update_current_git_vars:9> local 'st=HEAD detached at 2017092006-Cesàro
nothing to commit, working tree clean'
+/Users/lamont/.zsh-backup/functions/update_current_git_vars:10> [[ -n 'HEAD detached at 2017092006-Cesàro
nothing to commit, working tree clean' ]]
+/Users/lamont/.zsh-backup/functions/update_current_git_vars:11> local -a arr
+/Users/lamont/.zsh-backup/functions/update_current_git_vars:12> arr=( 'HEAD detached at 2017092006-Cesàro' 'nothing to commit, working tree clean' )
+/Users/lamont/.zsh-backup/functions/update_current_git_vars:14> [[ $arr[1] -regex-match 'Not currently on any branch.' ]]
+/Users/lamont/.zsh-backup/functions/update_current_git_vars:17> __CURRENT_GIT_BRANCH=2017092006-Cesàro
+/Users/lamont/.zsh-backup/functions/update_current_git_vars:20> [[ $arr[2] -regex-match 'Your branch is' ]]
unset __CURRENT_GIT_BRANCH
unset __CURRENT_GIT_BRANCH_STATUS
unset __CURRENT_GIT_BRANCH_IS_DIRTY
unset __CURRENT_GIT_PARENT
unset __CURRENT_GIT_BASENAME
local st="$(git status 2>/dev/null)"
if [[ -n "$st" ]]; then
local -a arr
arr=(${(f)st})
if [[ $arr[1] =~ 'Not currently on any branch.' ]]; then
__CURRENT_GIT_BRANCH='no-branch'
else
__CURRENT_GIT_BRANCH="${arr[1][(w)4]}";
fi
if [[ $arr[2] =~ 'Your branch is' ]]; then
if [[ $arr[2] =~ 'ahead' ]]; then
__CURRENT_GIT_BRANCH_STATUS='ahead'
elif [[ $arr[2] =~ 'diverged' ]]; then
__CURRENT_GIT_BRANCH_STATUS='diverged'
elif [[ $arr[2] =~ 'up-to-date' ]]; then
unset __CURRENT_GIT_BRANCH_STATUS
else
__CURRENT_GIT_BRANCH_STATUS='behind'
fi
fi
if [[ ! $st =~ 'nothing to commit' ]]; then
__CURRENT_GIT_BRANCH_IS_DIRTY='1'
fi
__CURRENT_GIT_PARENT=$(git rev-parse --show-toplevel)
__CURRENT_GIT_BASENAME=$(basename $__CURRENT_GIT_PARENT)
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment