OSDN Git Service

completion/git-switch: support git-switch
authorVictorien Elvinger <victorien@elvinger.fr>
Wed, 19 Apr 2023 16:34:22 +0000 (18:34 +0200)
committerVictorien Elvinger <victorien@elvinger.fr>
Sat, 22 Apr 2023 10:51:53 +0000 (12:51 +0200)
share/completion/git
share/completion/git-switch [new file with mode: 0644]

index 03dfd5e..1e4730b 100644 (file)
@@ -264,6 +264,7 @@ function completion/git::completecmd { #>>#
        # discouraged: complete -P "$PREFIX" -D "" stripspace
        complete -P "$PREFIX" -D "manipulate submodules" submodule
        complete -P "$PREFIX" -D "operate with a Subversion repository" svn
+       complete -P "$PREFIX" -D "switch a branch" switch
        complete -P "$PREFIX" -D "make or resolve a symbolic ref" symbolic-ref
        complete -P "$PREFIX" -D "manipulate tags" tag
        # deprecated: complete -P "$PREFIX" -D "" tar-tree
diff --git a/share/completion/git-switch b/share/completion/git-switch
new file mode 100644 (file)
index 0000000..ac82a77
--- /dev/null
@@ -0,0 +1,85 @@
+# (C) 2023 Victorien Elvinger
+
+# Completion script for the "git-switch" command.
+# Supports Git 2.23.0.
+
+function completion/git-switch {
+       WORDS=(git switch "${WORDS[2,-1]}")
+       command -f completion//reexecute
+}
+
+function completion/git::switch:arg {
+       OPTIONS=( #>#
+       "C: --force-create:; create or reset a new branch and switch to it"
+       "--conflict:; like --merge, but specify format of unmerged files"
+       "c: --create:; create a new branch and switch to it"
+       "d --detach; leave HEAD in detached head state"
+       "--guess; guess which branch to track based on its name"
+       "f --force; overwrite local changes or ignore unmerged files"
+       "--discard-changes; restore the index and worktree to match the destination branch"
+       "--ignore-other-worktrees; switch even if it is checked out by other worktrees"
+       "m --merge; do 3-way merge for destination branch"
+       "--no-guess; don't guess which branch to track based on its name"
+       "--no-progress; don't report progress status on standard error"
+       "--no-recurse-submodules; don't update the content of all active submodules"
+       "--no-track; create a non-tracking branch"
+       "--orphan:; create a new branch with no parent"
+       "--progress; report progress status on standard error"
+       "q --quiet; print error and warning messages only"
+       "--recurse-submodules; update the content of all active submodules"
+       "t --track; create a tracking branch"
+       ) #<#
+
+       command -f completion//parseoptions
+       case $ARGOPT in
+               (-)
+                       command -f completion//completeoptions
+                       ;;
+               ([Cc]|--create|--force-create|--orphan)
+                       command -f completion/git::completeref --branches
+                       ;;
+               (--conflict) #>>#
+                       complete -P "$PREFIX" -D "ours and theirs" merge
+                       complete -P "$PREFIX" -D "ours, theirs, and original" diff3
+                       ;; #<<#
+               ('')
+                       # Parse options that modify completion behavior,
+                       # and find first non-option argument.
+                       typeset OPTIND=2 branch=0 detach=0 orphan=0
+                       while [ $OPTIND -le ${WORDS[#]} ]; do
+                               case ${WORDS[OPTIND]} in
+                                       (-[Cc]*|--create=*|--force-create=*)
+                                               branch=1
+                                               ;;
+                                       (-d|--detach)
+                                               detach=1
+                                               ;;
+                                       (--orphan=*)
+                                               branch=1
+                                               orphan=1
+                                               ;;
+                                       (-?*)
+                                               ;;
+                                       (*)
+                                               break
+                                               ;;
+                               esac
+                               OPTIND=$((OPTIND+1))
+                       done
+
+                       # no operands yet
+                       if [ $OPTIND -gt ${WORDS[#]} ]; then
+                               if [ $detach -eq 1 ]; then
+                                       command -f completion/git::completeref
+                               elif [ $branch -eq 0 ]; then
+                                       command -f completion/git::completeref --branches
+                               elif [ $orphan -eq 0 ]; then
+                                       command -f completion/git::completeref
+                               fi
+                       fi
+                       ;;
+       esac
+}
+
+
+# vim: set ft=sh ts=8 sts=8 sw=8 noet: