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>
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

1 participant