1
0
Fork 0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2024-11-13 09:20:09 +00:00

Merge branch 'master' of github.com:robbyrussell/oh-my-zsh

This commit is contained in:
Robby Russell 2015-10-05 13:46:26 -07:00
commit f3fa41834d
2 changed files with 54 additions and 39 deletions

View file

@ -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.

View file

@ -1,10 +1,13 @@
#compdef git
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Description # Description
# ----------- # -----------
# #
# Completion script for git-extras (http://github.com/tj/git-extras). # Completion script for git-extras (http://github.com/tj/git-extras).
# #
# This depends on and reueses 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 # Authors
# ------- # -------
@ -22,16 +25,18 @@
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
__git_command_successful () { # Internal functions
if (( ${#pipestatus:#0} > 0 )); then # These are a lot like their __git_* equivalents inside _git
__gitex_command_successful () {
if (( ${#*:#0} > 0 )); then
_message 'not a git repository' _message 'not a git repository'
return 1 return 1
fi fi
return 0 return 0
} }
__gitex_commits() {
__git_commits() {
declare -A commits declare -A commits
git log --oneline -15 | sed 's/\([[:alnum:]]\{7\}\) /\1:/' | while read commit git log --oneline -15 | sed 's/\([[:alnum:]]\{7\}\) /\1:/' | while read commit
do do
@ -42,7 +47,7 @@ __git_commits() {
_describe -t commits commit commits && ret=0 _describe -t commits commit commits && ret=0
} }
__git_tag_names() { __gitex_tag_names() {
local expl local expl
declare -a tag_names declare -a tag_names
tag_names=(${${(f)"$(_call_program tags 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/})
@ -51,7 +56,7 @@ __git_tag_names() {
} }
__git_branch_names() { __gitex_branch_names() {
local expl local expl
declare -a branch_names declare -a branch_names
branch_names=(${${(f)"$(_call_program branchrefs git for-each-ref --format='"%(refname)"' refs/heads 2>/dev/null)"}#refs/heads/}) branch_names=(${${(f)"$(_call_program branchrefs git for-each-ref --format='"%(refname)"' refs/heads 2>/dev/null)"}#refs/heads/})
@ -59,7 +64,7 @@ __git_branch_names() {
_wanted branch-names expl branch-name compadd $* - $branch_names _wanted branch-names expl branch-name compadd $* - $branch_names
} }
__git_specific_branch_names() { __gitex_specific_branch_names() {
local expl local expl
declare -a branch_names declare -a branch_names
branch_names=(${${(f)"$(_call_program branchrefs git for-each-ref --format='"%(refname)"' refs/heads/"$1" 2>/dev/null)"}#refs/heads/$1/}) branch_names=(${${(f)"$(_call_program branchrefs git for-each-ref --format='"%(refname)"' refs/heads/"$1" 2>/dev/null)"}#refs/heads/$1/})
@ -67,32 +72,28 @@ __git_specific_branch_names() {
_wanted branch-names expl branch-name compadd $* - $branch_names _wanted branch-names expl branch-name compadd $* - $branch_names
} }
__gitex_feature_branch_names() {
__git_feature_branch_names() { __gitex_specific_branch_names 'feature'
__git_specific_branch_names 'feature'
} }
__gitex_refactor_branch_names() {
__git_refactor_branch_names() { __gitex_specific_branch_names 'refactor'
__git_specific_branch_names 'refactor'
} }
__gitex_bug_branch_names() {
__git_bug_branch_names() { __gitex_specific_branch_names 'bug'
__git_specific_branch_names 'bug'
} }
__gitex_submodule_names() {
__git_submodule_names() {
local expl local expl
declare -a submodule_names 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 __git_command_successful || return
_wanted submodule-names expl submodule-name compadd $* - $submodule_names _wanted submodule-names expl submodule-name compadd $* - $submodule_names
} }
__git_author_names() { __gitex_author_names() {
local expl local expl
declare -a author_names declare -a author_names
author_names=(${(f)"$(_call_program branchrefs git log --format='%aN' | sort -u)"}) author_names=(${(f)"$(_call_program branchrefs git log --format='%aN' | sort -u)"})
@ -123,7 +124,7 @@ _git-bug() {
case $line[1] in case $line[1] in
(finish) (finish)
_arguments -C \ _arguments -C \
':branch-name:__git_bug_branch_names' ':branch-name:__gitex_bug_branch_names'
;; ;;
esac esac
esac esac
@ -139,7 +140,7 @@ _git-changelog() {
_git-contrib() { _git-contrib() {
_arguments \ _arguments \
':author:__git_author_names' ':author:__gitex_author_names'
} }
@ -151,19 +152,19 @@ _git-count() {
_git-delete-branch() { _git-delete-branch() {
_arguments \ _arguments \
':branch-name:__git_branch_names' ':branch-name:__gitex_branch_names'
} }
_git-delete-submodule() { _git-delete-submodule() {
_arguments \ _arguments \
':submodule-name:__git_submodule_names' ':submodule-name:__gitex_submodule_names'
} }
_git-delete-tag() { _git-delete-tag() {
_arguments \ _arguments \
':tag-name:__git_tag_names' ':tag-name:__gitex_tag_names'
} }
@ -172,6 +173,7 @@ _git-effort() {
'--above[ignore file with less than x commits]' '--above[ignore file with less than x commits]'
} }
_git-extras() { _git-extras() {
local curcontext=$curcontext state line ret=1 local curcontext=$curcontext state line ret=1
declare -A opt_args declare -A opt_args
@ -216,7 +218,7 @@ _git-feature() {
case $line[1] in case $line[1] in
(finish) (finish)
_arguments -C \ _arguments -C \
':branch-name:__git_feature_branch_names' ':branch-name:__gitex_feature_branch_names'
;; ;;
esac esac
esac esac
@ -225,8 +227,8 @@ _git-feature() {
_git-graft() { _git-graft() {
_arguments \ _arguments \
':src-branch-name:__git_branch_names' \ ':src-branch-name:__gitex_branch_names' \
':dest-branch-name:__git_branch_names' ':dest-branch-name:__gitex_branch_names'
} }
@ -236,12 +238,14 @@ _git-ignore() {
'(--global -g)'{--global,-g}'[show global gitignore]' '(--global -g)'{--global,-g}'[show global gitignore]'
} }
_git-missing() { _git-missing() {
_arguments \ _arguments \
':first-branch-name:__git_branch_names' \ ':first-branch-name:__gitex_branch_names' \
':second-branch-name:__git_branch_names' ':second-branch-name:__gitex_branch_names'
} }
_git-refactor() { _git-refactor() {
local curcontext=$curcontext state line ret=1 local curcontext=$curcontext state line ret=1
declare -A opt_args declare -A opt_args
@ -263,7 +267,7 @@ _git-refactor() {
case $line[1] in case $line[1] in
(finish) (finish)
_arguments -C \ _arguments -C \
':branch-name:__git_refactor_branch_names' ':branch-name:__gitex_refactor_branch_names'
;; ;;
esac esac
esac esac
@ -272,12 +276,12 @@ _git-refactor() {
_git-squash() { _git-squash() {
_arguments \ _arguments \
':branch-name:__git_branch_names' ':branch-name:__gitex_branch_names'
} }
_git-summary() { _git-summary() {
_arguments '--line[summarize with lines other than commits]' _arguments '--line[summarize with lines rather than commits]'
__git_commits __gitex_commits
} }