adaszko / complgen

Declarative bash/fish/zsh completions without writing shell scripts
Apache License 2.0
221 stars 7 forks source link

bug: `conditional binary operator expected` for BASH #55

Closed jameskim0987 closed 3 weeks ago

jameskim0987 commented 4 weeks ago

While experimenting with complgen, I noticed that when I try to source the output of complgen aot ..., I get the following error:

$ source mygrep.bash
-bash: mygrep.bash: line 127: conditional binary operator expected
-bash: mygrep.bash: line 127: syntax error near `"literal_transitions[$state]"'
-bash: mygrep.bash: line 127: `        if [[ -v "literal_transitions[$state]" ]]; then'

After some searching, it looks like all instances where -v is used in an if condition, it needs to be surrounded with [ ] instead of [[ ]]

All 7 instances for bash: https://github.com/adaszko/complgen/blob/56bd58aa278a6ddc412c926de15cdd38f4f3c355/src/aot/bash.rs#L123 https://github.com/adaszko/complgen/blob/56bd58aa278a6ddc412c926de15cdd38f4f3c355/src/aot/bash.rs#L132 https://github.com/adaszko/complgen/blob/56bd58aa278a6ddc412c926de15cdd38f4f3c355/src/aot/bash.rs#L144 https://github.com/adaszko/complgen/blob/56bd58aa278a6ddc412c926de15cdd38f4f3c355/src/aot/bash.rs#L442 https://github.com/adaszko/complgen/blob/56bd58aa278a6ddc412c926de15cdd38f4f3c355/src/aot/bash.rs#L449 https://github.com/adaszko/complgen/blob/56bd58aa278a6ddc412c926de15cdd38f4f3c355/src/aot/bash.rs#L469 https://github.com/adaszko/complgen/blob/56bd58aa278a6ddc412c926de15cdd38f4f3c355/src/aot/bash.rs#L493

I manually tried changing from [[ ]] to [ ] and it resolved the error.

TODOs:

  1. in the above 7 instances, replace the if condition [[ ]] to [ ]
adaszko commented 3 weeks ago

The cause of this looks the same as in https://github.com/adaszko/complgen/issues/56

jameskim0987 commented 3 weeks ago

Closing issue https://github.com/adaszko/complgen/issues/56#issuecomment-2395527245