Skip to content

Commit c94bebb

Browse files
committed
fix(tar): Complete added files with long opts
Currently when using long options, we don't complete files to add to the archive, but show options. Handle long options in tar_mode to fix this. Fixes #98
1 parent e209afb commit c94bebb

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

completions/tar

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,11 @@ _comp_cmd_tar__preparse_cmdline()
203203

204204
for i in "$@"; do
205205
case "$i" in
206-
--delete | --test-label)
206+
--delete | --test-label | --catenate | --concatenate | --extract | --get | --update | --list | --append | --create)
207207
tar_mode=${i:2:100}
208-
tar_mode_arg=$i
208+
# FIXME: We don't set $tar_mode_arg since it's used for combined
209+
# single letter options, but that means we don't handle
210+
# compression formats.
209211
break
210212
;;
211213
--*)
@@ -236,7 +238,7 @@ _comp_cmd_tar__file_option()
236238
local ext="$1"
237239

238240
case "$tar_mode" in
239-
c)
241+
c | create)
240242
# no need to advise user to re-write existing tarball
241243
_comp_compgen_filedir -d
242244
;;
@@ -391,7 +393,7 @@ _comp_cmd_tar__adjust_PREV_from_old_option()
391393
_comp_cmd_tar__extract_like_mode()
392394
{
393395
local i
394-
for i in x d t delete; do
396+
for i in x d t delete extract get list; do
395397
[[ $tar_mode == "$i" ]] && return 0
396398
done
397399
return 1
@@ -455,7 +457,7 @@ _comp_cmd_tar__detect_ext()
455457

456458
case "$tar_mode_arg" in
457459
--*)
458-
# Should never happen?
460+
# FIXME: get correct extensions for long options (gnu style)
459461
;;
460462
?(-)*[cr]*f)
461463
ext='@(tar|gem|spkg|cbt|xpbs)'
@@ -490,7 +492,7 @@ _comp_cmd_tar__gnu()
490492
tar_mode tar_mode_arg old_opt_progress="" \
491493
old_opt_used="" old_opt_parsed=()
492494

493-
# Main mode, e.g. -x or -c (extract/creation)
495+
# Main mode, e.g. "x" or "c" or the long forms "extract" or "create"
494496
local tar_mode=none
495497

496498
# The mode argument, e.g. -cpf or -c
@@ -685,8 +687,6 @@ _comp_cmd_tar__posix()
685687

686688
_comp_initialize -s -- "$@" || return
687689

688-
tar_mode=none
689-
690690
# relatively compatible modes are {c,t,x}
691691
# relatively compatible options {b,f,m,v,w}
692692
short_arg_req="fb"

test/t/test_tar.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,9 @@ def test_22(self, bash, completion):
117117
"""Test listing escaped chars in old option."""
118118
assert completion == "c/"
119119

120+
# Test long options (gnu style)
121+
@pytest.mark.complete("tar --create --file created.tar ", cwd="tar")
122+
def test_23(self, completion):
123+
assert completion == "archive.tar.xz dir/ dir2/ escape.tar".split()
124+
120125
# TODO: "tar tf escape.tar a/b"

0 commit comments

Comments
 (0)