Skip to content

Commit 7fd8c79

Browse files
committed
feat(*sum): handle more common checksum filenames
checksums, checksums.txt, ${sumtype}sums, ${sumtype}sums.txt
1 parent 5ed9384 commit 7fd8c79

File tree

6 files changed

+16
-4
lines changed

6 files changed

+16
-4
lines changed

completions/sha256sum

+5-3
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,20 @@ _comp_cmd_sha256sum()
2020

2121
local sumtype=${1##*/}
2222
sumtype=${sumtype%sum}
23+
local sumglob=@(*.$sumtype|@(check|${sumtype})sums?(.txt))
2324

24-
local opt
25+
local files opt
2526
for opt in "${words[@]}"; do
2627
if [[ $opt == -@(c|-check) ]]; then
27-
_comp_compgen_filedir "$sumtype"
28+
_comp_compgen -v files filedir &&
29+
_comp_compgen -- -X "!$sumglob" -W '"${files[@]}"'
2830
return
2931
fi
3032
done
3133

3234
local files
3335
_comp_compgen -v files filedir &&
34-
_comp_compgen -- -X "*.$sumtype" -W '"${files[@]}"'
36+
_comp_compgen -- -X "$sumglob" -W '"${files[@]}"'
3537
} &&
3638
complete -F _comp_cmd_sha256sum b2sum md5sum sha{,1,224,256,384,512}sum
3739

test/fixtures/sha256sum/checksums

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 foo

test/fixtures/sha256sum/checksums.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 foo

test/fixtures/sha256sum/sha256sums

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 foo
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 foo

test/t/test_sha256sum.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,10 @@ def test_summing(self, completion):
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+
"foo.sha256",
19+
"sha256sums",
20+
"sha256sums.txt",
21+
]

0 commit comments

Comments
 (0)