I recently ran in trouble with an
command executed in a shell expansion, and in which the string started with a dash (-). Even single quotes around the string did not stop Kakoune from interpreting it as an illegal switch to
exec and raising an error. Fortunately there is a way around, using two dashes
-- to signal switch ending
exec -- "$string"
as in the case of many standard Unix commands. This also works with Kakoune commands that accept switches, such as
I have seen this trick used in a few script examples, but I have not seen it documented anywhere. If I am right about the lack of documentation, then this post with its title may be helpful to Kakoune newcomers.
Is it shell
exec or kakoune
I tested it and I can replicate the same issue with kakoune’s
execute-keys. In all these cases,
- is interpreted as option prefix:
and as it was said in original post, this is the solution that works:
execute-keys -- -
I was confused by the shell variable in original post. I was also experncing the same problem once, and didn’t seem any mention of that feature in docks back then
Sorry about the confusion, this is indeed Kakoune’s command
I use the
exec alias in Kakoune’s shell expansions because the line is more concise, for example:
printf '%s' "exec -- $sequence_of_keys"
to insert a string of dashes in Insert mode.
But what I said applies to other Kakoune commands that accept switches. For example, typing this at Kakoune’s command prompt:
will raise an error:
'echo' unknown option '-hello'
Now try this:
echo -- '-hello'
No error is raised.
In my next post I’ll send a short script in which this issue with dashes arose.