skarnet / execline

The execline scripting language
https://skarnet.org/software/execline/
ISC License
151 stars 19 forks source link

Overriding "1" as elgetopt's default substitution #12

Closed capezotte closed 1 year ago

capezotte commented 1 year ago

I used to use a command-line utility called dmenu, but came to like an alternative to it called fuzzel that has the same input and output format but has slightly different options.

More specifically, dmenu had a -x option, but fuzzel's equivalent is called --password. -x in fuzzel does something completely different.

In order not to rewrite all my scripts using dmenu due to this small difference, I thought of making /usr/local/bin/dmenu an execline wrapper:

#!/bin/execlineb
elgetopt ixl:p:
multisubstitute {
    importas hide ELGETOPT_x
    importas lines ELGETOPT_l
    importas prompt ELGETOPT_p
}
emptyenv -c fuzzel -d --password$hide -l$lines -p$prompt

Here comes the problem. -l and -p work as intended (being omitted entirely if not given by the script), but when -x is given, it comes out as --password1 which is an invalid option.

The only alternatives I'm seeing are either

The solution I'm proposing is for 1 to be overrideable by the user. For instance, making elgetopt insert an empty word into the environment instead of 1 would make my script work.

skarnet commented 1 year ago

Yeah, I can see an option to elgetopt working here. I'll write that down for the next version of execline, thanks for the suggestion.

skarnet commented 1 year ago

Please try elgetopt -D "" with the latest execline git commit, and tell me if it's working for you.

capezotte commented 1 year ago

Works for me. Thanks!