Skip to content

Commit 6cc313f

Browse files
committed
feat(*sum): handle more common checksum filenames
checksums, checksums.txt, ${sumtype}sums, ${sumtype}sums.txt
1 parent a5baa03 commit 6cc313f

File tree

7 files changed

+17
-6
lines changed

7 files changed

+17
-6
lines changed

completions/sha256sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ _comp_cmd_sha256sum()
2020

2121
local sumtype=${1##*/}
2222
sumtype=${sumtype%sum}
23+
local sumglob="@(*.$sumtype|@(check|${sumtype})sums?(.txt))"
24+
compopt -o filenames
2325

2426
local opt
2527
for opt in "${words[@]}"; do
2628
if [[ $opt == -@(c|-check) ]]; then
27-
_comp_compgen_filedir "$sumtype"
29+
_comp_compgen -- -f -X "!$sumglob" -o plusdirs
2830
return
2931
fi
3032
done
3133

32-
local files
33-
_comp_compgen -v files filedir &&
34-
_comp_compgen -- -X "*.$sumtype" -W '"${files[@]}"'
34+
_comp_compgen -- -f -X "$sumglob" -o plusdirs
3535
} &&
3636
complete -F _comp_cmd_sha256sum b2sum cksum md5sum \
3737
sha{,1,224,256,384,512}sum

test/fixtures/sha256sum/checksums

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 foo
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 foo

test/fixtures/sha256sum/dir/.gitignore

Whitespace-only changes.

test/fixtures/sha256sum/sha256sums

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 foo
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 foo

test/t/test_sha256sum.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,15 @@ def test_options(self, completion):
88

99
@pytest.mark.complete("sha256sum ", cwd="sha256sum")
1010
def test_summing(self, completion):
11-
assert completion == "foo"
11+
assert completion == ["dir/", "foo"]
1212

1313
@pytest.mark.complete("sha256sum -c ", cwd="sha256sum")
1414
def test_checking(self, completion):
15-
assert completion == "foo.sha256"
15+
assert completion == [
16+
"checksums",
17+
"checksums.txt",
18+
"dir/",
19+
"foo.sha256",
20+
"sha256sums",
21+
"sha256sums.txt",
22+
]

0 commit comments

Comments
 (0)