Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expand tilde to home-directory for language formatter command args #5538

Closed
mike-kfed opened this issue Jan 15, 2023 · 6 comments
Closed

expand tilde to home-directory for language formatter command args #5538

mike-kfed opened this issue Jan 15, 2023 · 6 comments
Labels
A-helix-term Area: Helix term improvements C-enhancement Category: Improvements

Comments

@mike-kfed
Copy link

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.

@mike-kfed mike-kfed added the C-enhancement Category: Improvements label Jan 15, 2023
@mike-kfed mike-kfed changed the title expand tilde to homedirectory for language formatter commands expand tilde to home-directory for language formatter command args Jan 15, 2023
@mike-kfed
Copy link
Author

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.

@kirawi
Copy link
Member

kirawi commented Jan 15, 2023

I suppose we could use either [editor.shell] so the shell expands the tilde, or use the function in helix-core::path

@kirawi kirawi added the A-helix-term Area: Helix term improvements label Jan 15, 2023
@mike-kfed
Copy link
Author

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.

@artfulrobot
Copy link

linked? #7624

@mike-kfed
Copy link
Author

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.

@yozachar
Copy link

yozachar commented Jul 5, 2024

For clang-format, I did

formatter = { command = "bash", args = ["-c", "clang-format --style=file:$HOME/.config/clang-format" ] }

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-helix-term Area: Helix term improvements C-enhancement Category: Improvements
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants