Most of my dotfile scripts are in zsh
, with the .zsh
extension and shebang - #!/usr/bin/env zsh
.
Formatting and linting does not work in zsh files out of the box (understandably so); however, they can still be very useful for these files.
I would like to treat them as if they were bash files for formatting/linting purposes.
When changing the shebang to use bash
instead, it all works. But I would like to keep the shebang as-is.
- I tried changing the config but I am not sure which settings to change. The documentation for lspconfig bashls doesn't
show all the available values for override so I'm not sure what to
update.
lspconfig.bashls.setup({ filetypes = { "sh", "zsh" } })
- I also tried exporting
SHELLCHECK_OPTS='--shell=bash'
to force it on the user level but it doesn't seem like shellcheck is reading this when being run in vim, although the docs specify something like this should work.
In fact, I'm not sure what exactly I should update - I know both shellcheck and bashls are installed via Mason. I am not sure how to configure them and which needs the attention.
Is it maybe actually neovim that does the detection, so I should add an ftdetect
entry to handle this?
Can anyone shed some light and point me in the right direction?
allowlist
like mentioned here: github.com/bash-lsp/bash-language-server/blob/main/…:let g:is_bash = 1
and then after opening one of the zsh files you use:set filetype=sh
? I guess one way to getting bash-like features on your zsh files is treating them as actual bash. If that works, then we can find a way to configure that as a more permanent configuration, to do so automatically every time you open them. What do you think?setup({ settings = { ... }})
and putting it insetup({ ... })
directly... neither worked. Thanks for the effort :) would love more ideasx=*; echo $x
in bash and zsh for example. Arrays work different, builtins are different, and many other things. shellcheck doesn't even parse my~/.zshrc
, and after I fixed a few "syntax errors" I got many spurious warnings that don't apply to zsh. It's your editor, but I think it will be very confusing.