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

fix: quote boolean command names such as if "$boolean_variable"; then #914

Closed
wants to merge 6 commits into from

Conversation

akinomyoga
Copy link
Collaborator

@akinomyoga akinomyoga commented Apr 3, 2023

I have created this branch after #891 (comment) but left it for about one month. Now there was a related discussion in #910 (comment), so I decided to submit it here.

edit: This branch also includes other fixes: 7b6fb48, e731fc4, 7971f50

@akinomyoga akinomyoga force-pushed the boolean-test branch 2 times, most recently from 71ed5f1 to 938e466 Compare April 8, 2023 04:53
@akinomyoga
Copy link
Collaborator Author

akinomyoga commented Apr 8, 2023

I decided to separate the change $split && return to "$split" && return to another PR #918 for easier review.

@akinomyoga akinomyoga changed the title Quote boolean command names (such as if "$boolean_variable"; then and "$split" && return) fix: quote boolean command names such as if "$boolean_variable"; then Apr 8, 2023
@@ -806,7 +806,7 @@ _comp_delimited()
fi
[[ $cur == *$delimiter* ]] && prefix=${cur%"$delimiter"*}$delimiter

if $deduplicate; then
if "$deduplicate"; then
Copy link
Owner

@scop scop Apr 3, 2023

Choose a reason for hiding this comment

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

Ouch. I had written this last week, but forgot to click "Review changes", so the comment was left in pending state. Sorry! Anyway, here goes.


I can't say I'm too enthusiastic about this at least in cases where we are in complete control of the variable's contents.

I can see how this would be necessary to make things work in some crazy $IFS cases, but I believe the codebase is riddled with things that would break with them (this PR's just scratching the surface), and I'm not convinced we should try and support everything one might want to throw at it. I suppose there was a PR somewhere (which I've likely failed to follow up with) that would ensure a desired environment at start of a completion -- that would sound much preferable over this approach to me.

To me, reading if "$something"; then raises the question "was this supposed to be if [[ "$something" ]]; then" (even though the quotes within the square brackets are superfluous) and thus makes the code heavier to read. Also I'm quite convinced that it will take me a long time until I learn to take this into account, and there's no tool to fix it up or warn me. And even if I did learn it, I can't say I'd like it.

I'm leaning towards that we either don't do anything about this at all, or switch to comparing variable values instead of invoking boolean commands they contain, similarly as we did e.g. for the _known_hosts_real $ipv4 and $ipv6 cases below before this change. I think I'd prefer the string set might as a "set" marker better than 1 or true to clearly differentiate from the boolean commands and arithmetic context, but that's a bit besides the point, but in case we're modifying these anyway...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I suppose there was a PR somewhere (which I've likely failed to follow up with) that would ensure a desired environment at start of a completion -- that would sound much preferable over this approach to me.

PR #739 and Issue #786 are related. PR #739 contains unrelated long discussions, but the current situation is summarized in the following two comments:

To me, reading if "$something"; then raises the question "was this supposed to be if [[ "$something" ]]; then" (even though the quotes within the square brackets are superfluous) and thus makes the code heavier to read.

I actually prefer [[ $something ]] with something being an empty/non-empty variable. The reason that I decided to switch to this direction was item 2 in the review comment #891 (review). Might I have misread the comment? Anyway, if you would like to switch to [[ $something ]], I will adjust them.

Copy link
Owner

Choose a reason for hiding this comment

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

I actually prefer [[ $something ]] with something being an empty/non-empty variable. The reason that I decided to switch to this direction was item 2 in the review comment #891 (review). Might I have misread the comment?

You've got it right. My opinion is still that if $something; then reads cleaner than if [[ $something ]]; then. But per reasoning here, we can't have the former if we want to protect against funky $IFS. And I think if "$something"; then with the quotes is so weird that I prefer if [[ $something ]]; then over that.

Anyway, if you would like to switch to [[ $something ]], I will adjust them.

Yes, please. I'd also suggest using literal set as the value when the variable is set, instead of true, 1 or the like.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, please. I'd also suggest using literal set as the value when the variable is set, instead of true, 1 or the like.

I reworked them so decided to submit them as another PR #931.

completions/lzip Outdated Show resolved Hide resolved
akinomyoga added a commit to akinomyoga/bash-completion that referenced this pull request Apr 10, 2023
The original codes before PR 862,

https://github.com/scop/bash-completion/pull/862/files#diff-87387e55a9536f7ac2aa5fce39d9a0442c29ec2058215563388d5a284a9ac1c1L15-R24

were already broken.  According to the man page of lzip, lzip supports
separate options `--decompress` and `-d`, but there are no options
`--decompress-d` or `--decompress-...d`.  In this patch, we separate
these unexpectedly combined option names.

Reference:

scop#914 (comment)

Co-authored-by: Ville Skyttä <[email protected]>
akinomyoga added a commit to akinomyoga/bash-completion that referenced this pull request Apr 16, 2023
The original codes before PR 862,

https://github.com/scop/bash-completion/pull/862/files#diff-87387e55a9536f7ac2aa5fce39d9a0442c29ec2058215563388d5a284a9ac1c1L15-R24

were already broken.  According to the man page of lzip, lzip supports
separate options `--decompress` and `-d`, but there are no options
`--decompress-d` or `--decompress-...d`.  In this patch, we separate
these unexpectedly combined option names.

Reference:

scop#914 (comment)

Co-authored-by: Ville Skyttä <[email protected]>
scop added a commit that referenced this pull request Apr 21, 2023
The original codes before PR 862,

https://github.com/scop/bash-completion/pull/862/files#diff-87387e55a9536f7ac2aa5fce39d9a0442c29ec2058215563388d5a284a9ac1c1L15-R24

were already broken.  According to the man page of lzip, lzip supports
separate options `--decompress` and `-d`, but there are no options
`--decompress-d` or `--decompress-...d`.  In this patch, we separate
these unexpectedly combined option names.

Reference:

#914 (comment)

Co-authored-by: Ville Skyttä <[email protected]>
@akinomyoga
Copy link
Collaborator Author

akinomyoga commented Apr 22, 2023

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.

2 participants