mirror of
https://github.com/dcarrillo/prezto.git
synced 2025-06-15 08:01:43 +00:00
[#23] Rename plugins to modules
This commit is contained in:
1
modules/git/.gitignore
vendored
Normal file
1
modules/git/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
_git
|
254
modules/git/alias.zsh
Normal file
254
modules/git/alias.zsh
Normal file
@ -0,0 +1,254 @@
|
||||
#
|
||||
# Defines Git aliases.
|
||||
#
|
||||
# Authors:
|
||||
# Sorin Ionescu <sorin.ionescu@gmail.com>
|
||||
#
|
||||
|
||||
# Git
|
||||
alias g='git'
|
||||
compdef g=git
|
||||
|
||||
# Branch (b)
|
||||
alias gb='git branch'
|
||||
compdef _git gb=git-branch
|
||||
alias gbc='git checkout -b'
|
||||
compdef _git gbc=git-checkout
|
||||
alias gbl='git branch -v'
|
||||
compdef _git gbl=git-branch
|
||||
alias gbL='git branch -av'
|
||||
compdef _git gbL=git-branch
|
||||
alias gbx='git branch -d'
|
||||
compdef _git gbx=git-branch
|
||||
alias gbX='git branch -D'
|
||||
compdef _git gbX=git-branch
|
||||
alias gbm='git branch -m'
|
||||
compdef _git gbm=git-branch
|
||||
alias gbM='git branch -M'
|
||||
compdef _git gbM=git-branch
|
||||
|
||||
# Commit (c)
|
||||
alias gc='git commit'
|
||||
compdef _git gc=git-commit
|
||||
alias gca='git commit --all'
|
||||
compdef _git gca=git-commit
|
||||
alias gcm='git commit --message'
|
||||
compdef _git gcm=git-commit
|
||||
alias gco='git checkout'
|
||||
compdef _git gco=git-checkout
|
||||
alias gcO='git checkout HEAD --'
|
||||
compdef _git gcO=git-checkout
|
||||
alias gcf='git commit --amend --reuse-message HEAD'
|
||||
compdef _git gcf=git-commit
|
||||
alias gcp='git cherry-pick --ff'
|
||||
compdef _git gcp=git-cherry-pick
|
||||
alias gcP='git cherry-pick --no-commit'
|
||||
compdef _git gcP=git-cherry-pick
|
||||
alias gcr='git revert'
|
||||
compdef _git gcr=git-revert
|
||||
alias gcR='git reset "HEAD^"'
|
||||
compdef _git gcR=git-reset
|
||||
alias gcs='git show'
|
||||
compdef _git gcs=git-show
|
||||
alias gcv='git fsck | awk '\''/dangling commit/ {print $3}'\'' | git show --format="SHA1: %C(green)%h%C(reset) %f" --stdin | awk '\''/SHA1/ {sub("SHA1: ", ""); print}'\'''
|
||||
|
||||
# Data (d)
|
||||
alias gd='git ls-files'
|
||||
compdef _git gd=git-ls-files
|
||||
alias gdc='git ls-files --cached'
|
||||
compdef _git gdc=git-ls-files
|
||||
alias gdx='git ls-files --deleted'
|
||||
compdef _git gdx=git-ls-files
|
||||
alias gdm='git ls-files --modified'
|
||||
compdef _git gdm=git-ls-files
|
||||
alias gdu='git ls-files --other --exclude-standard'
|
||||
compdef _git gdu=git-ls-files
|
||||
alias gdk='git ls-files --killed'
|
||||
compdef _git gdk=git-ls-files
|
||||
alias gdi='git status --porcelain --short --ignored | sed -n "s/^!! //p"'
|
||||
|
||||
# Fetch (f)
|
||||
alias gf='git fetch'
|
||||
compdef _git gf=git-fetch
|
||||
alias gfc='git clone'
|
||||
compdef _git gfc=git-clone
|
||||
alias gfm='git pull'
|
||||
compdef _git gfm=git-pull
|
||||
alias gfr='git pull --rebase'
|
||||
compdef _git gfr=git-pull
|
||||
|
||||
# Index (i)
|
||||
alias gia='git add'
|
||||
compdef _git gia=git-add
|
||||
alias giA='git add --patch'
|
||||
compdef _git giA=git-add
|
||||
alias giu='git add --update'
|
||||
compdef _git giu=git-add
|
||||
alias gid='git diff --no-ext-diff --cached'
|
||||
compdef _git gid=git-diff
|
||||
alias giD='git diff --no-ext-diff --cached --word-diff'
|
||||
compdef _git giD=git-diff
|
||||
alias gir='git reset --mixed'
|
||||
compdef _git gir=git-reset
|
||||
alias giR='git reset --keep'
|
||||
compdef _git giR=git-reset
|
||||
alias gix='git rm -r --cached'
|
||||
compdef _git gix=git-rm
|
||||
alias giX='git rm -rf --cached'
|
||||
compdef _git giX=git-rm
|
||||
alias gig='git grep --cached'
|
||||
compdef _git gig=git-grep
|
||||
|
||||
# Konflict (k)
|
||||
alias gkl='git status | sed -n "s/^.*both [a-z]*ed: *//p"'
|
||||
alias gka='git add $(gkl)'
|
||||
compdef _git gka=git-add
|
||||
alias gke='git mergetool $(gkl)'
|
||||
alias gko='git checkout --ours --'
|
||||
compdef _git gko=git-checkout
|
||||
alias gkO='gko $(gkl)'
|
||||
alias gkt='git checkout --theirs --'
|
||||
compdef _git gkt=git-checkout
|
||||
alias gkT='gkt $(gkl)'
|
||||
|
||||
# Log (l)
|
||||
git_log_format_medium='--pretty=format:%C(bold)Commit:%C(reset) %C(green)%H%C(red)%d%n%C(bold)Author:%C(reset) %C(cyan)%an <%ae>%n%C(bold)Date:%C(reset) %C(blue)%ai (%ar)%C(reset)%n%+B'
|
||||
git_log_format_oneline='--pretty=format:%C(green)%h%C(reset) %s%n'
|
||||
git_log_format_brief='--pretty=format:%C(green)%h%C(reset) %s%n%C(blue)(%ar by %an)%C(red)%d%C(reset)%n'
|
||||
|
||||
alias gl='git log --topo-order ${git_log_format_medium}'
|
||||
compdef _git gl=git-log
|
||||
alias gls='git log --topo-order --stat ${git_log_format_medium}'
|
||||
compdef _git gls=git-log
|
||||
alias gld='git log --topo-order --stat --patch --full-diff ${git_log_format_medium}'
|
||||
compdef _git gld=git-log
|
||||
alias glo='git log --topo-order ${git_log_format_oneline}'
|
||||
compdef _git glo=git-log
|
||||
alias glg='git log --topo-order --all --graph ${git_log_format_oneline}'
|
||||
compdef _git glg=git-log
|
||||
alias glb='git log --topo-order ${git_log_format_brief}'
|
||||
compdef _git glb=git-log
|
||||
alias glc='git shortlog --summary --numbered'
|
||||
compdef _git glc=git-shortlog
|
||||
|
||||
# Merge (m)
|
||||
alias gm='git merge'
|
||||
compdef _git gm=git-merge
|
||||
alias gmC='git merge --no-commit'
|
||||
compdef _git gmC=git-merge
|
||||
alias gmF='git merge --no-ff'
|
||||
compdef _git gmF=git-merge
|
||||
alias gma='git merge --abort'
|
||||
compdef _git gma=git-merge
|
||||
alias gmt='git mergetool'
|
||||
compdef _git gmt=git-mergetool
|
||||
|
||||
# Push (p)
|
||||
alias gp='git push'
|
||||
compdef _git gp=git-push
|
||||
alias gpf='git push --force'
|
||||
compdef _git gpf=git-push
|
||||
alias gpa='git push --all'
|
||||
compdef _git gpa=git-push
|
||||
alias gpA='git push --all && git push --tags'
|
||||
compdef _git gpA=git-push
|
||||
alias gpt='git push --tags'
|
||||
compdef _git gpt=git-push
|
||||
alias gpc='git push --set-upstream origin "$(git-current-branch)"'
|
||||
compdef _git gpc=git-push
|
||||
alias gpp='git pull origin "$(git-current-branch)" && git push origin "$(git-branch)"'
|
||||
|
||||
# Rebase (r)
|
||||
alias gr='git rebase'
|
||||
compdef _git gr=git-rebase
|
||||
alias gra='git rebase --abort'
|
||||
compdef _git gra=git-rebase
|
||||
alias grc='git rebase --continue'
|
||||
compdef _git grc=git-rebase
|
||||
alias gri='git rebase --interactive'
|
||||
compdef _git gri=git-rebase
|
||||
alias grs='git rebase --skip'
|
||||
compdef _git grs=git-rebase
|
||||
|
||||
# Remote (R)
|
||||
alias gR='git remote'
|
||||
compdef _git gh=git-remote
|
||||
alias gRl='git remote --verbose'
|
||||
compdef _git gRl=git-remote
|
||||
alias gRa='git remote add'
|
||||
compdef _git gRa=git-remote
|
||||
alias gRx='git remote rm'
|
||||
compdef _git gRx=git-remote
|
||||
alias gRm='git remote rename'
|
||||
compdef _git gRm=git-remote
|
||||
alias gRu='git remote update'
|
||||
compdef _git gRu=git-remote
|
||||
alias gRc='git remote prune'
|
||||
compdef _git gRc=git-remote
|
||||
alias gRs='git remote show'
|
||||
compdef _git gRs=git-remote
|
||||
alias gRb='git-hub'
|
||||
compdef _git-hub gRb=git-hub
|
||||
|
||||
# Stash (s)
|
||||
alias gs='git stash'
|
||||
compdef _git gs=git-stash
|
||||
alias gsa='git stash apply'
|
||||
compdef _git gsa=git-stash
|
||||
alias gsc='git stash clear'
|
||||
compdef _git gsc=git-stash
|
||||
alias gsx='git stash drop'
|
||||
compdef _git gsx=git-stash
|
||||
alias gsl='git stash list'
|
||||
compdef _git gsl=git-stash
|
||||
alias gsL='git stash show --patch --stat'
|
||||
compdef _git gsL=git-stash
|
||||
alias gsp='git stash pop'
|
||||
compdef _git gsp=git-stash
|
||||
alias gss='git stash save --include-untracked'
|
||||
compdef _git gss=git-stash
|
||||
alias gsS='git stash save --patch --no-keep-index'
|
||||
compdef _git gsS=git-stash
|
||||
|
||||
# Submodule (S)
|
||||
alias gS='git submodule'
|
||||
compdef _git gS=git-submodule
|
||||
alias gSa='git submodule add'
|
||||
compdef _git gSa=git-submodule
|
||||
alias gSf='git submodule foreach'
|
||||
compdef _git gSf=git-submodule
|
||||
alias gSi='git submodule init'
|
||||
compdef _git gSi=git-submodule
|
||||
alias gSl='git submodule status'
|
||||
compdef _git gSl=git-submodule
|
||||
alias gSs='git submodule sync'
|
||||
compdef _git gSs=git-submodule
|
||||
alias gSu='git submodule update'
|
||||
compdef _git gSu=git-submodule
|
||||
alias gSU='git submodule update --init --recursive'
|
||||
compdef _git gSU=git-submdoule
|
||||
|
||||
# Working Copy (w)
|
||||
alias gws='git status --short'
|
||||
compdef _git gws=git-status
|
||||
alias gwS='git status'
|
||||
compdef _git gwS=git-status
|
||||
alias gwd='git diff --no-ext-diff'
|
||||
compdef _git gwd=git-diff
|
||||
alias gwD='git diff --no-ext-diff --word-diff'
|
||||
compdef _git gwD=git-diff
|
||||
alias gwr='git reset --soft'
|
||||
compdef _git gwr=git-reset
|
||||
alias gwR='git reset --hard'
|
||||
compdef _git gwR=git-reset
|
||||
alias gwc='git clean -n'
|
||||
compdef _git gwc=git-clean
|
||||
alias gwC='git clean -f'
|
||||
compdef _git gwC=git-clean
|
||||
alias gwx='git rm -r'
|
||||
compdef _git gwx=git-rm
|
||||
alias gwX='git rm -rf'
|
||||
compdef _git gwX=git-rm
|
||||
alias gwg='git grep'
|
||||
compdef _git gwg=git-grep
|
||||
|
44
modules/git/completions/_git-hub
Normal file
44
modules/git/completions/_git-hub
Normal file
@ -0,0 +1,44 @@
|
||||
#compdef git-hub
|
||||
#autoload
|
||||
|
||||
#
|
||||
# Completes git-hub.
|
||||
#
|
||||
# Authors:
|
||||
# Sorin Ionescu <sorin.ionescu@gmail.com>
|
||||
#
|
||||
|
||||
local state remotes remote branches files ret=1
|
||||
|
||||
_arguments -C -s -S \
|
||||
'1::args:->remote' \
|
||||
'2::args:->branch' \
|
||||
'3::args:->file' && ret=0
|
||||
|
||||
case "$state" in
|
||||
(remote)
|
||||
remotes=($(
|
||||
git config -l \
|
||||
| grep 'remote\.[^.]*\.url' \
|
||||
| cut -d'.' -f2))
|
||||
_describe -t branch 'remotes' remotes && ret=0
|
||||
;;
|
||||
(branch)
|
||||
remote="$words[(($CURRENT - 1))]"
|
||||
branches=($(
|
||||
git branch -r \
|
||||
| grep "${remote}/" \
|
||||
| sed \
|
||||
-e "/${remote}\/HEAD -> ${remote}/d" \
|
||||
-e "s/^[[:space:]]*${remote}\///g"
|
||||
))
|
||||
_describe -t branch 'branches' branches && ret=0
|
||||
;;
|
||||
(file)
|
||||
files=(${(0)"$(_call_program files git ls-files -z --exclude-standard 2>/dev/null)"})
|
||||
_wanted file expl 'file' _multi_parts - / files && ret=0
|
||||
;;
|
||||
esac
|
||||
|
||||
return $ret
|
||||
|
12
modules/git/completions/_git-hub-short-url
Normal file
12
modules/git/completions/_git-hub-short-url
Normal file
@ -0,0 +1,12 @@
|
||||
#compdef git-hub-short-url
|
||||
#autoload
|
||||
|
||||
#
|
||||
# Completes git-hub-short-url.
|
||||
#
|
||||
# Authors:
|
||||
# Sorin Ionescu <sorin.ionescu@gmail.com>
|
||||
#
|
||||
|
||||
_arguments '1:url:' && return 0
|
||||
|
15
modules/git/completions/_git-info
Normal file
15
modules/git/completions/_git-info
Normal file
@ -0,0 +1,15 @@
|
||||
#compdef git-info
|
||||
#autoload
|
||||
|
||||
#
|
||||
# Completes git-info.
|
||||
#
|
||||
# Authors:
|
||||
# Sorin Ionescu <sorin.ionescu@gmail.com>
|
||||
#
|
||||
|
||||
_arguments "1:toggle:((
|
||||
on\:'enable in-prompt information for the current repository'
|
||||
off\:'disable in-prompt information for the current repository'
|
||||
))" && return 0
|
||||
|
15
modules/git/functions/git-current-branch
Normal file
15
modules/git/functions/git-current-branch
Normal file
@ -0,0 +1,15 @@
|
||||
#
|
||||
# Displays the current Git branch.
|
||||
#
|
||||
# Authors:
|
||||
# Sorin Ionescu <sorin.ionescu@gmail.com>
|
||||
#
|
||||
|
||||
local ref="$(git symbolic-ref HEAD 2> /dev/null)"
|
||||
if [[ -n "$ref" ]]; then
|
||||
print "${ref#refs/heads/}"
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
|
45
modules/git/functions/git-hub
Normal file
45
modules/git/functions/git-hub
Normal file
@ -0,0 +1,45 @@
|
||||
#
|
||||
# Opens a GitHub repository in the default browser.
|
||||
#
|
||||
# Authors:
|
||||
# Sorin Ionescu <sorin.ionescu@gmail.com>
|
||||
#
|
||||
|
||||
local remote branches branch current_branch file url
|
||||
|
||||
remote="${1:-origin}"
|
||||
url=$(
|
||||
git config -l \
|
||||
| grep "remote.${remote}.url" \
|
||||
| sed -En "s/remote.${remote}.url=(git|https?)(@|:\/\/)github.com(:|\/)(.+)\/(.+).git/https:\/\/github.com\/\4\/\5/p"
|
||||
)
|
||||
branches=($(
|
||||
git branch -r | sed -e "/${remote}\/HEAD -> ${remote}/d" -e "s/^[[:space:]]*${remote}\///g"
|
||||
))
|
||||
current_branch="$(git-current-branch)"
|
||||
branch="${2:-master}"
|
||||
file="$3"
|
||||
|
||||
if [[ -z "$2" ]]; then
|
||||
if (( $branches[(I)$current_branch] != 0 )); then
|
||||
branch="$current_branch"
|
||||
else
|
||||
branch='master'
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -n "$url" ]]; then
|
||||
url="${url}/tree/${branch}/${file}"
|
||||
|
||||
if (( $+commands[$BROWSER] )); then
|
||||
"$BROWSER" "$url"
|
||||
return 0
|
||||
else
|
||||
print "$0: browser not set or set to a non-existent browser" >&2
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
print "$0: not a Git repository or remote origin not set" >&2
|
||||
return 1
|
||||
fi
|
||||
|
23
modules/git/functions/git-hub-short-url
Normal file
23
modules/git/functions/git-hub-short-url
Normal file
@ -0,0 +1,23 @@
|
||||
#
|
||||
# Shortens GitHub URLs.
|
||||
#
|
||||
# Authors:
|
||||
# Sorin Ionescu <sorin.ionescu@gmail.com>
|
||||
#
|
||||
|
||||
local url="$1"
|
||||
|
||||
if [[ "$url" == '-' ]]; then
|
||||
read url <&0
|
||||
fi
|
||||
|
||||
if [[ -z "$url" ]]; then
|
||||
print "usage: $0 [ url | - ]" >&2
|
||||
fi
|
||||
|
||||
if (( $+commands[curl] )); then
|
||||
curl -s -i 'http://git.io' -F "url=$url" | grep 'Location:' | sed 's/Location: //'
|
||||
else
|
||||
print "$0: command not found: curl" >&2
|
||||
fi
|
||||
|
364
modules/git/functions/git-info
Normal file
364
modules/git/functions/git-info
Normal file
@ -0,0 +1,364 @@
|
||||
#
|
||||
# Displays Git repository information.
|
||||
#
|
||||
# Authors:
|
||||
# Sorin Ionescu <sorin.ionescu@gmail.com>
|
||||
#
|
||||
|
||||
# Gets the path to the Git directory.
|
||||
function _git-dir {
|
||||
local git_dir="${$(git rev-parse --git-dir):A}"
|
||||
|
||||
if [[ -n "$git_dir" ]]; then
|
||||
print "$git_dir"
|
||||
return 0
|
||||
fi
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
# Gets the Git special action (am, merge, rebase, etc.).
|
||||
# Borrowed from vcs_info and edited.
|
||||
function _git-action {
|
||||
local action=''
|
||||
local action_dir
|
||||
local git_dir="$(_git-dir)"
|
||||
|
||||
for action_dir in \
|
||||
"${git_dir}/rebase-apply" \
|
||||
"${git_dir}/rebase" \
|
||||
"${git_dir}/../.dotest"; do
|
||||
if [[ -d "$action_dir" ]] ; then
|
||||
if [[ -f "${action_dir}/rebasing" ]] ; then
|
||||
action='rebase'
|
||||
elif [[ -f "${action_dir}/applying" ]] ; then
|
||||
action='am'
|
||||
else
|
||||
action='am/rebase'
|
||||
fi
|
||||
print "$action"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
|
||||
for action_dir in \
|
||||
"${git_dir}/rebase-merge/interactive" \
|
||||
"${git_dir}/.dotest-merge/interactive"; do
|
||||
if [[ -f "$action_dir" ]]; then
|
||||
print 'rebase-i'
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
|
||||
for action_dir in \
|
||||
"${git_dir}/rebase-merge" \
|
||||
"${git_dir}/.dotest-merge"; do
|
||||
if [[ -d "$action_dir" ]]; then
|
||||
print 'rebase-m'
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ -f "${git_dir}/MERGE_HEAD" ]]; then
|
||||
print 'merge'
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [[ -f "${git_dir}/CHERRY_PICK_HEAD" ]]; then
|
||||
print 'cherry-pick'
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [[ -f "${git_dir}/BISECT_LOG" ]]; then
|
||||
print 'bisect'
|
||||
return 0
|
||||
fi
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
# Turns off git-info for the current repository.
|
||||
function _git-info-abort {
|
||||
if ! is-true "$_git_info_executing"; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
cat >&2 <<EOF
|
||||
|
||||
|
||||
Gathering status for certain repositories is time intensive.
|
||||
By pressing CTRL + C, you have turned off prompt Git status
|
||||
for this repository.
|
||||
|
||||
To revert, execute:
|
||||
git-info on
|
||||
|
||||
EOF
|
||||
|
||||
unset _git_info_executing
|
||||
git config --bool prompt.showinfo false
|
||||
git-info
|
||||
return 0
|
||||
}
|
||||
add-zsh-trap INT _git-info-abort
|
||||
|
||||
# Gets the Git status information.
|
||||
function git-info {
|
||||
# Extended globbing is needed to parse repository status.
|
||||
setopt LOCAL_OPTIONS
|
||||
setopt EXTENDED_GLOB
|
||||
|
||||
local action
|
||||
local action_format
|
||||
local action_formatted
|
||||
local added=0
|
||||
local added_format
|
||||
local added_formatted
|
||||
local ahead
|
||||
local ahead_and_behind
|
||||
local ahead_and_behind_cmd
|
||||
local ahead_format
|
||||
local ahead_formatted
|
||||
local ahead_or_behind
|
||||
local behind
|
||||
local behind_format
|
||||
local behind_formatted
|
||||
local branch
|
||||
local branch_format
|
||||
local branch_formatted
|
||||
local branch_info
|
||||
local commit
|
||||
local commit_format
|
||||
local commit_formatted
|
||||
local deleted=0
|
||||
local deleted_format
|
||||
local deleted_formatted
|
||||
local dirty=0
|
||||
local dirty_format
|
||||
local dirty_formatted
|
||||
local ignore_submodule
|
||||
local ignore_submodule_when
|
||||
local line_number=0
|
||||
local modified=0
|
||||
local modified_format
|
||||
local modified_formatted
|
||||
local position
|
||||
local position_format
|
||||
local position_formatted
|
||||
local prompt_format
|
||||
local remote
|
||||
local remote_cmd
|
||||
local remote_format
|
||||
local remote_formatted
|
||||
local renamed=0
|
||||
local renamed_format
|
||||
local renamed_formatted
|
||||
local rprompt_format
|
||||
local stashed=0
|
||||
local stashed_format
|
||||
local stashed_formatted
|
||||
local status_cmd
|
||||
local unmerged=0
|
||||
local unmerged_format
|
||||
local unmerged_formatted
|
||||
local untracked=0
|
||||
local untracked_format
|
||||
local untracked_formatted
|
||||
local -A git_info_vars
|
||||
local git_info_var
|
||||
|
||||
# Clean up previous git-info.
|
||||
unset git_prompt_info
|
||||
unset git_rprompt_info
|
||||
|
||||
# Return if not inside a Git repository work tree.
|
||||
if ! is-true "$(git rev-parse --is-inside-work-tree 2> /dev/null)"; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
if (( $# > 0 )); then
|
||||
if [[ "$1" == [Oo][Nn] ]]; then
|
||||
git config --bool prompt.showinfo true
|
||||
elif [[ "$1" == [Oo][Ff][Ff] ]]; then
|
||||
git config --bool prompt.showinfo false
|
||||
else
|
||||
print "usage: $0 [ on | off ]" >&2
|
||||
fi
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Return if git-info is disabled.
|
||||
if ! is-true "${$(git config --bool prompt.showinfo):-true}"; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Used to abort and turn git-info off on SIGINT.
|
||||
_git_info_executing=true
|
||||
|
||||
# Use porcelain status for easy parsing.
|
||||
status_cmd='git status --porcelain'
|
||||
|
||||
# Gets the remote name.
|
||||
remote_cmd='git rev-parse --symbolic-full-name --verify HEAD@{upstream}'
|
||||
|
||||
# Gets the commit difference counts between local and remote.
|
||||
ahead_and_behind_cmd='git rev-list --count --left-right HEAD...@{upstream}'
|
||||
|
||||
# Ignore submodule status.
|
||||
zstyle -b \
|
||||
':omz:module:git:prompt:ignore' submodule 'ignore_submodule'
|
||||
zstyle -s \
|
||||
':omz:module:git:prompt:ignore:submodule' when 'ignore_submodule_when'
|
||||
if is-true "$ignore_submodule"; then
|
||||
status_cmd+=" --ignore-submodules=${ignore_submodule_when:-all}"
|
||||
fi
|
||||
|
||||
# Format commit.
|
||||
commit="$(git rev-parse HEAD 2> /dev/null)"
|
||||
if [[ -n "$commit" ]]; then
|
||||
zstyle -s ':omz:module:git:prompt' commit 'commit_format'
|
||||
zformat -f commit_formatted "$commit_format" "c:$commit"
|
||||
fi
|
||||
|
||||
# Format stashed.
|
||||
if [[ -f "$(_git-dir)/refs/stash" ]]; then
|
||||
stashed="$(git stash list 2> /dev/null | wc -l)"
|
||||
zstyle -s ':omz:module:git:prompt' stashed 'stashed_format'
|
||||
zformat -f stashed_formatted "$stashed_format" "S:$stashed"
|
||||
fi
|
||||
|
||||
# Format action.
|
||||
action="$(_git-action)"
|
||||
if [[ -n "$action" ]]; then
|
||||
zstyle -s ':omz:module:git:prompt' action 'action_format'
|
||||
zformat -f action_formatted "$action_format" "s:$action"
|
||||
fi
|
||||
|
||||
# Get current status.
|
||||
while IFS=$'\n' read line; do
|
||||
# Count added, deleted, modified, renamed, unmerged, untracked, dirty.
|
||||
# T (type change) is undocumented, see http://git.io/FnpMGw.
|
||||
# For a table of scenarii, see http://i.imgur.com/2YLu1.png.
|
||||
[[ "$line" == ([ACDMT][\ MT]|[ACMT]D)\ * ]] && (( added++ ))
|
||||
[[ "$line" == [\ ACMRT]D\ * ]] && (( deleted++ ))
|
||||
[[ "$line" == ?[MT]\ * ]] && (( modified++ ))
|
||||
[[ "$line" == R?\ * ]] && (( renamed++ ))
|
||||
[[ "$line" == (AA|DD|U?|?U)\ * ]] && (( unmerged++ ))
|
||||
[[ "$line" == \?\?\ * ]] && (( untracked++ ))
|
||||
(( dirty++ ))
|
||||
done < <(${(z)status_cmd} 2> /dev/null)
|
||||
|
||||
# Format branch.
|
||||
branch="${$(git symbolic-ref -q HEAD)##refs/heads/}"
|
||||
if [[ -n "$branch" ]]; then
|
||||
zstyle -s ':omz:module:git:prompt' branch 'branch_format'
|
||||
zformat -f branch_formatted "$branch_format" "b:$branch"
|
||||
|
||||
# Format remote.
|
||||
remote="${$(${(z)remote_cmd} 2> /dev/null)##refs/remotes/}"
|
||||
if [[ -n "$remote" ]]; then
|
||||
zstyle -s ':omz:module:git:prompt' remote 'remote_format'
|
||||
zformat -f remote_formatted "$remote_format" "R:$remote"
|
||||
|
||||
# Get ahead and behind counts.
|
||||
ahead_and_behind="$(${(z)ahead_and_behind_cmd} 2> /dev/null)"
|
||||
|
||||
# Format ahead.
|
||||
ahead="$ahead_and_behind[(w)1]"
|
||||
if (( $ahead > 0 )); then
|
||||
zstyle -s ':omz:module:git:prompt' ahead 'ahead_format'
|
||||
zformat -f ahead_formatted "$ahead_format" "A:$ahead"
|
||||
fi
|
||||
|
||||
# Format behind.
|
||||
behind="$ahead_and_behind[(w)2]"
|
||||
if (( $behind > 0 )); then
|
||||
zstyle -s ':omz:module:git:prompt' behind 'behind_format'
|
||||
zformat -f behind_formatted "$behind_format" "B:$behind"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
# Format position.
|
||||
position="$(git describe --contains --all HEAD 2> /dev/null)"
|
||||
if [[ -n "$position" ]]; then
|
||||
zstyle -s ':omz:plugin:git:prompt' position 'position_format'
|
||||
zformat -f position_formatted "$position_format" "p:$position"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Format added.
|
||||
if (( $added > 0 )); then
|
||||
zstyle -s ':omz:module:git:prompt' added 'added_format'
|
||||
zformat -f added_formatted "$added_format" "a:$added_format"
|
||||
fi
|
||||
|
||||
# Format deleted.
|
||||
if (( $deleted > 0 )); then
|
||||
zstyle -s ':omz:module:git:prompt' deleted 'deleted_format'
|
||||
zformat -f deleted_formatted "$deleted_format" "d:$deleted_format"
|
||||
fi
|
||||
|
||||
# Format modified.
|
||||
if (( $modified > 0 )); then
|
||||
zstyle -s ':omz:module:git:prompt' modified 'modified_format'
|
||||
zformat -f modified_formatted "$modified_format" "m:$modified"
|
||||
fi
|
||||
|
||||
# Format renamed.
|
||||
if (( $renamed > 0 )); then
|
||||
zstyle -s ':omz:module:git:prompt' renamed 'renamed_format'
|
||||
zformat -f renamed_formatted "$renamed_format" "r:$renamed"
|
||||
fi
|
||||
|
||||
# Format unmerged.
|
||||
if (( $unmerged > 0 )); then
|
||||
zstyle -s ':omz:module:git:prompt' unmerged 'unmerged_format'
|
||||
zformat -f unmerged_formatted "$unmerged_format" "U:$unmerged"
|
||||
fi
|
||||
|
||||
# Format untracked.
|
||||
if (( $untracked > 0 )); then
|
||||
zstyle -s ':omz:module:git:prompt' untracked 'untracked_format'
|
||||
zformat -f untracked_formatted "$untracked_format" "u:$untracked"
|
||||
fi
|
||||
|
||||
# Format dirty.
|
||||
if (( $dirty > 0 )); then
|
||||
zstyle -s ':omz:module:git:prompt' dirty 'dirty_format'
|
||||
zformat -f dirty_formatted "$dirty_format" "D:$dirty"
|
||||
fi
|
||||
|
||||
# Format prompts.
|
||||
zstyle -s ':omz:module:git:prompt' prompt 'prompt_format'
|
||||
zstyle -s ':omz:module:git:prompt' rprompt 'rprompt_format'
|
||||
|
||||
git_info_vars=(
|
||||
git_prompt_info "$prompt_format"
|
||||
git_rprompt_info "$rprompt_format"
|
||||
)
|
||||
|
||||
for git_info_var in ${(k)git_info_vars}; do
|
||||
zformat -f "$git_info_var" "$git_info_vars[$git_info_var]" \
|
||||
"A:$ahead_formatted" \
|
||||
"B:$behind_formatted" \
|
||||
"D:$dirty_formatted" \
|
||||
"R:$remote_formatted" \
|
||||
"S:$stashed_formatted" \
|
||||
"U:$unmerged_formatted" \
|
||||
"a:$added_formatted" \
|
||||
"b:$branch_formatted" \
|
||||
"c:$commit_formatted" \
|
||||
"d:$deleted_formatted" \
|
||||
"m:$modified_formatted" \
|
||||
"p:$position_formatted" \
|
||||
"r:$renamed_formatted" \
|
||||
"s:$action_formatted" \
|
||||
"u:$untracked_formatted"
|
||||
done
|
||||
|
||||
unset _git_info_executing
|
||||
return 0
|
||||
}
|
||||
|
||||
git-info "$@"
|
||||
|
15
modules/git/functions/git-root
Normal file
15
modules/git/functions/git-root
Normal file
@ -0,0 +1,15 @@
|
||||
#
|
||||
# Displays the Git repository root.
|
||||
#
|
||||
# Authors:
|
||||
# Sorin Ionescu <sorin.ionescu@gmail.com>
|
||||
#
|
||||
|
||||
local root="$(git rev-parse --show-toplevel 2> /dev/null)"
|
||||
if [[ -n "$root" ]]; then
|
||||
print "$root"
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
|
15
modules/git/hub.zsh
Normal file
15
modules/git/hub.zsh
Normal file
@ -0,0 +1,15 @@
|
||||
#
|
||||
# Adds GitHub knowledge to the Git command.
|
||||
# https://github.com/defunkt/hub
|
||||
#
|
||||
# Authors:
|
||||
# Chris Wanstrath <chris@wanstrath.com>
|
||||
# Sorin Ionescu <sorin.ionescu@gmail.com>
|
||||
#
|
||||
|
||||
if (( $+commands[hub] )); then
|
||||
function git {
|
||||
hub "$@"
|
||||
}
|
||||
fi
|
||||
|
12
modules/git/init.zsh
Normal file
12
modules/git/init.zsh
Normal file
@ -0,0 +1,12 @@
|
||||
#
|
||||
# Provides Git aliases and functions.
|
||||
#
|
||||
# Authors:
|
||||
# Sorin Ionescu <sorin.ionescu@gmail.com>
|
||||
#
|
||||
|
||||
# Source module files.
|
||||
source "${0:h}/alias.zsh"
|
||||
source "${0:h}/hub.zsh"
|
||||
source "${0:h}/style.zsh"
|
||||
|
64
modules/git/style.zsh
Normal file
64
modules/git/style.zsh
Normal file
@ -0,0 +1,64 @@
|
||||
#
|
||||
# Defines Git information display styles.
|
||||
#
|
||||
# Authors:
|
||||
# Sorin Ionescu <sorin.ionescu@gmail.com>
|
||||
#
|
||||
|
||||
# %s - Special action name (am, merge, rebase).
|
||||
zstyle ':omz:module:git:prompt' action 'action:%s'
|
||||
|
||||
# %a - Indicator to notify of added files.
|
||||
zstyle ':omz:module:git:prompt' added 'added:%a'
|
||||
|
||||
# %A - Indicator to notify of ahead branch.
|
||||
zstyle ':omz:module:git:prompt' ahead 'ahead:%A'
|
||||
|
||||
# %B - Indicator to notify of behind branch.
|
||||
zstyle ':omz:module:git:prompt' behind 'behind:%B'
|
||||
|
||||
# %b - Branch name.
|
||||
zstyle ':omz:module:git:prompt' branch 'branch:%b'
|
||||
|
||||
# %c - SHA-1 hash.
|
||||
zstyle ':omz:module:git:prompt' commit 'commit:%c'
|
||||
|
||||
# %d - Indicator to notify of deleted files.
|
||||
zstyle ':omz:module:git:prompt' deleted 'deleted:%d'
|
||||
|
||||
# %D - Indicator to notify of dirty files.
|
||||
zstyle ':omz:module:git:prompt' dirty 'dirty:%D'
|
||||
|
||||
# %m - Indicator to notify of modified files.
|
||||
zstyle ':omz:module:git:prompt' modified 'modified:%m'
|
||||
|
||||
# %p - HEAD position in relation to the nearest branch, remote, tag.
|
||||
zstyle ':omz:module:git:prompt' position 'position:%p'
|
||||
|
||||
# %R - Remote name.
|
||||
zstyle ':omz:module:git:prompt' remote 'remote:%R'
|
||||
|
||||
# %r - Indicator to notify of renamed files.
|
||||
zstyle ':omz:module:git:prompt' renamed 'renamed:%r'
|
||||
|
||||
# %S - Indicator to notify of stashed files.
|
||||
zstyle ':omz:module:git:prompt' stashed 'stashed:%S'
|
||||
|
||||
# %U - Indicator to notify of unmerged files.
|
||||
zstyle ':omz:module:git:prompt' unmerged 'unmerged:%U'
|
||||
|
||||
# %u - Indicator to notify of untracked files.
|
||||
zstyle ':omz:module:git:prompt' untracked 'untracked:%u'
|
||||
|
||||
# Left prompt.
|
||||
zstyle ':omz:module:git:prompt' prompt ' git:(%b %D)'
|
||||
|
||||
# Right prompt.
|
||||
zstyle ':omz:module:git:prompt' rprompt ''
|
||||
|
||||
# Ignore submodule.
|
||||
zstyle ':omz:module:git:prompt:ignore' submodule 'no'
|
||||
|
||||
# Ignore submodule when it is 'dirty', 'untracked', 'all', or 'none'.
|
||||
zstyle ':omz:module:git:prompt:ignore:submodule' when 'all'
|
||||
|
Reference in New Issue
Block a user