2015-10-23 22:05:15 +00:00
|
|
|
# vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8
|
|
|
|
################################################################
|
|
|
|
# vcs
|
|
|
|
# This file holds supplemental VCS functions
|
|
|
|
# for the powerlevel9k-ZSH-theme
|
|
|
|
# https://github.com/bhilburn/powerlevel9k
|
|
|
|
################################################################
|
|
|
|
|
2016-02-18 01:09:54 +00:00
|
|
|
set_default POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY true
|
2015-10-23 22:05:15 +00:00
|
|
|
function +vi-git-untracked() {
|
2016-02-18 01:09:54 +00:00
|
|
|
# TODO: check git >= 1.7.2 - see function git_compare_version()
|
2016-02-08 16:14:28 +00:00
|
|
|
local FLAGS
|
|
|
|
FLAGS=('--porcelain')
|
2016-02-18 01:09:54 +00:00
|
|
|
|
|
|
|
if [[ "$POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY" == "false" ]]; then
|
|
|
|
FLAGS+='--ignore-submodules=dirty'
|
|
|
|
fi
|
|
|
|
|
2015-10-23 22:05:15 +00:00
|
|
|
if [[ $(git rev-parse --is-inside-work-tree 2> /dev/null) == 'true' && \
|
2016-02-26 14:23:02 +00:00
|
|
|
-n $(git status ${FLAGS} | grep -E '^\?\?' 2> /dev/null | tail -n1) ]]; then
|
2016-02-10 20:57:06 +00:00
|
|
|
hook_com[unstaged]+=" $(print_icon 'VCS_UNTRACKED_ICON')"
|
2016-01-26 22:20:20 +00:00
|
|
|
VCS_WORKDIR_HALF_DIRTY=true
|
|
|
|
else
|
|
|
|
VCS_WORKDIR_HALF_DIRTY=false
|
2015-10-23 22:05:15 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function +vi-git-aheadbehind() {
|
|
|
|
local ahead behind branch_name
|
|
|
|
local -a gitstatus
|
|
|
|
|
|
|
|
branch_name=$(git symbolic-ref --short HEAD 2>/dev/null)
|
|
|
|
|
|
|
|
# for git prior to 1.7
|
|
|
|
# ahead=$(git rev-list origin/${branch_name}..HEAD | wc -l)
|
|
|
|
ahead=$(git rev-list "${branch_name}"@{upstream}..HEAD 2>/dev/null | wc -l)
|
2016-02-10 20:57:06 +00:00
|
|
|
(( ahead )) && gitstatus+=( " $(print_icon 'VCS_OUTGOING_CHANGES_ICON')${ahead// /}" )
|
2015-10-23 22:05:15 +00:00
|
|
|
|
|
|
|
# for git prior to 1.7
|
|
|
|
# behind=$(git rev-list HEAD..origin/${branch_name} | wc -l)
|
|
|
|
behind=$(git rev-list HEAD.."${branch_name}"@{upstream} 2>/dev/null | wc -l)
|
2016-02-10 20:57:06 +00:00
|
|
|
(( behind )) && gitstatus+=( " $(print_icon 'VCS_INCOMING_CHANGES_ICON')${behind// /}" )
|
2015-10-23 22:05:15 +00:00
|
|
|
|
|
|
|
hook_com[misc]+=${(j::)gitstatus}
|
|
|
|
}
|
|
|
|
|
|
|
|
function +vi-git-remotebranch() {
|
|
|
|
local remote branch_name
|
|
|
|
|
|
|
|
# Are we on a remote-tracking branch?
|
|
|
|
remote=${$(git rev-parse --verify HEAD@{upstream} --symbolic-full-name 2>/dev/null)/refs\/(remotes|heads)\/}
|
|
|
|
branch_name=$(git symbolic-ref --short HEAD 2>/dev/null)
|
|
|
|
|
2016-02-10 20:57:06 +00:00
|
|
|
hook_com[branch]="$(print_icon 'VCS_BRANCH_ICON')${hook_com[branch]}"
|
2015-10-23 22:05:15 +00:00
|
|
|
# Always show the remote
|
|
|
|
#if [[ -n ${remote} ]] ; then
|
|
|
|
# Only show the remote if it differs from the local
|
|
|
|
if [[ -n ${remote} ]] && [[ "${remote#*/}" != "${branch_name}" ]] ; then
|
2016-02-10 20:57:06 +00:00
|
|
|
hook_com[branch]+="$(print_icon 'VCS_REMOTE_BRANCH_ICON')${remote// /}"
|
2015-10-23 22:05:15 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-07-13 00:28:01 +00:00
|
|
|
set_default POWERLEVEL9K_VCS_HIDE_TAGS false
|
2015-10-23 22:05:15 +00:00
|
|
|
function +vi-git-tagname() {
|
2016-09-26 17:54:43 +00:00
|
|
|
if [[ "$POWERLEVEL9K_VCS_HIDE_TAGS" == "false" ]]; then
|
2016-07-13 00:28:01 +00:00
|
|
|
# If we are on a tag, append the tagname to the current branch string.
|
|
|
|
local tag
|
|
|
|
tag=$(git describe --tags --exact-match HEAD 2>/dev/null)
|
2015-10-23 22:05:15 +00:00
|
|
|
|
2016-07-13 00:28:01 +00:00
|
|
|
if [[ -n "${tag}" ]] ; then
|
|
|
|
# There is a tag that points to our current commit. Need to determine if we
|
|
|
|
# are also on a branch, or are in a DETACHED_HEAD state.
|
|
|
|
if [[ -z $(git symbolic-ref HEAD 2>/dev/null) ]]; then
|
|
|
|
# DETACHED_HEAD state. We want to append the tag name to the commit hash
|
|
|
|
# and print it. Unfortunately, `vcs_info` blows away the hash when a tag
|
|
|
|
# exists, so we have to manually retrieve it and clobber the branch
|
|
|
|
# string.
|
|
|
|
local revision
|
|
|
|
revision=$(git rev-list -n 1 --abbrev-commit --abbrev=${POWERLEVEL9K_VCS_INTERNAL_HASH_LENGTH} HEAD)
|
|
|
|
hook_com[branch]="$(print_icon 'VCS_BRANCH_ICON')${revision} $(print_icon 'VCS_TAG_ICON')${tag}"
|
|
|
|
else
|
|
|
|
# We are on both a tag and a branch; print both by appending the tag name.
|
|
|
|
hook_com[branch]+=" $(print_icon 'VCS_TAG_ICON')${tag}"
|
|
|
|
fi
|
|
|
|
fi
|
2016-04-11 19:37:28 +00:00
|
|
|
fi
|
2015-10-23 22:05:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Show count of stashed changes
|
|
|
|
# Port from https://github.com/whiteinge/dotfiles/blob/5dfd08d30f7f2749cfc60bc55564c6ea239624d9/.zsh_shouse_prompt#L268
|
|
|
|
function +vi-git-stash() {
|
|
|
|
local -a stashes
|
|
|
|
|
|
|
|
if [[ -s $(git rev-parse --git-dir)/refs/stash ]] ; then
|
|
|
|
stashes=$(git stash list 2>/dev/null | wc -l)
|
2016-02-10 20:57:06 +00:00
|
|
|
hook_com[misc]+=" $(print_icon 'VCS_STASH_ICON')${stashes// /}"
|
2015-10-23 22:05:15 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function +vi-hg-bookmarks() {
|
|
|
|
if [[ -n "${hgbmarks[@]}" ]]; then
|
2016-02-10 20:57:06 +00:00
|
|
|
hook_com[hg-bookmark-string]=" $(print_icon 'VCS_BOOKMARK_ICON')${hgbmarks[@]}"
|
2015-10-23 22:05:15 +00:00
|
|
|
|
|
|
|
# To signal that we want to use the sting we just generated, set the special
|
|
|
|
# variable `ret' to something other than the default zero:
|
|
|
|
ret=1
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function +vi-vcs-detect-changes() {
|
2015-12-17 23:47:37 +00:00
|
|
|
if [[ "${hook_com[vcs]}" == "git" ]]; then
|
2016-12-15 12:08:21 +00:00
|
|
|
|
2017-02-24 09:12:35 +00:00
|
|
|
local remote=$(git ls-remote --get-url 2> /dev/null)
|
2016-12-15 12:08:21 +00:00
|
|
|
if [[ "$remote" =~ "github" ]] then
|
|
|
|
vcs_visual_identifier='VCS_GIT_GITHUB_ICON'
|
|
|
|
elif [[ "$remote" =~ "bitbucket" ]] then
|
|
|
|
vcs_visual_identifier='VCS_GIT_BITBUCKET_ICON'
|
2017-11-30 12:03:54 +00:00
|
|
|
elif [[ "$remote" =~ "stash" ]] then
|
|
|
|
vcs_visual_identifier='VCS_GIT_BITBUCKET_ICON'
|
2016-12-15 12:08:21 +00:00
|
|
|
elif [[ "$remote" =~ "gitlab" ]] then
|
|
|
|
vcs_visual_identifier='VCS_GIT_GITLAB_ICON'
|
|
|
|
else
|
|
|
|
vcs_visual_identifier='VCS_GIT_ICON'
|
|
|
|
fi
|
|
|
|
|
2015-12-17 23:47:37 +00:00
|
|
|
elif [[ "${hook_com[vcs]}" == "hg" ]]; then
|
|
|
|
vcs_visual_identifier='VCS_HG_ICON'
|
2016-08-31 00:29:36 +00:00
|
|
|
elif [[ "${hook_com[vcs]}" == "svn" ]]; then
|
|
|
|
vcs_visual_identifier='VCS_SVN_ICON'
|
2015-12-17 23:47:37 +00:00
|
|
|
fi
|
|
|
|
|
2015-10-23 22:05:15 +00:00
|
|
|
if [[ -n "${hook_com[staged]}" ]] || [[ -n "${hook_com[unstaged]}" ]]; then
|
|
|
|
VCS_WORKDIR_DIRTY=true
|
|
|
|
else
|
|
|
|
VCS_WORKDIR_DIRTY=false
|
|
|
|
fi
|
|
|
|
}
|
2016-08-25 21:13:15 +00:00
|
|
|
|
|
|
|
function +vi-svn-detect-changes() {
|
2016-10-19 13:35:23 +00:00
|
|
|
local svn_status="$(svn status)"
|
2016-08-25 21:13:15 +00:00
|
|
|
if [[ -n "$(echo "$svn_status" | grep \^\?)" ]]; then
|
2016-08-31 00:29:36 +00:00
|
|
|
hook_com[unstaged]+=" $(print_icon 'VCS_UNTRACKED_ICON')"
|
2016-08-25 21:13:15 +00:00
|
|
|
VCS_WORKDIR_HALF_DIRTY=true
|
2016-08-25 21:51:16 +00:00
|
|
|
fi
|
2016-08-31 00:29:36 +00:00
|
|
|
if [[ -n "$(echo "$svn_status" | grep \^\M)" ]]; then
|
|
|
|
hook_com[unstaged]+=" $(print_icon 'VCS_UNSTAGED_ICON')"
|
|
|
|
VCS_WORKDIR_DIRTY=true
|
|
|
|
fi
|
2016-08-25 21:51:16 +00:00
|
|
|
if [[ -n "$(echo "$svn_status" | grep \^\A)" ]]; then
|
2016-08-31 00:29:36 +00:00
|
|
|
hook_com[staged]+=" $(print_icon 'VCS_STAGED_ICON')"
|
2016-08-25 21:31:00 +00:00
|
|
|
VCS_WORKDIR_DIRTY=true
|
2016-08-25 21:13:15 +00:00
|
|
|
fi
|
|
|
|
}
|