@@ -30,22 +30,27 @@ make check # optional, requires dejagnu and tcllib
30
30
make install # as root
31
31
```
32
32
33
- These commands installs the completions and helpers, as well as a
34
- profile.d script that loads ` bash_completion ` where appropriate. If
35
- your system does not use the profile.d directory (usually below
36
- ` /etc ` ) mechanism, i.e. does not automatically source shell scripts in
37
- it, you can source the ` $sysconfdir/profile.d/bash_completion.sh `
33
+ These commands install the completions and helpers, as well as a
34
+ ` profile.d ` script that loads ` bash_completion ` where appropriate.
35
+
36
+ If your system does not use the ` profile.d ` directory (usually below
37
+ ` /etc ` ) mechanism—i.e. does not automatically source shell scripts in
38
+ it—you can source the ` $sysconfdir/profile.d/bash_completion.sh `
38
39
script in ` /etc/bashrc ` or ` ~/.bashrc ` .
39
40
40
- The profile.d script provides a configuration file hook that can be
41
+ The ` profile.d ` script provides a configuration file hook that can be
41
42
used to prevent loading ` bash_completion ` on per user basis when it's
42
- installed system wide. To do this, turn off programmable completion
43
- with ` shopt -u progcomp ` in ` $XDG_CONFIG_HOME/bash_completion `
44
- (` ~/.config/bash_completion ` if ` $XDG_CONFIG_HOME ` is not set), and
45
- turn it back on for example in ` ~/.bashrc ` if you want to use
46
- programmable completion for other purposes.
43
+ installed system wide. To do this:
44
+
45
+ 1 . Turn off programmable completion with ` shopt -u progcomp ` in
46
+ ` $XDG_CONFIG_HOME/bash_completion ` (or ` ~/.config/bash_completion `
47
+ if ` $XDG_CONFIG_HOME ` is not set)
48
+ 2 . Turn it back on (for example in ` ~/.bashrc ` ) if you want to use
49
+ programmable completion for other purposes.
50
+
51
+ ### macOS (OS X)
47
52
48
- If you're using MacOS X , ` /etc/bashrc ` is apparently not sourced at
53
+ If you're using macOS (formerly OS X) , ` /etc/bashrc ` is apparently not sourced at
49
54
all. In that case, you can put the ` bash_completion ` file in ` /sw/etc `
50
55
and add the following code to ` ~/.bash_profile ` :
51
56
@@ -73,62 +78,65 @@ tracing on in it before doing anything else there.
73
78
74
79
## Known problems
75
80
76
- 1 . There seems to be some issue with using the bash built-in cd within
81
+ 1 . There seems to be some issue with using the bash built-in ` cd ` within
77
82
Makefiles. When invoked as ` /bin/sh ` within ` Makefile ` s, bash seems
78
83
to have a problem changing directory via the ` cd ` command. A
79
84
work-around for this is to define ` SHELL=/bin/bash ` within your
80
85
` Makefile ` . This is believed to be a bug in bash.
81
86
82
87
2 . Many of the completion functions assume GNU versions of the various
83
- text utilities that they call (e.g. grep, sed and awk). Your
88
+ text utilities that they call (e.g. ` grep ` , ` sed ` , and ` awk ` ). Your
84
89
mileage may vary.
85
90
86
91
3 . If you are seeing 'unbound variable' warnings from bash when
87
- hitting \< Tab>, this is because you have either ` set -u ` or `set -o
88
- nounset` somewhere in your start-up files. This causes bash to flag
89
- the use of any uninitialised shell variables as an error.
92
+ hitting < kbd > & lt ; Tab></ kbd > , this is because you have either ` set -u `
93
+ or ` set -o nounset` somewhere in your start-up files. This causes bash
94
+ to flag the use of any uninitialised shell variables as an error.
90
95
91
96
Whilst we try to avoid references to uninitialised variables in the
92
97
code, there seem to be at least some cases where bash issues this
93
98
warning even though the variable in question has been initialised.
94
99
95
100
One place this appears to occur is within the ` _muttconffiles() `
96
- helper function used by mutt completion, where the function calls
101
+ helper function used by ` mutt ` completion, where the function calls
97
102
itself recursively. This seems to confuse bash and it issues
98
103
spurious warnings if ` nounset ` is set.
99
104
100
105
101
106
## FAQ
102
107
103
- Q. The bash completion code inhibits some commands from completing on
108
+ ** Q. The bash completion code inhibits some commands from completing on
104
109
files with extensions that are legitimate in my environment. Do I
105
110
have to disable completion for that command in order to complete on
106
- the files that I need to?
111
+ the files that I need to?**
107
112
108
113
A. No. Use ` M-/ ` to (in the words of the bash man page) attempt file
109
114
name completion on the text to the left of the cursor. This will
110
115
circumvent any file type restrictions put in place by the bash
111
116
completion code.
112
117
113
- Q. How can I insert my own local completions without having to
114
- reinsert them every time you issue a new release?
118
+ ** Q. How can I insert my own local completions without having to
119
+ reinsert them every time you issue a new release?**
115
120
116
121
A. Put them in ` ~/.bash_completion ` , which is parsed at the end of the
117
122
main completion script. See also the next question.
118
123
119
- Q. I author/maintain package X and would like to maintain my own
124
+ ** Q. I author/maintain package X and would like to maintain my own
120
125
completion code for this package. Where should I put it to be sure
121
- that interactive bash shells will find it and source it?
126
+ that interactive bash shells will find it and source it?**
122
127
123
128
A. Install it in one of the directories pointed to by
124
- bash-completion's pkgconfig file variables. There are two
125
- alternatives: the recommended one is ` completionsdir ` (get it with
126
- ` pkg-config --variable=completionsdir bash-completion ` ) from which
127
- completions are loaded on demand based on invoked commands' names,
129
+ bash-completion's ` pkgconfig ` file variables. There are two
130
+ alternatives:
131
+
132
+ - The recommended directory is ` completionsdir ` , which you can get with
133
+ ` pkg-config --variable=completionsdir bash-completion ` . From this
134
+ directory, completions are loaded on-demand based on invoked commands' names,
128
135
so be sure to name your completion file accordingly, and to include
129
- for example symbolic links in case the file provides completions
130
- for more than one command. The other one which is present for
131
- backwards compatibility reasons is ` compatdir ` (get it with
136
+ (for example) symbolic links in case the file provides completions
137
+ for more than one command.
138
+ - The other directory (which only present for backwards compatibility)
139
+ is ` compatdir ` (get it with
132
140
` pkg-config --variable=compatdir bash-completion ` ) from which files
133
141
are loaded when ` bash_completion ` is loaded.
134
142
@@ -166,39 +174,39 @@ A. Install it in one of the directories pointed to by
166
174
${BASH_COMPLETION_COMPLETIONSDIR})
167
175
```
168
176
169
- Q. I use CVS in combination with passwordless SSH access to my remote
177
+ ** Q. I use CVS in combination with passwordless SSH access to my remote
170
178
repository. How can I have the ` cvs ` command complete on remotely
171
- checked-out files where relevant?
179
+ checked-out files where relevant?**
172
180
173
181
A. Define ` $COMP_CVS_REMOTE ` . Setting this to anything will result in
174
182
the behaviour you would like.
175
183
176
- Q. When I'm running a ` ./configure ` script and completion returns a list
184
+ ** Q. When I'm running a ` ./configure ` script and completion returns a list
177
185
of long options to me, some of these take a parameter,
178
- e.g. ` --this-option=DESCRIPTION ` .
186
+ e.g. ` --this-option=DESCRIPTION ` .**
179
187
180
- Running ` ./configure --help ` lists these descriptions, but
188
+ ** Running ` ./configure --help ` lists these descriptions, but
181
189
everything after the ` = ` is stripped when returning completions, so
182
190
I don't know what kind of data is expected as a given option's
183
- parameter.
191
+ parameter.**
184
192
185
- Is there a way of getting ` ./configure ` completion to return the
193
+ ** Is there a way of getting ` ./configure ` completion to return the
186
194
entire option string, so that I can see what kind of data is
187
195
required and then simply delete the descriptive text and add my own
188
- data?
196
+ data?**
189
197
190
198
A. Define ` $COMP_CONFIGURE_HINTS ` . Setting this to anything will
191
199
result in the behaviour you would like.
192
200
193
- Q. When doing tar completion on a file within a tar file like this:
201
+ ** Q. When doing tar completion on a file within a tar file like this:**
194
202
195
203
```
196
204
tar tzvf foo.tar.gz <Tab>
197
205
```
198
206
199
- the pathnames contained in the tar file are not displayed
200
- correctly. The slashes are removed and everything looks like it's
201
- in a single directory. Why is this?
207
+ ** the pathnames contained in the tar file are not displayed
208
+ correctly. The slashes are removed, and everything looks like it's
209
+ in a single directory. Why is this?**
202
210
203
211
A. It's a choice we had to make. bash's programmable completion is
204
212
limited in how it handles the list of possible completions it
@@ -218,8 +226,9 @@ A. It's a choice we had to make. bash's programmable completion is
218
226
contents, define ` $COMP_TAR_INTERNAL_PATHS ` * before* sourcing
219
227
` bash_completion ` .
220
228
221
- Q. When completing on a symlink to a directory, bash does not append
222
- the trailing ` / ` and I have to hit \< Tab> again. I don't like this.
229
+ ** Q. When completing on a symlink to a directory, bash does not append
230
+ the trailing ` / ` and I have to hit <kbd >< ; Tab></kbd > again.
231
+ I don't like this.**
223
232
224
233
A. This has nothing to do with ` bash_completion ` . It's the default for
225
234
completing symlinks to directories since bash 2.05a, and was added
@@ -230,8 +239,8 @@ A. This has nothing to do with `bash_completion`. It's the default for
230
239
mark-symlinked-directories on` in your ` /etc/inputrc` or
231
240
` ~/.inputrc ` file.
232
241
233
- Q. Completion goes awry when I try to complete on something that contains
234
- a colon.
242
+ ** Q. Completion goes awry when I try to complete on something that contains
243
+ a colon.**
235
244
236
245
A. This is actually a 'feature' of bash. bash recognises a colon as
237
246
starting a new completion token, which is often what you want when
@@ -258,7 +267,7 @@ A. This is actually a 'feature' of bash. bash recognises a colon as
258
267
Unfortunately, there's no way to turn this off. The only thing you
259
268
can do is escape the colons with a backslash.
260
269
261
- Q. Why is ` rpm ` completion so slow with ` -q ` ?
270
+ ** Q. Why is ` rpm ` completion so slow with ` -q ` ?**
262
271
263
272
A. Probably because the database is being queried every time and this uses a
264
273
lot of memory.
@@ -281,17 +290,17 @@ A. Probably because the database is being queried every time and this uses a
281
290
unless it detects that the database has changed since the file was created,
282
291
in which case it will still use the database to ensure accuracy.
283
292
284
- Q. bash-completion interferes with my ` command_not_found_handler ` function!
293
+ ** Q. bash-completion interferes with my ` command_not_found_handler ` function!**
285
294
286
295
A. If your ` command_not_found_handler ` function is not intended to
287
296
address (possibly missing) commands invoked during bash
288
- programmable completion functions, you can take that into account
289
- in your function for example by testing if the ` $COMP_ ` * variables
290
- are set and taking appropriate bypass or other action.
297
+ programmable completion functions, you can account for this
298
+ by, for example, testing if the ` $COMP_ ` \ * variables are set and
299
+ taking appropriate bypass or other action.
291
300
292
- Q. Can tab completion be made even easier?
301
+ ** Q. Can tab completion be made even easier?**
293
302
294
- A. The readline(3) library offers a few settings that can make tab
303
+ A. The ` readline(3) ` library offers a few settings that can make tab
295
304
completion easier (or at least different) to use.
296
305
297
306
For example, try putting the following in either ` /etc/inputrc ` or
@@ -309,7 +318,7 @@ A. The readline(3) library offers a few settings that can make tab
309
318
```
310
319
311
320
This will suffix each returned file completion with a character
312
- denoting its type, in a similar way to ls(1) with ` -F ` or ` --classify ` .
321
+ denoting its type, in a similar way to ` ls(1) ` with ` -F ` or ` --classify ` .
313
322
314
323
```
315
324
set page-completions off
@@ -318,7 +327,7 @@ A. The readline(3) library offers a few settings that can make tab
318
327
This turns off the use of the internal pager when returning long
319
328
completion lists.
320
329
321
- Q. Is bash the be-all-and-end-all of completion as far as shells go?
330
+ ** Q. Is bash the be-all-and-end-all of completion as far as shells go?**
322
331
323
332
A. Absolutely not. zsh has an extremely sophisticated completion system
324
333
that offers many features absent from the bash implementation. Its
0 commit comments