1 # bash completion support for StGIT -*- shell-script -*-
3 # Copyright (C) 2006, Karl Hasselström <kha@treskal.com>
4 # Based on git-completion.sh
6 # To use these routines:
8 # 1. Copy this file to somewhere (e.g. ~/.stgit-completion.bash).
10 # 2. Add the following line to your .bashrc:
11 # . ~/.stgit-completion.bash
13 # The path to .git, or empty if we're not in a repository.
16 echo "$(git rev-parse --git-dir 2>/dev/null)"
19 # Name of the current branch, or empty if there isn't one.
22 local b
=$
(git symbolic-ref HEAD
2>/dev
/null
)
26 # List of all applied patches.
30 [ "$g" ] && cat "$g/patches/$(_current_branch)/applied"
33 # List of all unapplied patches.
37 [ "$g" ] && cat "$g/patches/$(_current_branch)/unapplied"
40 # List of all patches.
43 local b
=$
(_current_branch
)
45 [ "$g" ] && cat "$g/patches/$b/applied" "$g/patches/$b/unapplied"
48 # List of all patches except the current patch.
51 local b
=$
(_current_branch
)
53 [ "$g" ] && cat "$g/patches/$b/applied" "$g/patches/$b/unapplied" \
54 |
grep -v
"^$(< $g/patches/$b/current)$"
57 # Generate completions for patches and patch ranges from the given
58 # patch list function, and options from the given list.
59 _complete_patch_range
()
61 local patchlist
="$1" options
="$2"
62 local pfx cur
="${COMP_WORDS[COMP_CWORD]}"
67 COMPREPLY
=($
(compgen
-P
"$pfx" -W
"$($patchlist)" -- "$cur"))
70 COMPREPLY
=($
(compgen
-W
"$options $($patchlist)" -- "$cur"))
75 # Generate completions for options from the given list.
79 COMPREPLY
=($
(compgen
-W
"$options" -- "${COMP_WORDS[COMP_CWORD]}"))
84 _complete_patch_range _all_patches
"--branch --help"
89 _complete_patch_range _all_other_patches
"--help"
94 _complete_patch_range _all_patches \
95 "--all --to --cc --bcc --auto --noreply --version --prefix --template \
96 --cover --edit-cover --edit-patches --sleep --refid --smtp-user \
97 --smtp-password --branch --mbox --help"
102 _complete_options
"--message --showpatch --author --authname --authemail \
103 --authdate --commname --commemail --help"
108 _complete_patch_range _applied_patches
"--all --number --keep --help"
113 _complete_patch_range _unapplied_patches
"--all --number --reverse \
114 --merged --undo --help"
119 _complete_options
"--modified --new --deleted --conflict --unknown \
120 --noexclude --reset --help"
127 while [ $c -lt
$COMP_CWORD ]; do
129 command="${COMP_WORDS[c]}"
134 # Complete name of subcommand.
135 if [ $c -eq
$COMP_CWORD -a
-z
"$command" ]; then
136 COMPREPLY
=($
(compgen \
137 -W
"--help --version \
138 $(stg help|grep '^ '|sed 's/ *\([^ ]\) .*/\1/')" \
139 -- "${COMP_WORDS[COMP_CWORD]}"))
143 # Complete arguments to subcommands.
145 delete
) _stg_delete
;;
151 status
) _stg_status
;;
156 complete
-o default
-F _stg stg