Skip to content

Commit df990b0

Browse files
committed
docs(tar): move commentary from README to variable and implementation
While at it, make semantics of setting the variable more accurate: it needs to be set before the *tar* completion is sourced (not bash_completion), and it needs to be set to a non-null value.
1 parent 521348d commit df990b0

File tree

3 files changed

+24
-32
lines changed

3 files changed

+24
-32
lines changed

README.md

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -212,34 +212,6 @@ A. Define `$COMP_CVS_REMOTE`. Setting this to anything will result in
212212
A. Define `$COMP_CONFIGURE_HINTS`. Setting this to anything will
213213
result in the behaviour you would like.
214214

215-
**Q. When doing tar completion on a file within a tar file like this:**
216-
217-
```shell
218-
tar tzvf foo.tar.gz <Tab>
219-
```
220-
221-
**the pathnames contained in the tar file are not displayed
222-
correctly. The slashes are removed, and everything looks like it's
223-
in a single directory. Why is this?**
224-
225-
A. It's a choice we had to make. bash's programmable completion is
226-
limited in how it handles the list of possible completions it
227-
returns.
228-
229-
Because the paths returned from within the tar file are likely not
230-
existing paths on the file system, `-o dirnames` must be passed to
231-
the `complete` built-in to make it treat them as such. However,
232-
then bash will append a space when completing on directories during
233-
pathname completion to the tar files themselves.
234-
235-
It's more important to have proper completion of paths to tar files
236-
than it is to have completion for their contents, so this sacrifice
237-
was made and `-o filenames` is used with complete instead.
238-
239-
If you would rather have correct path completion for tar file
240-
contents, define `$COMP_TAR_INTERNAL_PATHS` *before* sourcing
241-
`bash_completion`.
242-
243215
**Q. When completing on a symlink to a directory, bash does not append
244216
the trailing `/` and I have to hit <kbd>&lt;Tab></kbd> again.
245217
I don't like this.**

completions/tar

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,24 @@
3737
# - mode option should be advised only once
3838
# - format option should be advised only once
3939
# ...
40+
#
41+
# Tar files vs internal paths
42+
# ===========================
43+
#
44+
# bash's programmable completion is limited in how it handles the list of
45+
# possible completions it returns.
46+
#
47+
# Because the paths returned from within the tar file are likely not existing
48+
# paths on the file system, `-o dirnames` must be passed to the `complete`
49+
# built-in to make it treat them as such. However, then bash will append a
50+
# space when completing on directories during pathname completion to the tar
51+
# files themselves.
52+
#
53+
# It's more important to have proper completion of paths to tar files than it
54+
# is to have completion for their contents, so this sacrifice was made and
55+
# `-o filenames` is used with complete instead by default. Setting the
56+
# `$COMP_TAR_INTERNAL_PATHS` environment variable to a non-null
57+
# value *before sourcing* this completion toggles that the other way around.
4058

4159
__gtar_parse_help_opt()
4260
{

doc/bash_completion.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@
5757
Default is unset.
5858

5959
*COMP_TAR_INTERNAL_PATHS*::
60-
If set and not null *before* sourcing bash_completion, `tar` completion
61-
will do correct path completion for tar file contents. If unset or null,
62-
`tar' completion will do correct completion for paths to tar files. See
63-
also README.
60+
If set and not null *before sourcing* the `tar` completion, it will do
61+
correct path completion for tar file _contents_. If unset or null,
62+
_paths to_ tar files will be correctly completed. Unfortunately we do not
63+
have a way to make both Just Work properly at the moment. We consider it
64+
more important to have proper completion of paths to tar files than it is
65+
to have completion for their contents, so the default is unset.

0 commit comments

Comments
 (0)