Sitelet https://github.com/scop/bash-completion/pull/1734
Skip to content

fix(tar): complete files for combined short options like -tf with bsdtar - #1734

Open
fudianchn wants to merge 1 commit into
scop:mainfrom
fudianchn:fix/bsdtar-combined-short-options
Open

fudianchn wants to merge 1 commit into
scop:mainfrom
fudianchn:fix/bsdtar-combined-short-options

Conversation

@fudianchn

@fudianchn fudianchn commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

AI disclosure: this change was prepared with AI coding agents, reviewed and revised line by line by me.

What

bsdtar -tf <TAB> and star -tf <TAB> now complete archive files. Combined short options ending in f or b complete their argument like the plain form. Plain -f is unchanged.

Why

bsdtar and star parse combined short options like GNU tar does. The completion dropped the file argument for every combined form.

How

_comp_cmd_tar__posix calls _comp_cmd_tar__cleanup_prev before matching the previous word, mirroring the GNU path.

Root cause

_comp_cmd_tar__posix_prev_handle matches exact -f only. _comp_cmd_tar__cleanup_prev, which turns -tf into -f, ran in the GNU path only.

Testing

  • test_tar.py#test_26 (bsdtar -tf ): fails on main, passes with the fix.
  • test_27 (bsdtar -f ) guards plain -f: passes on both.
  • test_28-test_30: star -tf positive, -cf create-mode combo guard (directories only), -tzf compression-extension guard.
  • All 33 tar tests pass (test_tar 30 + test_bsdtar 2 + test_smbtar 1). shellcheck and shfmt clean.
  • Not covered: bsdtar -t <TAB> and -tv <TAB> still complete nothing. Pre-existing gap in _comp_cmd_tar__try_list_archive, left untouched.

Verification of the original issue

Issue reports no completion for bsdtar -tf . With the fix, the same line completes archives like gtar -tf does.

Fixes #1728

_comp_cmd_tar__posix did not normalize a bundled short option such as
"-tf" down to its last letter before matching the previous word against
"-f" and "-b", so unlike the GNU path (which calls
_comp_cmd_tar__cleanup_prev) the file argument of combined short options
was never completed for bsdtar and star.  Call _comp_cmd_tar__cleanup_prev
after _comp_cmd_tar__adjust_PREV_from_old_option so "-tf", "-bf",
"-tvf" etc. complete archives/dirs like plain "-f" does.

Signed-off-by: 付典 <fudianchn@gmail.com>
@akinomyoga

Copy link
Copy Markdown
Collaborator

The function modified in this PR is _comp_cmd_tar__posix, which is not specifically for BSD tar. POSIX (SUSv2) tar doesn't support -tf. At the same time, the missing support for BSD tar is not limited to the option argument to -f; there are many BSD options we do not support.

@fudianchn

Copy link
Copy Markdown
Contributor Author
  1. _comp_cmd_tar__posix is reached from the bsdtar/star registrations and from _comp_cmd_tar, which dispatches bare tar to it when --version does not report GNU. In practice that bare tar is bsdtar (macOS, BSD). bsdtar (libarchive) completion wrongly assumes that combining short options is not supported #1728 reports both entries and expects them to complete archives like gtar -tf .

  2. For a tar that strictly follows SUSv2 and rejects bundled short options, this change would complete files after -tf , a form that tar rejects; harmless, but wider than its syntax. I could not find a clean way to narrow it: enabling the normalization only for the bsdtar/star command names would miss the bare tar dispatch from bsdtar (libarchive) completion wrongly assumes that combining short options is not supported #1728, and the dispatch itself already selects "not GNU" rather than "POSIX".

  3. The BSD option surface (long options, -C, ...) is a larger gap. This PR only restores the argument completion of bundled short options, matching what the GNU path does with _comp_cmd_tar__cleanup_prev. I kept it to that; if the BSD options gap is worth tracking, I can open a separate issue.

I can rework this in a different direction if preferred.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bsdtar (libarchive) completion wrongly assumes that combining short options is not supported

2 participants