#StackBounty: #shell #zsh #autocomplete zsh completion: do not offer directories when extracting archive with tar

Bounty: 200

the completion system for tar command is quite clever. When I have different archive types, it offers the relevant files depending on tar options used:

$ ls
file.tar.xz
file.tar.gz

$ tar xJf f<TAB>
file.tar.xz

$ tar xzf f<TAB>
file.tar.gz

It recognizes xJf as acting on tar.xz files, and xzf acting on tar.gz files.

But when directory exists in current location, it offers it for completion as well :

$ tar xJf f<TAB>
foo/   file.tar.xz

Can I tell the completion system, that I only want to complete files, when extracting archives (ie, tar option x...) ?

But it should still offer directories when creating archives (tar option c...):

tar cpJf foo.tar.xz 

I assume this will need modifying the main completion file for tar command: /usr/share/zsh/functions/Completion/Unix/_tar. But how?


Get this bounty!!!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.