1
0
Fork 0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2024-11-25 15:20:08 +00:00
ohmyzsh/plugins/git-extras/git-extras.plugin.zsh

332 lines
8.7 KiB
Bash
Raw Normal View History

2012-07-19 10:50:53 +00:00
#compdef git
2012-07-19 11:01:32 +00:00
# ------------------------------------------------------------------------------
# Description
# -----------
#
2014-12-15 04:41:22 +00:00
# Completion script for git-extras (http://github.com/tj/git-extras).
2012-07-19 11:01:32 +00:00
#
# ------------------------------------------------------------------------------
# Authors
# -------
#
# * Alexis GRIMALDI (https://github.com/agrimaldi)
2014-12-15 04:41:22 +00:00
# * spacewander (https://github.com/spacewander)
2012-07-19 11:01:32 +00:00
#
# ------------------------------------------------------------------------------
# Inspirations
# -----------
#
2014-12-15 04:41:22 +00:00
# * git-extras (http://github.com/tj/git-extras)
2012-07-19 11:01:32 +00:00
# * git-flow-completion (http://github.com/bobthecow/git-flow-completion)
#
# ------------------------------------------------------------------------------
2012-07-19 10:50:53 +00:00
__git_command_successful () {
if (( ${#pipestatus:#0} > 0 )); then
_message 'not a git repository'
return 1
fi
return 0
}
2014-12-15 04:41:22 +00:00
__git_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
}
2012-07-19 10:50:53 +00:00
__git_tag_names() {
local expl
declare -a tag_names
2014-12-15 04:41:22 +00:00
tag_names=(${${(f)"$(_call_program tags git for-each-ref --format='"%(refname)"' refs/tags 2>/dev/null)"}#refs/tags/})
2012-07-19 10:50:53 +00:00
__git_command_successful || return
_wanted tag-names expl tag-name compadd $* - $tag_names
}
__git_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/})
__git_command_successful || return
_wanted branch-names expl branch-name compadd $* - $branch_names
}
2014-12-15 04:41:22 +00:00
__git_specific_branch_names() {
2012-07-19 10:50:53 +00:00
local expl
declare -a branch_names
2014-12-15 04:41:22 +00:00
branch_names=(${${(f)"$(_call_program branchrefs git for-each-ref --format='"%(refname)"' refs/heads/"$1" 2>/dev/null)"}#refs/heads/$1/})
2012-07-19 10:50:53 +00:00
__git_command_successful || return
_wanted branch-names expl branch-name compadd $* - $branch_names
}
2014-12-15 04:41:22 +00:00
__git_feature_branch_names() {
__git_specific_branch_names 'feature'
}
2012-07-19 10:50:53 +00:00
__git_refactor_branch_names() {
2014-12-15 04:41:22 +00:00
__git_specific_branch_names 'refactor'
2012-07-19 10:50:53 +00:00
}
__git_bug_branch_names() {
2014-12-15 04:41:22 +00:00
__git_specific_branch_names 'bug'
2012-07-19 10:50:53 +00:00
}
__git_submodule_names() {
local expl
declare -a submodule_names
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() {
local expl
declare -a author_names
author_names=(${(f)"$(_call_program branchrefs git log --format='%aN' | sort -u)"})
__git_command_successful || return
_wanted author-names expl author-name compadd $* - $author_names
}
2014-12-15 04:41:22 +00:00
# subcommands
2012-07-19 10:50:53 +00:00
2014-12-15 04:41:22 +00:00
_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:__git_bug_branch_names'
;;
esac
esac
2012-07-19 10:50:53 +00:00
}
2014-12-15 04:41:22 +00:00
_git-changelog() {
2012-07-19 10:50:53 +00:00
_arguments \
2014-12-15 04:41:22 +00:00
'(-l --list)'{-l,--list}'[list commits]' \
2012-07-19 10:50:53 +00:00
}
2014-12-15 04:41:22 +00:00
2012-07-19 10:50:53 +00:00
_git-contrib() {
_arguments \
':author:__git_author_names'
}
_git-count() {
_arguments \
'--all[detailed commit count]'
}
_git-delete-branch() {
_arguments \
':branch-name:__git_branch_names'
}
_git-delete-submodule() {
_arguments \
':submodule-name:__git_submodule_names'
}
_git-delete-tag() {
_arguments \
':tag-name:__git_tag_names'
}
2014-12-15 04:41:22 +00:00
_git-effort() {
_arguments \
'--above[ignore file with less than x commits]'
}
2012-07-19 10:50:53 +00:00
_git-extras() {
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=(
'update:update git-extras'
)
_describe -t commands command commands && ret=0
;;
esac
_arguments \
2014-12-15 04:41:22 +00:00
'(-v --version)'{-v,--version}'[show current version]'
2012-07-19 10:50:53 +00:00
}
_git-feature() {
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 feature 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_feature_branch_names'
;;
esac
esac
}
2014-12-15 04:41:22 +00:00
_git-graft() {
_arguments \
':src-branch-name:__git_branch_names' \
':dest-branch-name:__git_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:__git_branch_names' \
':second-branch-name:__git_branch_names'
}
2012-07-19 10:50:53 +00:00
_git-refactor() {
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 refactor 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_refactor_branch_names'
;;
esac
esac
}
2014-12-15 04:41:22 +00:00
_git-squash() {
_arguments \
':branch-name:__git_branch_names'
}
2012-07-19 10:50:53 +00:00
2014-12-15 04:41:22 +00:00
_git-summary() {
_arguments '--line[summarize with lines other than commits]'
__git_commits
2012-07-19 10:50:53 +00:00
}
2014-12-15 04:41:22 +00:00
_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)]'
}
2012-07-19 10:50:53 +00:00
zstyle ':completion:*:*:git:*' user-commands \
2014-12-15 04:41:22 +00:00
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' \
2012-07-19 10:50:53 +00:00
changelog:'populate changelog file with commits since the previous tag' \
2014-12-15 04:41:22 +00:00
commits-since:'list commits since a given date' \
2012-07-19 10:50:53 +00:00
contrib:'display author contributions' \
count:'count commits' \
2014-12-15 04:41:22 +00:00
create-branch:'create local and remote branch' \
2012-07-19 10:50:53 +00:00
delete-branch:'delete local and remote branch' \
2014-12-15 04:41:22 +00:00
delete-merged-brancees:'delete merged branches'\
2012-07-19 10:50:53 +00:00
delete-submodule:'delete submodule' \
delete-tag:'delete local and remote tag' \
2014-12-15 04:41:22 +00:00
effort:'display effort statistics' \
2012-07-19 10:50:53 +00:00
extras:'git-extras' \
feature:'create a feature branch' \
2014-12-15 04:41:22 +00:00
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' \
2012-07-19 10:50:53 +00:00
ignore:'add patterns to .gitignore' \
info:'show info about the repository' \
2014-12-15 04:41:22 +00:00
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' \
2012-07-19 10:50:53 +00:00
setup:'setup a git repository' \
2014-12-15 04:41:22 +00:00
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' \
2012-07-19 10:50:53 +00:00
touch:'one step creation of new files' \
2014-12-15 04:41:22 +00:00
undo:'remove the latest commit' \
unlock:'unlock a file excluded from version control'