Skip to content
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

Update Git completion #120

Merged
merged 2 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
- The `trap` built-in now also reports signals that are ignored
because the program that invoked the shell has set the signal
to be ignored.
- [line-editing] Updated the completion scripts to support Git
2.48.1.
- [line-editing] Added the completion script for `git-mv`.
- Fixed a possible crash when the `read` built-in reads input in an
interactive shell.
- Added a workaround for an apparent bug in glibc's fsetpos function
Expand Down
2 changes: 2 additions & 0 deletions NEWS.ja
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
も含めて全てのトラップを表示する。
- `trap` 組込みはシェルが起動された時点で最初から無視されていた
シグナルも表示するようになった
- [行編集] 補完スクリプトを Git 2.48.1 相当に更新
- [行編集] git-mv の補完を追加
- 対話シェルで `read` 組込みが入力を読み込む際にクラッシュすることが
あったのを修正
- glibc の fsetpos 関数が正しく動作しないために履歴ファイルが更新
Expand Down
81 changes: 75 additions & 6 deletions share/completion/git
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
# (C) 2011-2021 magicant
# (C) 2011-2025 magicant

# Completion script for the "git" command.
# Supports Git 2.9.2.
# Supports Git 2.48.1.

function completion/git {

typeset OPTIONS ARGOPT PREFIX
OPTIONS=( #>#
"C:; specify a directory to operate in"
"c:; specify a configuration parameter"
"--attr-source:; specify the attribute file"
"--bare; treat the repository as a bare repository"
"--config-env:; specify a configuration parameter from environment"
"--exec-path::; specify or print the directory containing core git executables"
"--git-dir:; specify the repository directory"
"--glob-pathspecs; enable globbing on all path-specs"
"--html-path; print the directory where HTML documentation is installed"
"--icase-pathspecs; treat path-specs case-insensitively"
"--info-path; print the directory where info manuals are installed"
"--list-cmds:; list commands by group"
"--literal-pathspecs; treat path-specs literally"
"--man-path; print the directory where manual pages are installed"
"--namespace:; specify a namespace"
"--no-advice; don't print any hints"
"--noglob-pathspecs; disable globbing on all path-specs"
"--no-lazy-fetch; don't fetch missing objects from remote"
"--no-optional-locks; don't do optional operations that require locks"
"p --paginate; run a pager to view Git's output"
"--no-pager; don't run a pager to view Git's output"
"P --no-pager; don't run a pager to view Git's output"
"--no-replace-objects; don't use replacement refs"
"--work-tree:; specify the working tree directory"
"--help"
"--version"
"h --help"
"v --version"
) #<#

# convert "--help" to "help"
Expand Down Expand Up @@ -634,6 +640,14 @@ function completion/git::--author:arg {
done 2>/dev/null <(git log --all --format=format:%an | uniq)
}

function completion/git::--cleanup:arg { #>>#
complete -P "$PREFIX" -D "like \"strip\" when editing and \"whitespace\" otherwise" default
complete -P "$PREFIX" -D "delete empty lines and lines below the cut line" scissors
complete -P "$PREFIX" -D "delete empty lines and comments" strip
complete -P "$PREFIX" -D "leave message as is" verbatim
complete -P "$PREFIX" -D "delete empty lines" whitespace
} #<<#

function completion/git::--color:arg { #>>#
complete -P "$PREFIX" -D "always print in color" always
complete -P "$PREFIX" -D "print in color if output is terminal" auto
Expand All @@ -658,13 +672,38 @@ function completion/git::--date:arg { #>>#
complete -P "$PREFIX" -D "print in strict ISO 8601 format" iso8601-strict
complete -P "$PREFIX" -D "print in RFC 2822 format" rfc2822
complete -P "$PREFIX" -D "print in YYYY-MM-DD format" short
complete -P "$PREFIX" -D "print the raw timestamp value" raw
complete -P "$PREFIX" -D "print the raw timestamp value with offset" raw
complete -P "$PREFIX" -D "print in minimal human-readable format" human
complete -P "$PREFIX" -D "print the raw timestamp value" unix
complete -P "$PREFIX" local relative-local default-local iso8601-local \
iso8601-strict-local rfc2822-local short-local raw-local
complete -P "$PREFIX" -D "specify a format" -T format:
} #<<#
# TODO --date=format:...%

function completion/git::--empty:arg { #>>#
complete -P "$PREFIX" -D 'discard redundant patches' drop
complete -P "$PREFIX" -D 'create empty commits for redundant patches' keep
complete -P "$PREFIX" -D 'pause on redundant patches' stop
} #<<#

function completion/git::--exclude-hidden:arg { #>>#
complete -P "$PREFIX" -D "fetch.hideRefs" fetch
complete -P "$PREFIX" -D "receive.hideRefs" receive
complete -P "$PREFIX" -D "uploadpack.hideRefs" uploadpack
} #<<#

function completion/git::--filter:arg { #>>#
complete -P "$PREFIX" -D "omit all blobs" blob:none
complete -P "$PREFIX" -S = -T -D "pick blobs smaller than the specified size" blob:limit
complete -P "$PREFIX" -D "pick tags only" object:type=tag
complete -P "$PREFIX" -D "pick commits only" object:type=commit
complete -P "$PREFIX" -D "pick trees only" object:type=tree
complete -P "$PREFIX" -D "pick blobs only" object:type=blob
complete -P "$PREFIX" -S = -T -D "pick blobs for sparse checkout only" sparse:oid
complete -P "$PREFIX" -S : -T -D "omit blobs deeper than the specified level" tree
} #<<#

function completion/git::--format:arg {
typeset word="${TARGETWORD#"$PREFIX"}"
word=${word//%%}
Expand Down Expand Up @@ -721,6 +760,7 @@ function completion/git::--format:arg {
complete -P "$PREFIX" -D "commit ID, author, date, and full log message" medium
complete -P "$PREFIX" -D "commit ID, author, committer, and full log message" full
complete -P "$PREFIX" -D "commit ID, author, date, committer, date, and full log message" fuller
complete -P "$PREFIX" -D "commit ID, title, and date" reference
complete -P "$PREFIX" -D "imitate email" email
complete -P "$PREFIX" -D "raw commit object" raw
complete -P "$PREFIX" -D "specify a format (newline-separated)" -T format:
Expand All @@ -733,13 +773,21 @@ function completion/git::--format:arg {
esac
}

function completion/git::--gpg-sign:arg {
# TODO
}

function completion/git::--ignore-submodules:arg { #>>#
complete -P "$PREFIX" -D "ignore all changes in submodules" all
complete -P "$PREFIX" -D "ignore uncommitted changes in submodules" dirty
complete -P "$PREFIX" -D "show all changes in submodules" none
complete -P "$PREFIX" -D "ignore untracked files in submodules" untracked
} #<<#

function completion/git::--negotiation-tip:arg {
command -f completion/git::completeref
}

function completion/git::--pretty:arg {
command -f completion/git::--format:arg "$@"
}
Expand All @@ -755,6 +803,27 @@ function completion/git::--recurse-submodules:arg { #>>#
complete -P "$PREFIX" yes
} #<<#

function completion/git::--ref-format:arg { #>>#
complete -P "$PREFIX" files reftable
} #<<#

function completion/git::--refmap:arg {
command -f completion/git::completeref
}

function completion/git::--shallow-exclude:arg {
command -f completion/git::completeref
}

function completion/git::--sort:arg {
# TODO
}

function completion/git::--track:arg { #>>#
complete -P "$PREFIX" -D "use start-point branch as upstream" direct
complete -P "$PREFIX" -D "copy remote-tracking branch from start-point branch" inherit
} #<<#

function completion/git::--untracked-files:arg { #>>#
complete -P "$PREFIX" -D "print all individual files in untracked directories" all
complete -P "$PREFIX" -D "print untracked files and directories" normal
Expand Down
17 changes: 15 additions & 2 deletions share/completion/git-add
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# (C) 2011-2013 magicant
# (C) 2011-2025 magicant

# Completion script for the "git-add" command.
# Supports Git 1.7.7.
# Supports Git 2.48.1

function completion/git-add {
WORDS=(git add "${WORDS[2,-1]}")
Expand All @@ -12,15 +12,22 @@ function completion/git::add:arg {

OPTIONS=( #>#
"A --all; add all files including untracked files"
"--chmod:; override executable bit of added files"
"n --dry-run; don't actually add files"
"e --edit; edit patch hunks before adding"
"f --force; add ignored files"
"--ignore-errors; continue adding other files on an error"
"--ignore-missing; ignore missing files (with -n)"
"N --intent-to-add; add filepaths but not their contents"
"i --interactive; enter the interactive mode"
"--no-all --no-ignore-removal; add only new and modified files"
"--no-warn-embedded-repo; allow adding embedded repositories"
"p --patch; interactively choose patch hunks to add"
"--pathspec-file-nul; use nul as separator for pathspecs"
"--pathspec-from-file:; read pathspecs from file"
"--refresh; refresh stat info in the index without adding"
"--renormalize; re-apply \"clean\" process"
"--sparse; update index outside of sparse-checkout cone"
"u --update; add tracked files only; don't add new files"
"v --verbose; print affected filenames"
) #<#
Expand All @@ -30,6 +37,12 @@ function completion/git::add:arg {
(-)
command -f completion//completeoptions
;;
(--chmod)
complete -P "$PREFIX" -- -x +x
;;
(--pathspec-from-file)
complete -P "$PREFIX" -f
;;
('')
command -f completion/git::add:opr
;;
Expand Down
28 changes: 25 additions & 3 deletions share/completion/git-am
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# (C) 2011 magicant
# (C) 2011-2025 magicant

# Completion script for the "git-am" command.
# Supports Git 1.7.7.
# Supports Git 2.48.1.

function completion/git-am {
WORDS=(git am "${WORDS[2,-1]}")
Expand All @@ -11,20 +11,33 @@ function completion/git-am {
function completion/git::am:arg {

OPTIONS=( #>#
"3 --3way; try 3-way merge on conflict"
"--allow-empty; create empty commit for message without patch"
"--abort; abort patching and restore the original branch"
"--committer-date-is-author-date; use author date for committer date"
"r --continue --resolved; commit the current index and continue patching"
"--empty:; specify how to handle messages without a patch"
"S:: --gpg-sign::; sign commits using GPG"
"--ignore-date; use committer date for author date"
"i --interactive"
"k --keep; use the mail subject intact as the commit message"
"--keep-cr; don't remove carriage returns at the end of lines"
"--keep-non-patch; keep bracketed words in subject except [PATCH]"
"m --message-id; add message-id to commit message"
"--no-3way; don't try 3-way merge on conflict"
"--no-gpg-sign; don't sign commits using GPG"
"--no-keep-cr; remove carriage returns at the end of lines"
"--no-message-id; don't add message-id to commit message"
"--no-scissors; cancels the --scissors OPTIONS"
"--no-utf8; don't convert character encoding"
"v --no-verify; bypass pre-applypatch and applypatch-msg hooks"
"--patch-format:; specify patch format"
"--quoted-cr:; specify how to handle CR in quoted email"
"q --quiet; print error messages only"
"--quit; abort patching and keep HEAD and index as is"
"--resolvemsg:" # not for command line use
"--retry; re-apply last conflicting patch"
"c --scissors; remove lines before a scissors line"
"--show-current-patch::; show message on conflict"
"s --signoff; add a \"signed-off-by\" line to the message"
"--skip; skip the current patch (when restarting an aborted patch)"
"u --utf8; re-encode the log message into UTF-8"
Expand All @@ -42,6 +55,15 @@ function completion/git::am:arg {
('')
complete -P "$PREFIX" -f
;;
(--empty)
command -f completion/git::--empty:arg
;;
(--patch-format)
complete -P "$PREFIX" mbox mboxrd stgit stgit-series hg
;;
(S|--gpg-sign)
command -f completion/git::--gpg-sign:arg
;;
(*)
if command -vf completion/git::apply:compopt >/dev/null 2>&1 ||
. -AL completion/git-apply; then
Expand Down
2 changes: 1 addition & 1 deletion share/completion/git-annotate
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# (C) 2011 magicant

# Completion script for the "git-annotate" command.
# Supports Git 1.7.7.
# Supports Git 2.48.1.

function completion/git-annotate {
WORDS=(git annotate "${WORDS[2,-1]}")
Expand Down
16 changes: 12 additions & 4 deletions share/completion/git-apply
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# (C) 2011 magicant
# (C) 2011-2025 magicant

# Completion script for the "git-apply" command.
# Supports Git 1.7.7.
# Supports Git 2.48.1.

function completion/git-apply {
WORDS=(git apply "${WORDS[2,-1]}")
Expand All @@ -12,21 +12,26 @@ function completion/git::apply:arg {

OPTIONS=( #>#
"--allow-binary-replacement --binary"
"--allow-empty; accept patch with no diff"
"--apply; force to apply patches"
"--build-fake-ancestor:" # TODO
"--cached; apply patches to the index without modifying the working tree"
"--check; check if patches can be applied without errors instead of applying patches"
"--exclude:; skip files whose names match the specified pattern"
"--inaccurate-eof; work around diff errors about missing newlines at end of file"
"--include:; apply to only files whose names match the specified pattern"
"--index; apply patches to the index as well as the working tree"
"--intent-to-add; add filepaths but not their contents"
"--no-add; apply deletions but not additions"
"--ours; resolve conflicts in favor of our version"
"q --quiet; suppress status and progress output"
"--recount; ignore line counts in hunk headers"
"R --reverse; patch in reverse"
"--stat; print diffstat instead of applying patches"
"--numstat; print a diffstat in the machine-friendly format instead of applying patches"
"--summary; print summary instead of applying patches"
"--theirs; resolve conflicts in favor of their version"
"--unidiff-zero; accept unified diffs without context lines"
"--union; resolve conflicts by combining both sides"
"--unsafe-paths; allow patching outside working tree"
"v --verbose; report progress in detail"
"z; print a null byte after each filename"
) #<#
Expand All @@ -52,7 +57,10 @@ function completion/git::apply:getopt {
case $1 in (am|apply)
apply=true
OPTIONS=("$OPTIONS" #>#
"3 --3way; try 3-way merge on conflict"
"--directory:; specify a directory to work in"
"--exclude:; skip files whose names match the specified pattern"
"--include:; apply to only files whose names match the specified pattern"
"p:; specify the number of pathname components to strip from file names"
"--reject; apply as much as possible and leave rejected hunks in *.rej file"
) #<#
Expand Down
7 changes: 4 additions & 3 deletions share/completion/git-bisect
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# (C) 2011-2016 magicant
# (C) 2011-2025 magicant

# Completion script for the "git-bisect" command.
# Supports Git 2.9.2.
# Supports Git 2.48.1.

function completion/git-bisect {
WORDS=(git bisect "${WORDS[2,-1]}")
Expand All @@ -25,7 +25,7 @@ function completion/git::bisect:arg {
complete -P "$PREFIX" -D "mark a commit as untestable" skip
complete -P "$PREFIX" -D "start bisection" start
complete -P "$PREFIX" -D "show terms used in the current session" terms
complete -P "$PREFIX" -D "show remaining suspects with GUI" visualize
complete -P "$PREFIX" -D "show remaining suspects with GUI" visualize view
#<<#
case ${TARGETWORD#"$PREFIX"} in (vie*)
complete -P "$PREFIX" -D "show remaining suspects with GUI" view
Expand Down Expand Up @@ -80,6 +80,7 @@ function completion/git::bisect:skip:arg {
function completion/git::bisect:start:arg {

OPTIONS=( #>#
"--first-parent; follow only first parent of merge commits"
"--no-checkout; don't automatically check out commits to test"
"--term-old: --term-good:; specify a term for the old state"
"--term-new: --term-bad:; specify a term for the new state"
Expand Down
2 changes: 1 addition & 1 deletion share/completion/git-blame
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# (C) 2011 magicant

# Completion script for the "git-blame" command.
# Supports Git 1.7.7.
# Supports Git 2.48.1.

function completion/git-blame {
WORDS=(git blame "${WORDS[2,-1]}")
Expand Down
Loading