[Bash-completion-devel] Bug#618734: [RFC/PATCH] 'tar jcf <TAB>' should complete arbitrary filenames

Jonathan Nieder jrnieder at gmail.com
Fri Mar 18 02:21:44 UTC 2011


Currently "tar cjf <TAB>" completes arbitrary filenames, while
"tar jcf <TAB>" completes files with a .bz2 suffix.

It is useful to only match .bz2 files when extracting an archive, but
when using "c" to create an archive I don't think you would often want
to create it over the top of an existing file.  So if you use tab
completion in this case, you are probably wanting it to match any old
file to save typing.  Make it so.

Reported-by: Adam Nielsen <adam.nielsen at uq.edu.au>
---
How about something like this patch?  It occurs to me that

 * "tar -rjf <TAB>" completes arbitrary files instead of just
   bzip2 files;

 * the pattern "tar --compare <TAB>" triggers this case by
   accident; similarly, "tar --diff <TAB>" triggers the -f
   case by accident.

With a fixup for those, would this be a sane thing to do?

Thoughts, bug reports, improvements welcome.

 CHANGES         |    4 ++++
 completions/tar |    2 +-
 2 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/CHANGES b/CHANGES
index eedac4e..b3ba70e 100644
--- a/CHANGES
+++ b/CHANGES
@@ -10,6 +10,10 @@ bash-completion (2.x)
   [ Guillaume Rousse ]
   * added puppet completion, using work from Mathieu Parent (sathieudebian.org)
 
+  [ Jonathan Nieder ]
+  * Complete arbitrary filenames in the argument to "tar zcf", like we already
+    do for "tar czf" (Debian: #618734)
+
  -- David Paleino <d.paleino at gmail.com>  Sun, 06 Feb 2011 21:46:37 +0100
 
 bash-completion (1.3)
diff --git a/completions/tar b/completions/tar
index a5c0249..5dfaca5 100644
--- a/completions/tar
+++ b/completions/tar
@@ -14,7 +14,7 @@ _tar()
     fi
 
     case ${COMP_WORDS[1]} in
-        ?(-)[cr]*f)
+        ?(-)r*f | *c*f)
             _filedir
             return 0
             ;;
-- 
1.7.4.1






More information about the Bash-completion-devel mailing list