summaryrefslogtreecommitdiff
path: root/plugins/git-extras
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/git-extras')
-rw-r--r--plugins/git-extras/README.md11
-rw-r--r--plugins/git-extras/git-extras.plugin.zsh242
2 files changed, 157 insertions, 96 deletions
diff --git a/plugins/git-extras/README.md b/plugins/git-extras/README.md
new file mode 100644
index 000000000..8f12e297e
--- /dev/null
+++ b/plugins/git-extras/README.md
@@ -0,0 +1,11 @@
+# git-extras
+
+This plugin provides completion definitions for some of the commands defined by [git-extras](http://github.com/tj/git-extras).
+
+## Setup notes
+
+The completions work by augmenting the `_git` completion provided by `zsh`. This only works with the `zsh`-provided `_git`, not the `_git` provided by `git` itself. If you have both `zsh` and `git` installed, you need to make sure that the `zsh`-provided `_git` takes precedence.
+
+### OS X Homebrew Setup
+
+On OS X with Homebrew, you need to install `git` with `brew install git --without-completions`. Otherwise, `git`'s `_git` will take precedence, and you won't see the completions for `git-extras` commands.
diff --git a/plugins/git-extras/git-extras.plugin.zsh b/plugins/git-extras/git-extras.plugin.zsh
index 8419166ab..0dcd630e8 100644
--- a/plugins/git-extras/git-extras.plugin.zsh
+++ b/plugins/git-extras/git-extras.plugin.zsh
@@ -1,45 +1,62 @@
-#compdef git
# ------------------------------------------------------------------------------
# Description
# -----------
#
-# Completion script for git-extras (http://github.com/visionmedia/git-extras).
+# Completion script for git-extras (http://github.com/tj/git-extras).
+#
+# This depends on and reuses some of the internals of the _git completion
+# function that ships with zsh itself. It will not work with the _git that ships
+# with git.
#
# ------------------------------------------------------------------------------
# Authors
# -------
#
# * Alexis GRIMALDI (https://github.com/agrimaldi)
+# * spacewander (https://github.com/spacewander)
#
# ------------------------------------------------------------------------------
# Inspirations
# -----------
#
-# * git-extras (http://github.com/visionmedia/git-extras)
+# * git-extras (http://github.com/tj/git-extras)
# * git-flow-completion (http://github.com/bobthecow/git-flow-completion)
#
# ------------------------------------------------------------------------------
-__git_command_successful () {
- if (( ${#pipestatus:#0} > 0 )); then
- _message 'not a git repository'
- return 1
- fi
- return 0
+# Internal functions
+# These are a lot like their __git_* equivalents inside _git
+
+__gitex_command_successful () {
+ if (( ${#*:#0} > 0 )); then
+ _message 'not a git repository'
+ return 1
+ fi
+ return 0
}
+__gitex_commits() {
+ declare -A commits
+ git log --oneline -15 | sed 's/\([[:alnum:]]\{7\}\) /\1:/' | while read commit
+ do
+ hash=$(echo $commit | cut -d':' -f1)
+ commits[$hash]="$commit"
+ done
+ local ret=1
+ _describe -t commits commit commits && ret=0
+}
-__git_tag_names() {
+__gitex_tag_names() {
local expl
declare -a tag_names
- tag_names=(${${(f)"$(_call_program branchrefs git for-each-ref --format='"%(refname)"' refs/tags 2>/dev/null)"}#refs/tags/})
+ tag_names=(${${(f)"$(_call_program tags git for-each-ref --format='"%(refname)"' refs/tags 2>/dev/null)"}#refs/tags/})
__git_command_successful || return
_wanted tag-names expl tag-name compadd $* - $tag_names
}
-__git_branch_names() {
+__gitex_branch_names() {
local expl
declare -a branch_names
branch_names=(${${(f)"$(_call_program branchrefs git for-each-ref --format='"%(refname)"' refs/heads 2>/dev/null)"}#refs/heads/})
@@ -47,44 +64,36 @@ __git_branch_names() {
_wanted branch-names expl branch-name compadd $* - $branch_names
}
-
-__git_feature_branch_names() {
+__gitex_specific_branch_names() {
local expl
declare -a branch_names
- branch_names=(${${(f)"$(_call_program branchrefs git for-each-ref --format='"%(refname)"' refs/heads/feature 2>/dev/null)"}#refs/heads/feature/})
+ branch_names=(${${(f)"$(_call_program branchrefs git for-each-ref --format='"%(refname)"' refs/heads/"$1" 2>/dev/null)"}#refs/heads/$1/})
__git_command_successful || return
_wanted branch-names expl branch-name compadd $* - $branch_names
}
-
-__git_refactor_branch_names() {
- local expl
- declare -a branch_names
- branch_names=(${${(f)"$(_call_program branchrefs git for-each-ref --format='"%(refname)"' refs/heads/refactor 2>/dev/null)"}#refs/heads/refactor/})
- __git_command_successful || return
- _wanted branch-names expl branch-name compadd $* - $branch_names
+__gitex_feature_branch_names() {
+ __gitex_specific_branch_names 'feature'
}
-
-__git_bug_branch_names() {
- local expl
- declare -a branch_names
- branch_names=(${${(f)"$(_call_program branchrefs git for-each-ref --format='"%(refname)"' refs/heads/bug 2>/dev/null)"}#refs/heads/bug/})
- __git_command_successful || return
- _wanted branch-names expl branch-name compadd $* - $branch_names
+__gitex_refactor_branch_names() {
+ __gitex_specific_branch_names 'refactor'
}
+__gitex_bug_branch_names() {
+ __gitex_specific_branch_names 'bug'
+}
-__git_submodule_names() {
+__gitex_submodule_names() {
local expl
declare -a submodule_names
- submodule_names=(${(f)"$(_call_program branchrefs git submodule status | awk '{print $2}')"})
+ submodule_names=(${(f)"$(_call_program branchrefs git submodule status | awk '{print $2}')"}) # '
__git_command_successful || return
_wanted submodule-names expl submodule-name compadd $* - $submodule_names
}
-__git_author_names() {
+__gitex_author_names() {
local expl
declare -a author_names
author_names=(${(f)"$(_call_program branchrefs git log --format='%aN' | sort -u)"})
@@ -92,22 +101,46 @@ __git_author_names() {
_wanted author-names expl author-name compadd $* - $author_names
}
+# subcommands
-_git-changelog() {
- _arguments \
- '(-l --list)'{-l,--list}'[list commits]' \
+_git-bug() {
+ local curcontext=$curcontext state line ret=1
+ declare -A opt_args
+
+ _arguments -C \
+ ': :->command' \
+ '*:: :->option-or-argument' && ret=0
+
+ case $state in
+ (command)
+ declare -a commands
+ commands=(
+ 'finish:merge bug into the current branch'
+ )
+ _describe -t commands command commands && ret=0
+ ;;
+ (option-or-argument)
+ curcontext=${curcontext%:*}-$line[1]:
+ case $line[1] in
+ (finish)
+ _arguments -C \
+ ':branch-name:__gitex_bug_branch_names'
+ ;;
+ esac
+ esac
}
-_git-effort() {
+_git-changelog() {
_arguments \
- '--above[ignore file with less than x commits]' \
+ '(-l --list)'{-l,--list}'[list commits]' \
}
+
_git-contrib() {
_arguments \
- ':author:__git_author_names'
+ ':author:__gitex_author_names'
}
@@ -119,19 +152,25 @@ _git-count() {
_git-delete-branch() {
_arguments \
- ':branch-name:__git_branch_names'
+ ':branch-name:__gitex_branch_names'
}
_git-delete-submodule() {
_arguments \
- ':submodule-name:__git_submodule_names'
+ ':submodule-name:__gitex_submodule_names'
}
_git-delete-tag() {
_arguments \
- ':tag-name:__git_tag_names'
+ ':tag-name:__gitex_tag_names'
+}
+
+
+_git-effort() {
+ _arguments \
+ '--above[ignore file with less than x commits]'
}
@@ -154,20 +193,7 @@ _git-extras() {
esac
_arguments \
- '(-v --version)'{-v,--version}'[show current version]' \
-}
-
-
-_git-graft() {
- _arguments \
- ':src-branch-name:__git_branch_names' \
- ':dest-branch-name:__git_branch_names'
-}
-
-
-_git-squash() {
- _arguments \
- ':branch-name:__git_branch_names'
+ '(-v --version)'{-v,--version}'[show current version]'
}
@@ -192,13 +218,34 @@ _git-feature() {
case $line[1] in
(finish)
_arguments -C \
- ':branch-name:__git_feature_branch_names'
+ ':branch-name:__gitex_feature_branch_names'
;;
esac
esac
}
+_git-graft() {
+ _arguments \
+ ':src-branch-name:__gitex_branch_names' \
+ ':dest-branch-name:__gitex_branch_names'
+}
+
+
+_git-ignore() {
+ _arguments -C \
+ '(--local -l)'{--local,-l}'[show local gitignore]' \
+ '(--global -g)'{--global,-g}'[show global gitignore]'
+}
+
+
+_git-missing() {
+ _arguments \
+ ':first-branch-name:__gitex_branch_names' \
+ ':second-branch-name:__gitex_branch_names'
+}
+
+
_git-refactor() {
local curcontext=$curcontext state line ret=1
declare -A opt_args
@@ -220,66 +267,69 @@ _git-refactor() {
case $line[1] in
(finish)
_arguments -C \
- ':branch-name:__git_refactor_branch_names'
+ ':branch-name:__gitex_refactor_branch_names'
;;
esac
esac
}
-_git-bug() {
- local curcontext=$curcontext state line ret=1
- declare -A opt_args
-
- _arguments -C \
- ': :->command' \
- '*:: :->option-or-argument' && ret=0
+_git-squash() {
+ _arguments \
+ ':branch-name:__gitex_branch_names'
+}
- case $state in
- (command)
- declare -a commands
- commands=(
- 'finish:merge bug into the current branch'
- )
- _describe -t commands command commands && ret=0
- ;;
- (option-or-argument)
- curcontext=${curcontext%:*}-$line[1]:
- case $line[1] in
- (finish)
- _arguments -C \
- ':branch-name:__git_bug_branch_names'
- ;;
- esac
- esac
+_git-summary() {
+ _arguments '--line[summarize with lines rather than commits]'
+ __gitex_commits
}
+_git-undo(){
+ _arguments -C \
+ '(--soft -s)'{--soft,-s}'[only rolls back the commit but changes remain un-staged]' \
+ '(--hard -h)'{--hard,-h}'[wipes your commit(s)]'
+}
+
zstyle ':completion:*:*:git:*' user-commands \
+ alias:'define, search and show aliases' \
+ archive-file:'export the current HEAD of the git repository to a archive' \
+ back:'undo and stage latest commits' \
+ bug:'create a bug branch' \
changelog:'populate changelog file with commits since the previous tag' \
+ commits-since:'list commits since a given date' \
contrib:'display author contributions' \
count:'count commits' \
+ create-branch:'create local and remote branch' \
delete-branch:'delete local and remote branch' \
+ delete-merged-branches:'delete merged branches'\
delete-submodule:'delete submodule' \
delete-tag:'delete local and remote tag' \
+ effort:'display effort statistics' \
extras:'git-extras' \
- graft:'merge commits from source branch to destination branch' \
- squash:'merge commits from source branch into the current one as a single commit' \
feature:'create a feature branch' \
- refactor:'create a refactor branch' \
- bug:'create a bug branch' \
- summary:'repository summary' \
- effort:'display effort statistics' \
- repl:'read-eval-print-loop' \
- commits-since:'list commits since a given date' \
- release:'release commit with the given tag' \
- alias:'define, search and show aliases' \
+ fork:'fork a repo on github' \
+ fresh-branch:'create empty local branch' \
+ gh-pages:'create the GitHub Pages branch' \
+ graft:'merge commits from source branch to destination branch' \
ignore:'add patterns to .gitignore' \
info:'show info about the repository' \
- create-branch:'create local and remote branch' \
- fresh-branch:'create empty local branch' \
- undo:'remove the latest commit' \
+ local-commits:'list unpushed commits on the local branch' \
+ lock:'lock a file excluded from version control' \
+ locked:'ls files that have been locked' \
+ missing:'show commits missing from another branch' \
+ pr:'checks out a pull request locally' \
+ rebase-patch:'rebases a patch' \
+ refactor:'create a refactor branch' \
+ release:'commit, tag and push changes to the repository' \
+ rename-tag:'rename a tag' \
+ repl:'read-eval-print-loop' \
+ reset-file:'reset one file' \
+ root:'show path of root' \
setup:'setup a git repository' \
+ show-tree:'show branch tree of commit history' \
+ squash:'merge commits from source branch into the current one as a single commit' \
+ summary:'repository summary' \
touch:'one step creation of new files' \
- obliterate:'Completely remove a file from the repository, including past commits and tags' \
- local-commits:'list unpushed commits on the local branch' \
+ undo:'remove the latest commit' \
+ unlock:'unlock a file excluded from version control'