vaeth / zram-init

A wrapper script for the zram linux kernel module with zsh and openrc support
http://www.mathematik.uni-wuerzburg.de/~vaeth/download/index.html#zram-init
79 stars 25 forks source link

Strange ''bad subsitution" error when zsh-completing on openrc zram-init file #31

Closed hhoffstaette closed 3 years ago

hhoffstaette commented 3 years ago

I just installed zram-init on Gentoo and while everything is working fine (thank you!), I've been puzzled by a strange zsh completion error for the init script that I really don't understand:

$/etc/init.d/zram-init <TAB>
_init_d:130: bad substitution

The _init_d completer is the stock zsh-5.8 script, and the line that complains is the first one in the followign block where it parses the script for commands:

# If we didn't get $cmds from a zstyle, then read init script for opts.
# If script doesn't specify opts, then default to the standard opts.
(( $#cmds )) || cmds=( ${(eQz)${(M)${(f)"$( <$script)"}:#[[:blank:]]#opts=*}#*=} )
(( $#cmds )) || cmds=($opts)

After a lot of trial and error I managed to trace the problem to the ZramIgnore() function and first suspected the use of eval. However as it turns out this is not the case; the only problem is the use of the opts identifier here. Renaming the field to options lets the completer pass without error. Apparently the field name and the completion parser conflict on the identifier name, which is all sorts of terrible for a parser. Was wondering if you have any suggestions. Maybe it's just a matter of quoting and/or identifier expansion?

vaeth commented 3 years ago

Thanks for the report. Should be fixed in zsh-10.8.

hhoffstaette commented 3 years ago

While the commit probably does fix an issue with zram-init's own zsh-completion for the zram-init command, it's not the one I reported above. The above issue reproduces also when the _zram-init completion is not installed at all.

hhoffstaette commented 3 years ago

Btw if you think this is a bug in zsh's _init_d completion please let me know and I'll go bug them instead. :)

vaeth commented 3 years ago

The whole approach of parsing a script like this might be considered a bug, but it is probably among the best they can do. Anyway, let's work around this problem. I would not like to rename the variable, so I hope putting the assignment not at the beginning is sufficient (at least my tests indicated that opts is not set in the completion afterwards). Hopefully really “fixed” now in 10.9