-
-
Notifications
You must be signed in to change notification settings - Fork 25.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New git plugin: git2 #2494
New git plugin: git2 #2494
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
## Git plugin | ||
**Maintainer:** [Stibbons](https://github.com/Stibbons) | ||
|
||
Compared to the first git plugin, this one adds several organised git aliases and increase the completion | ||
function provided by zsh. Please note that is is a complete rework, with many new aliases to relearn. | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#compdef git-branch | ||
|
||
_git-branch () | ||
{ | ||
declare l c m d | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In my opinion you could use real meaningful variable names, single letters vars don't really say what their purpose is ;) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a port from zsh's completion of git. Apparently it's the standard notation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK fair enough ;) |
||
|
||
l='--color --no-color -r -a --all -v --verbose --abbrev --no-abbrev' | ||
c='-l -f --force -t --track --no-track --set-upstream --contains --merged --no-merged' | ||
m='-m -M' | ||
d='-d -D' | ||
|
||
declare -a dependent_creation_args | ||
if (( words[(I)-r] == 0 )); then | ||
dependent_creation_args=( | ||
"($l $m $d): :__git_branch_names" | ||
"::start-point:__git_revisions") | ||
fi | ||
|
||
declare -a dependent_deletion_args | ||
if (( words[(I)-d] || words[(I)-D] )); then | ||
dependent_creation_args= | ||
dependent_deletion_args=( | ||
'-r[delete only remote-tracking branches]') | ||
if (( words[(I)-r] )); then | ||
dependent_deletion_args+='*: :__git_ignore_line_inside_arguments __git_remote_branch_names' | ||
else | ||
dependent_deletion_args+='*: :__git_ignore_line_inside_arguments __git_branch_names' | ||
fi | ||
fi | ||
|
||
declare -a dependent_modification_args | ||
if (( words[(I)-m] || words[(I)-M] )); then | ||
dependent_creation_args= | ||
dependent_modification_args=( | ||
':old or new branch name:__git_branch_names' | ||
'::new branch name:__git_branch_names') | ||
fi | ||
|
||
_arguments -w -S -s \ | ||
"($c $m $d --no-color :)--color=-[turn on branch coloring]:: :__git_color_whens" \ | ||
"($c $m $d : --color)--no-color[turn off branch coloring]" \ | ||
"($c $m -a --all)-r[list or delete only remote-tracking branches]" \ | ||
"($c $m $d : -r)"{-a,--all}"[list both remote-tracking branches and local branches]" \ | ||
"($c $m $d : -v --verbose)"{-v,--verbose}'[show SHA1 and commit subject line for each head]' \ | ||
"($c $m $d :)--abbrev=[set minimum SHA1 display-length]: :__git_guard_number length" \ | ||
"($c $m $d :)--no-abbrev[do not abbreviate sha1s]" \ | ||
"($l $m $d)-l[create the branch's reflog]" \ | ||
"($l $m $d -f --force)"{-f,--force}"[force the creation of a new branch]" \ | ||
"($l $m $d -t --track)"{-t,--track}"[set up configuration so that pull merges from the start point]" \ | ||
"($l $m $d)--no-track[override the branch.autosetupmerge configuration variable]" \ | ||
"($l $m $d)--set-upstream[set up configuration so that pull merges]" \ | ||
"($l $m $d)--contains=[only list branches which contain the specified commit]: :__git_committishs" \ | ||
"($l $m $d)--merged=[only list branches which are fully contained by HEAD]: :__git_committishs" \ | ||
"($l $m $d)--no-merged=[do not list branches which are fully contained by HEAD]: :__git_committishs" \ | ||
$dependent_creation_args \ | ||
"($l $c $d -M)-m[rename a branch and the corresponding reflog]" \ | ||
"($l $c $d -m)-M[rename a branch even if the new branch-name already exists]" \ | ||
$dependent_modification_args \ | ||
"($l $c $m -D)-d[delete a fully merged branch]" \ | ||
"($l $c $m -d)-D[delete a branch]" \ | ||
$dependent_deletion_args | ||
} | ||
|
||
(( $+functions[__git_ignore_line] )) || | ||
__git_ignore_line () { | ||
declare -a ignored | ||
ignored=() | ||
((CURRENT > 1)) && | ||
ignored+=(${line[1,CURRENT-1]//(#m)[\[\]()\\*?#<>~\^]/\\$MATCH}) | ||
((CURRENT < $#line)) && | ||
ignored+=(${line[CURRENT+1,-1]//(#m)[\[\]()\\*?#<>~\^]/\\$MATCH}) | ||
$* -F ignored | ||
} | ||
|
||
(( $+functions[__git_ignore_line_inside_arguments] )) || | ||
__git_ignore_line_inside_arguments () { | ||
declare -a compadd_opts | ||
|
||
zparseopts -D -E -a compadd_opts V: J: 1 2 n f X: M: P: S: r: R: q F: | ||
|
||
__git_ignore_line $* $compadd_opts | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#compdef git-remote | ||
|
||
# NOTE: --track is undocumented. | ||
# TODO: --track, -t, --master, and -m should take remote branches, I guess. | ||
# NOTE: --master is undocumented. | ||
# NOTE: --fetch is undocumented. | ||
_git-remote () { | ||
local curcontext=$curcontext state line | ||
declare -A opt_args | ||
|
||
_arguments -C \ | ||
':command:->command' \ | ||
'*::options:->options' && ret=0 | ||
|
||
case $state in | ||
(command) | ||
declare -a commands | ||
|
||
commands=( | ||
'add:add a new remote' | ||
'show:show information about a given remote' | ||
'prune:delete all stale tracking branches for a given remote' | ||
'update:fetch updates for a set of remotes' | ||
'rm:remove a remote from .git/config and all associated tracking branches' | ||
'rename:rename a remote from .git/config and update all associated tracking branches' | ||
'set-head:sets or deletes the default branch' | ||
'set-branches:changes the list of branches tracked by the named remote.' | ||
'set-url:changes URL remote points to.' | ||
) | ||
|
||
_describe -t commands 'sub-command' commands && ret=0 | ||
;; | ||
(options) | ||
case $line[1] in | ||
(add) | ||
_arguments \ | ||
'*'{--track,-t}'[track given branch instead of default glob refspec]:branch:__git_branch_names' \ | ||
'(--master -m)'{--master,-m}'[set the remote'\''s HEAD to point to given master branch]:branch:__git_branch_names' \ | ||
'(--fetch -f)'{--fetch,-f}'[run git-fetch on the new remote after it has been created]' \ | ||
':branch name:__git_remotes' \ | ||
':url:_urls' && ret=0 | ||
;; | ||
(show) | ||
_arguments \ | ||
'-n[do not contact the remote for a list of branches]' \ | ||
':remote:__git_remotes' && ret=0 | ||
;; | ||
(prune) | ||
_arguments \ | ||
'(--dry-run -n)'{-n,--dry-run}'[do not actually prune, only list what would be done]' \ | ||
':remote:__git_remotes' && ret=0 | ||
;; | ||
(update) | ||
__git_remote-groups && ret=0 | ||
;; | ||
(rm) | ||
__git_remotes && ret=0 | ||
;; | ||
(rename) | ||
__git_remotes && ret=0 | ||
;; | ||
(set-url) | ||
_arguments \ | ||
'*--push[manipulate push URLs]' \ | ||
'(--add)--add[add URL]' \ | ||
'(--delete)--delete[delete URLs]' \ | ||
':branch name:__git_remotes' \ | ||
':url:_urls' && ret=0 | ||
;; | ||
|
||
esac | ||
;; | ||
esac | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you be more specific ?
As for myself I'm not using aliases, but completion is definitely interesting. It seem the completion function cannot find options on some git commands like
git-blame
/git-annotate
etc.