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
Bash completion nounset mode fixes #1351
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @scop - can you provide some further detail on the problem and what this fix accomplishes? I'm not sure there is a problem (or I just don't understand it yet!).
My understanding of the conditional -n
is:
-n string
True if the length of string is non-zero.
Regarding nounset
, I can see this possibly being a problem if those variables are unset, are people running their shells in this fashion? Again, any further context on this would be really helpful!
If we do this, I think I would prefer to see this format:
if [ -n "${ZSH_VERSION:-}" ]
But let me know if that won't work!
Yes. Mileages vary, but it's one good way of avoiding havoc caused by mistyping variable names.
It does work, but strictly speaking it's unnecessary/redundant: it substitutes not only unset values but also empty values with an empty value. The variant without the colon only substitutes unset values with an empty string, which captures the intent exactly without redundancy. Therefore I think that form is better, and also easier on the eye if you ask me ;) |
Ah, I was unaware of it, should have done a search, sorry about that. However what I'd do with that PR is just replace it in entirety with the contents of this one; this one is more complete and in my opinion more "correct" stylewise as discussed above. But I'll add a note there. |
@scop After discussion in the other PR we determined that |
That is another way to fix that part of the problem. Again, stylewise kind of worse way if you ask me, but also again, I don't care too deeply about the "how" as long as the fixes end up in the tree in one form or another. |
On a 2nd thought, I'll call it a tie, because all existing variable "declarations" in the generated code are already initiliazing the variable to something, so for consistency it's ok to initialize these to the empty string. |
Great discussion! I'll go ahead and close this and address the existing PR - thanks again for the contribution!! |
I'm not sure if this is complete, but it addresses some low hanging fruits related to nounset mode bash.