summaryrefslogtreecommitdiffstats
path: root/bash_completion
blob: ec248c11f885751fecf03582e553a9e3f3414228 (plain) (blame)
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
#-*- mode: shell-script;-*-

# Programmed completion for bash to use quilt
# Copyright 2003-2004 Martin Quinson (martin quinson#debian org)

# This file is part of the distribution of quilt, and is distributed under
# the same licence than quilt itself

# WARNING: This script doesn't read user or system quiltrc files, and assumes
# that QUILT_PC is left unchanged. If you have changed QUILT_PC and want
# completion to work then you must set QUILT_PC in your global environment
# (for example in ~/.profile) and not just in your quiltrc file.

# Complete on files (by default) or directories (with -d)
#
_quilt_comfile()
{
	local IFS=$'\t\n'
	COMPREPLY=( "${COMPREPLY[@]}" $( compgen ${1:--f} -- "$cur" ) )
}

_quilt_completion()
{
    local cur prev cmds command_matches

    COMPREPLY=()
    cur=${COMP_WORDS[COMP_CWORD]}
    prev=${COMP_WORDS[COMP_CWORD-1]}

    # quilt sub commands
    cmds='add annotate applied delete diff edit files fold fork graph \
	  grep header import mail new next patches pop previous push refresh \
	  remove rename revert series setup snapshot top unapplied upgrade'

    # if no command were given, complete on commands
    if [[ $COMP_CWORD -eq 1 ]] ; then
	COMPREPLY=( $( compgen -W "$cmds -h" -- $cur ) )
	return 0
    fi

    # if we're completing for 'quilt -h', then just
    # complete on any valid command
    if [ ${COMP_WORDS[1]} == -h ] ; then
	    COMPREPLY=( $( compgen -W "$cmds" -- $cur ) )
	    return 0
    fi

    # Accept a partial command if it's unique, because quilt will accept it.
    command_matches=( $(compgen -W "$cmds" -- ${COMP_WORDS[1]}) )
    if [ ${#command_matches[@]} -ne 1 ] ; then
	return 0
    fi

    # Complete depending on options
    case ${command_matches[0]} in
	add)
	   case $prev in
	     -P)
		COMPREPLY=( $( compgen -W "$(quilt --quiltrc - applied 2>/dev/null)" -- $cur ) )
		;;
	     *)
		_quilt_comfile
		COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W "-P -h" -- $cur ) )
		;;
	   esac
	   ;;
	annotate)
	   case $prev in
	     -P)
		COMPREPLY=( $( compgen -W "$(quilt --quiltrc - applied 2>/dev/null)" -- $cur ) )
		;;
	     *)
		_quilt_comfile
		COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W "-P -h" -- $cur ) )
		;;
	   esac
	   ;;
	applied)
	   COMPREPLY=( $( compgen -W "-h $(quilt --quiltrc - applied 2>/dev/null)" -- $cur ) )
	   ;;
	delete)
	   COMPREPLY=( $( compgen -W "-n -r -h --backup $(quilt --quiltrc - series)" -- $cur ) )
	   ;;
	diff)
	   case $prev in
	     -p)
		COMPREPLY=( $( compgen -W "0 1 ab" -- $cur ) )
		;;
	     -P|--combine)
		COMPREPLY=( $( compgen -W "$(quilt --quiltrc - applied 2>/dev/null)" -- $cur ) )
		;;
	     --diff|-U|-C)
		;;
	     *)
		_quilt_comfile
		COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W "-p -P -u -U -c -C -R -z -h --snapshot --diff --no-timestamps --no-index --combine --color --sort" -- $cur ) )
		;;
	   esac
	   ;;
	edit)
	   _quilt_comfile
	   COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W "-h" -- $cur ) )
	   ;;
	files)
	   case $prev in
	     --combine)
		COMPREPLY=( $( compgen -W "$(quilt --quiltrc - applied 2>/dev/null)" -- $cur ) )
		;;
	     *)
		COMPREPLY=( $( compgen -W "-a -l -v -h --combine $(quilt --quiltrc - applied 2>/dev/null)" -- $cur ) )
		;;
	   esac
	   ;;
	fold)
	   case $prev in
	     -p)
		COMPREPLY=( $( compgen -W "0 1 2 3 4 5 6 7 8 9 10" -- $cur ) )
		;;
	     *)
		_quilt_comfile
		COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W "-R -q -f -p -h" -- $cur ) )
		;;
	   esac
	   ;;
	graph)
	   case $prev in
	     -T)
		COMPREPLY=( $( compgen -W "ps" -- $cur ) )
		;;
	     --edge-labels)
		COMPREPLY=( $( compgen -W "files" -- $cur ) )
		;;
	     *)
		COMPREPLY=( $( compgen -W "-T -h --all --reduce --lines --edge-labels $(quilt --quiltrc - applied 2>/dev/null)" -- $cur ) )
		;;
	   esac
	   ;;
	grep)
	   type _longopt &> /dev/null && _longopt grep
	   COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W "-h" -- $cur ) )
	   ;;
	header)
	   COMPREPLY=( $( compgen -W "-a -e -h -r --backup --strip-diffstat --strip-trailing-whitespace $(quilt --quiltrc - series)" -- $cur ) )
	   ;;
	import)
	   case $prev in
	     -p)
		COMPREPLY=( $( compgen -W "0 1 2 3 4 5 6 7 8 9 10" -- $cur ) )
		;;
	     -P)
		;;
	     -d)
		COMPREPLY=( $( compgen -W "o a n" -- $cur ) )
		;;
	     *)
		_quilt_comfile
		COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W "-p -R -P -f -d -h" -- $cur ) )
		;;
	   esac
	   ;;
	mail)
	   case $prev in
	     --mbox|-M)
		_quilt_comfile
		;;
	     --signature)
		_quilt_comfile
		COMPREPLY=( "${COMPREPLY[@]}" - )
		;;
	     --prefix|--sender|--from|--subject|--to|--cc|--bcc|--charset|--reply-to)
		;;
	     *)
		COMPREPLY=( $( compgen -W "-m -M --prefix --mbox --send --sender --from --subject --to --cc --bcc --charset --signature --reply-to -h" -- $cur ) )
		;;
	   esac
	   ;;
	new)
	   case $prev in
	     -p)
		COMPREPLY=( $( compgen -W "0 1 ap" -- $cur ) )
		;;
	     *)
		COMPREPLY=( $( compgen -W "-p -h" -- $cur ) )
		;;
	   esac
	   ;;
	next|previous)
	   COMPREPLY=( $( compgen -W "$(quilt --quiltrc - series) -h" -- $cur ) )
	   ;;
	patches)
	   _quilt_comfile
	   COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W "-v --color -h" -- $cur ) )
	   ;;
	pop)
	   COMPREPLY=( $( compgen -W "-a -f -R -q -v --refresh -h $(quilt --quiltrc - applied 2>/dev/null)" -- $cur ) )
	   ;;
	push)
	   case $prev in
	     --fuzz)
		;;
	     *)
		COMPREPLY=( $( compgen -W "-a -f -q -v -h --fuzz -m --merge --leave-rejects --color --refresh $(quilt --quiltrc - unapplied 2>/dev/null)" -- $cur ) )
		;;
	   esac
	   ;;
	refresh)
	   case $prev in
	     -p)
		COMPREPLY=( $( compgen -W "0 1 ap" -- $cur ) )
		;;
	     -U|-C)
		;;
	     *)
		COMPREPLY=( $( compgen -W "-p -u -U -c -C -z -f -h $(quilt --quiltrc - applied 2>/dev/null) --no-timestamps --no-index --diffstat --sort --backup --strip-trailing-whitespace" -- $cur ) )
		;;
	   esac
	   ;;
	remove|revert)
	   case $prev in
	     -P)
		COMPREPLY=( $( compgen -W "$(quilt --quiltrc - applied 2>/dev/null)" -- $cur ) )
		;;
	     *)
		_quilt_comfile
		COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W "-P -h" -- $cur ) )
		;;
	   esac
	   ;;
	rename)
	   case $prev in
	     -P)
		COMPREPLY=( $( compgen -W "$(quilt --quiltrc - series)" -- $cur ) )
		;;
	     *)
		COMPREPLY=( $( compgen -W "-P -h" -- $cur ) )
		;;
	   esac
	   ;;
	series)
	   COMPREPLY=( $( compgen -W "-v -h --color" -- $cur ) )
	   ;;
	setup)
	   case $prev in
	     -d|--sourcedir)
		_quilt_comfile -d
		;;
	     --fuzz)
		;;
	     *)
		_quilt_comfile
		COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W "-d -v -h --sourcedir --fuzz --slow --fast" -- $cur ) )
		;;
	   esac
	   ;;
	snapshot)
	   COMPREPLY=( $( compgen -W "-d -h" -- $cur ) )
	   ;;
	unapplied)
	   COMPREPLY=( $( compgen -W "-h $(quilt --quiltrc - series)" -- $cur ) )
	   ;;
	fork|top|upgrade)
	   ;;
    esac
    return 0
}

# With option "filenames", directories are shown in completion with their
# trailing / so that the user can go in them.
#
[ ${BASH_VERSINFO[0]} '>' 2 -o \
  ${BASH_VERSINFO[0]}  =  2 -a ${BASH_VERSINFO[1]} '>' 04 ] \
&& _quilt_complete_opt="-o filenames"
complete -F _quilt_completion $_quilt_complete_opt quilt
unset -v _quilt_complete_opt