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.
      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?

  • I'd guess you need to specify allowlist like mentioned here: github.com/bash-lsp/bash-language-server/blob/main/… Jun 20 at 7:39
  • Does it work the way you like if you use :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?
    – filbranden
    Jun 21 at 1:57
  • Unfortunately doesn't seem like changing either of these works :( as for the allowlist, I am not sure where to put it for lspconfig, but I tried a few options - putting it in setup({ settings = { ... }}) and putting it in setup({ ... }) directly... neither worked. Thanks for the effort :) would love more ideas
    – casraf
    Jun 22 at 10:46
  • bash and zsh have different semantics, so I'm not sure if what you want is even a good idea in the first place to be honest. Compare x=*; 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. Jun 23 at 17:53
  • Related issues: github.com/bash-lsp/bash-language-server/issues/252 and github.com/koalaman/shellcheck/issues/809zsh-sweep was mentioned as an alternative (I didn't read the entire thread so there may be others). I didn't try it, so I can't tell you if it's any good. Jun 23 at 17:57


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.