helix
helix copied to clipboard
expand tilde to home-directory for language formatter command args
right now in my languages.toml
I have this:
formatter = { command = 'deno', args = ["fmt", "-", "--ext", "md", "--config", "/home/mike/.config/deno.json" ] }
however in order to be compatible to any environment I'd like to store this in my dotfiles repo:
formatter = { command = 'deno', args = ["fmt", "-", "--ext", "md", "--config", "~/.config/deno.json" ] }
reasoning:
- default formatting options for markdown of deno are not what I want
- my current hardcoded config path argument for deno works fine on my home-pc but for work my username is not mike and I am on macOS where my home is
/Users/kmike
, I'd like to share my configs hence tilde-expansion to homedir is needed
problem:
right now using tilde breaks calling the formatter because it tries to open $(cwd)/~/.config/deno.json
which does not exist.
I cannot come up with an easy fix for this, because blindly "replacing any tilde found at the beginning of a string in the args list with $HOME" likely breaks something else/is dangerous. Maybe add an extra field expand_args: bool
which when true does replace the ~
and by default it is false which means not doing anything like now?
Other way to fix this would be hacking deno to have a default global config file path?
Workaround, for deno only and ugly: omit the --config
arg and put the config file in ~/deno.json
it will find it by automatically looking into parent directories. However this is not a unix style config filename and therefore not nice.
I suppose we could use either [editor.shell]
so the shell expands the tilde, or use the function in helix-core::path
silly me, I can make it work myself right now like this:
formatter = { command = 'bash', args = ["-c", "deno fmt - --ext md --config ~/.config/deno.json" ] }
but yes using [editor.shell]
and having helix construct this ^^ for me would be convenient. If this bug stays open until after my vacation I'll give it a shot with a PR.
linked? https://github.com/helix-editor/helix/issues/7624
just a heads up for people looking for this tilde-expanding feature, it has not been implemented, the workaround calling your shell shown above is still needed. Which is fine by me, as calling the shell for every command is useless overhead, therefore configuring the shell invocation explicitly is preferable.