1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
|
# (C) 2011-2025 magicant
# Completion script for the "git-stash" command.
# Supports Git 2.48.1.
function completion/git-stash {
WORDS=(git stash "${WORDS[2,-1]}")
command -f completion//reexecute
}
function completion/git::stash:arg
if [ ${WORDS[#]} -le 1 ]; then #>>#
complete -P "$PREFIX" -D "restore stash contents" apply
complete -P "$PREFIX" -D "restore stash contents in a new branch" branch
complete -P "$PREFIX" -D "remove all stashes" clear
complete -P "$PREFIX" -D "create a stash commit without adding it to the stash list" create
complete -P "$PREFIX" -D "remove stash contents without restoring it" drop
complete -P "$PREFIX" -D "list existing stashes" list
complete -P "$PREFIX" -D "restore stash contents and remove it from the stash list" pop
complete -P "$PREFIX" -D "save local changes in a new stash and reset to HEAD" push
complete -P "$PREFIX" save
complete -P "$PREFIX" -D "show stash contents" show
complete -P "$PREFIX" -D "add an existing commit to the stash list" store
#<<#
command -f completion/git::stash:push:arg
else
WORDS=("${WORDS[2,-1]}")
if command -vf "completion/git::stash:${WORDS[1]}:arg" >/dev/null 2>&1; then
command -f "completion/git::stash:${WORDS[1]}:arg"
else
case ${WORDS[1]} in (-*)
command -f completion/git::stash:push:arg
esac
fi
fi
function completion/git::stash:apply:arg {
command -f completion/git::stash:pop:arg
}
function completion/git::stash:branch:arg {
if [ ${WORDS[#]} -le 1 ]; then
command -f completion/git::completeref --branches
else
command -f completion/git::stash:completestash
fi
}
#function completion/git::stash:clear:arg {
#}
#function completion/git::stash:create:arg {
#}
function completion/git::stash:drop:arg {
command -f completion/git::stash:pop:arg
}
function completion/git::stash:list:arg {
OPTIONS=()
if command -vf completion/git::log:getopt >/dev/null 2>&1 ||
. -AL completion/git-log; then
command -f completion/git::log:getopt
fi
command -f completion//parseoptions -n
case $ARGOPT in
(-)
command -f completion//completeoptions
;;
('')
;;
(*)
command -f completion/git::log:compopt
;;
esac
}
function completion/git::stash:pop:arg {
OPTIONS=( #>#
"q --quiet; print error messages only"
) #<#
case ${WORDS[1]} in (apply|pop)
OPTIONS=("$OPTIONS" #>#
"--index; restore the index as well as the working copy"
) #<#
esac
command -f completion//parseoptions -n
case $ARGOPT in
(-)
command -f completion//completeoptions
;;
('')
command -f completion/git::stash:completestash
;;
esac
}
function completion/git::stash:push:arg {
OPTIONS=( #>#
"a --all; stash all files including ignored/untracked files"
"u --include-untracked; stash untracked files as well as tracked files"
"k --keep-index; keep the index intact"
"m: --message:; specify the stash message"
"--no-keep-index; stash and reset the index"
"p --patch; interactively choose patch hunks to stash"
"--pathspec-file-nul; use nul as separator for pathspecs"
"--pathspec-from-file:; read pathspecs from file"
"q --quiet; print error messages only"
"S --staged; stash only staged changes"
) #<#
case ${WORDS[1]} in (push|-*)
OPTIONS=("$OPTIONS" #>#
"m: --message:; specify the stash message"
) #<#
esac
command -f completion//parseoptions -n
case $ARGOPT in
(-)
if [ "${WORDS[#]}" -le 1 ]; then
WORDS=(push "$WORDS")
fi
command -f completion//completeoptions
;;
(--pathspec-from-file)
complete -P "$PREFIX" -f
;;
('')
case ${WORDS[1]} in (-*)
typeset i
for i in "${WORDS}"; do
if [ "$i" = -- ]; then
WORDS=(push "$WORDS")
break
fi
done
esac
case ${WORDS[1]} in (push)
command -f completion/git::completefilteredpath '' \
--ignore-submodules=dirty
esac
;;
esac
}
function completion/git::stash:save:arg {
command -f completion/git::stash:push:arg
}
function completion/git::stash:show:arg {
OPTIONS=( #>#
"u --include-untracked; show untracked files"
"--no-include-untracked; don't show untracked files"
"--only-untracked; show only untracked files"
) #<#
if command -vf completion/git::diff:getopt >/dev/null 2>&1 ||
. -AL completion/git-diff; then
command -f completion/git::diff:getopt
fi
command -f completion//parseoptions -n
case $ARGOPT in
(-)
command -f completion//completeoptions
;;
('')
command -f completion/git::stash:completestash
;;
(*)
command -f completion/git::diff:compopt
;;
esac
}
function completion/git::stash:completestash {
typeset name message
while read -r name message; do
name=${name%:}
complete -P "$PREFIX" -D "$message" -- "$name"
done 2>/dev/null <(git stash list)
}
# vim: set ft=sh ts=8 sts=8 sw=8 et:
|