Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(*sum): handle more common checksum filenames #1348

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions completions/sha256sum
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,20 @@ _comp_cmd_sha256sum()

local sumtype=${1##*/}
sumtype=${sumtype%sum}
local sumglob="@(*.$sumtype|@(check|${sumtype})sums?(.txt))"

local opt
local files opt
for opt in "${words[@]}"; do
if [[ $opt == -@(c|-check) ]]; then
_comp_compgen_filedir "$sumtype"
_comp_compgen -v files filedir &&
_comp_compgen -- -X "!$sumglob" -W '"${files[@]}"'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This filters out directory names generated by _comp_compgen_filedir, but we might want to generate also directory names.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, true, drafting until fixed.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I mentioned in #1358 (comment) a bit, I'm currently thinking of extending _comp_compgen_filedir to accept options to specify the whole glob pattern (instead of just the filename-extension part).

return
fi
done

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

Expand Down
1 change: 1 addition & 0 deletions test/fixtures/sha256sum/checksums
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 foo
1 change: 1 addition & 0 deletions test/fixtures/sha256sum/checksums.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 foo
1 change: 1 addition & 0 deletions test/fixtures/sha256sum/sha256sums
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 foo
1 change: 1 addition & 0 deletions test/fixtures/sha256sum/sha256sums.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 foo
8 changes: 7 additions & 1 deletion test/t/test_sha256sum.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@ def test_summing(self, completion):

@pytest.mark.complete("sha256sum -c ", cwd="sha256sum")
def test_checking(self, completion):
assert completion == "foo.sha256"
assert completion == [
"checksums",
"checksums.txt",
"foo.sha256",
"sha256sums",
"sha256sums.txt",
]