Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

bash-language-server

bash-lsp34.2kMIT5.6.0TypeScript support: included

A language server for Bash

readme

Bash Language Server

Bash language server that brings an IDE-like experience for bash scripts to most editors. This is based on the Tree Sitter parser and supports explainshell, shellcheck and shfmt.

Documentation around configuration variables can be found in the config.ts file.

Features

  • Jump to declaration
  • Find references
  • Code Outline & Show Symbols
  • Highlight occurrences
  • Code completion
  • Simple diagnostics reporting
  • Documentation for symbols on hover
  • Workspace symbols
  • Rename symbol
  • Format document

To be implemented:

  • Better jump to declaration and find references based on scope

Installation

Dependencies

As a dependency, we recommend that you first install shellcheck to enable linting: https://github.com/koalaman/shellcheck#installing . If shellcheck is installed, bash-language-server will automatically call it to provide linting and code analysis each time the file is updated (with debounce time of 500ms).

If you want your shell scripts to be formatted consistently, you can install shfmt. If shfmt is installed then your documents will be formatted whenever you take the 'format document' action. In most editors this can be configured to happen automatically when files are saved.

Bash language server

Usually you want to install a client for your editor (see the section below).

But if you want to install the server binary (for examples for editors, like helix, where a generic LSP client is built in), you can install from npm registry as:

npm i -g bash-language-server

Alternatively, bash-language-server may also be distributed directly by your Linux distro, for example on Fedora based distros:

dnf install -y nodejs-bash-language-server

Or on Ubuntu with snap:

sudo snap install bash-language-server --classic

To verify that everything is working:

bash-language-server --help

If you encounter installation errors, ensure you have node version 16 or newer (node --version).

Clients

The following editors and IDEs have available clients:

Vim

For Vim 8 or later install the plugin prabirshrestha/vim-lsp and add the following configuration to .vimrc:

if executable('bash-language-server')
  au User lsp_setup call lsp#register_server({
        \ 'name': 'bash-language-server',
        \ 'cmd': {server_info->['bash-language-server', 'start']},
        \ 'allowlist': ['sh', 'bash'],
        \ })
endif

For Vim 8 or Neovim using YouCompleteMe, add the following to .vimrc:

let g:ycm_language_server =
            \ [
            \   {
            \       'name': 'bash',
            \       'cmdline': [ 'bash-language-server', 'start' ],
            \       'filetypes': [ 'sh' ],
            \   }
            \ ]

For Vim 8 or Neovim using neoclide/coc.nvim, according to it's Wiki article, add the following to your coc-settings.json:

  "languageserver": {
    "bash": {
      "command": "bash-language-server",
      "args": ["start"],
      "filetypes": ["sh"],
      "ignoredRootPaths": ["~"]
    }
  }

For Vim 8 or NeoVim using dense-analysis/ale add the following configuration to your .vimrc:

let g:ale_linters = {
    \ 'sh': ['language_server'],
    \ }

Neovim

For Neovim v0.8:

vim.api.nvim_create_autocmd('FileType', {
  pattern = 'sh',
  callback = function()
    vim.lsp.start({
      name = 'bash-language-server',
      cmd = { 'bash-language-server', 'start' },
    })
  end,
})

For NeoVim using autozimu/LanguageClient-neovim, add the following configuration to init.vim:

let g:LanguageClient_serverCommands = {
    \ 'sh': ['bash-language-server', 'start']
    \ }

For Vim8/NeoVim v0.5 using jayli/vim-easycomplete. Execute :InstallLspServer sh and config nothing. Maybe it's the easiest way to use bash-language-server in vim/nvim.

Oni

On the config file (File -> Preferences -> Edit Oni config) add the following configuration:

"language.bash.languageServer.command": "bash-language-server",
"language.bash.languageServer.arguments": ["start"],

Emacs

Lsp-mode has a built-in client, can be installed by use-package. Add the configuration to your .emacs.d/init.el

(use-package lsp-mode
  :commands lsp
  :hook
  (sh-mode . lsp))

Using the built-in eglot lsp mode:

(use-package eglot
  :config
  (add-to-list 'eglot-server-programs '((sh-mode bash-ts-mode) . ("bash-language-server" "start")))

  :hook
  (sh-mode . eglot-ensure)
  (bash-ts-mode . eglot-ensure))

shfmt integration

The indentation used by shfmt is whatever has been configured for the current editor session, so there is no shfmt-specific configuration variable for this. If your editor is configured for two-space indents then that's what it will use. If you're using tabs for indentation then shfmt will use that.

The shfmt integration also supports configuration via .editorconfig. If any shfmt-specific configuration properties are found in .editorconfig then the config in .editorconfig will be used and the language server config will be ignored. This follows shfmt's approach of using either .editorconfig or command line flags, but not both. Note that only shfmt-specific configuration properties are read from .editorconfig - indentation preferences are still provided by the editor, so to format using the indentation specified in .editorconfig make sure your editor is also configured to read .editorconfig. It is possible to disable .editorconfig support and always use the language server config by setting the "Ignore Editorconfig" configuration variable.

Logging

The minimum logging level for the server can be adjusted using the BASH_IDE_LOG_LEVEL environment variable and through the general workspace configuration.

Development Guide

Please see docs/development-guide for more information.

changelog

Bash Language Server

5.4.3

5.4.2

  • Fix wrong pnpm engine version

5.4.1

  • Bump treesitter to latest version

5.4.0

5.3.4

5.3.3

5.3.2

5.3.1

5.3.0

5.2.0

5.1.2

5.1.1

5.1.0

5.0.0

4.10.3

4.10.2

4.10.1

  • Handle tree-sitter-bash parse errors gracefully

4.10.0

4.9.3

4.9.2

4.9.1

4.9.0

4.8.4

  • Make source error diagnostics ("Source command could not be analyzed") configurable with the enableSourceErrorDiagnostics flag.

4.8.3

4.8.2

4.8.1

4.8.0

4.7.0

4.6.2

4.6.1

4.6.0

4.5.5

4.5.4

4.5.3

4.5.2

4.5.1

4.5.0

4.4.0

4.3.2

4.3.0

4.2.5

4.2.4

  • Increase ShellCheck execution delay to 500ms after typing ends.

4.2.3

4.2.2

4.2.1

4.2.0

4.1.3

4.1.2

  • Correct ShellCheck source-path argument to support following sources based on the local folder of the file and the workspace root.

4.1.1

4.1.0

  • Symbols across files are now only included based on sourced files (using non dynamic statements like source file.sh or . ~/file.inc) instead of including symbols from all files in the workspace. We now also support jump-to-definition on the file path used in a source command. The new behavior can be disabled by turning on the includeAllWorkspaceSymbols configuration option. https://github.com/bash-lsp/bash-language-server/pull/244

4.0.1

  • Breaking: Drop support for Node 12, which reached its official end of life on April 30th 2022. Doing so enables new features. https://github.com/bash-lsp/bash-language-server/pull/584
  • ShellCheck: support code actions, remove duplicated error codes, add URLs and tags, support parsing dialects (sh, bash, dash, ksh) but still fallback to bash, enable configuring ShellCheck arguments using the shellcheckArguments configuration parameter (legacy environment variable: SHELLCHECK_ARGUMENTS)
  • Support workspace configuration instead of environment variables which enables updating configuration without reloading the server. We still support environment variables, but clients should migrate to the new workspace configuration. https://github.com/bash-lsp/bash-language-server/pull/599
  • Allow disabling background analysis by setting backgroundAnalysisMaxFiles: 0.

3.3.1

3.3.0

3.2.3

3.2.2

3.2.1

3.2.0

3.1.1

3.1.0

3.0.5

3.0.4

3.0.3

3.0.2

3.0.1

3.0.0

2.1.0

2.0.0

1.17.0

  • Default configuration change: parsing errors are not highlighted as problems (as the grammar is buggy)

1.16.1

1.16.0

1.15.0

1.14.0

1.13.1

1.13.0

1.12.0

1.11.3

1.11.2

1.11.1

  • Workspace symbols are resolved using fuzzy search (not just starting with it)

1.11.0

1.10.0

1.9.0

  • Skip analyzing files with a non-bash shebang

1.8.0

  • Extend file glob used for pre-analyzing files from **/*.sh to **/*@(.sh|.inc|.bash|.command)
  • Make file glob configurable with GLOB_PATTERN environment variable

1.7.0

  • Add PATH tilde expansion
  • Builtins and man pages formatting

1.6.1

  • Expose TypeScript typings from server
  • Update vscode-languageserver dependency

1.6.0

1.5.6

1.5.5

  • Upgrade tree-sitter from 0.13.5 to 0.13.22
  • Upgrade tree-sitter-bash from 0.13.3 to 0.13.7

1.5.4

1.5.3

  • Support for showing warning for missing nodes
  • Upgrade tree-sitter-bash to 0.13.3

1.5.2

  • Upgrade tree-sitter to 0.13.5 and tree-sitter-bash to 0.13.2

1.5.1

  • Upgrade tree-sitter and tree-sitter-bash
  • Fixed build issue with 1.5.0

1.5.0

  • Upgrade tree-sitter and tree-sitter-bash

1.4.1

  • It's now possible to disable error reporting by setting the environment variable HIGHLIGHT_PARSING_ERRORS to false.

1.4.0

1.3.1

  • More reliable NPM command execution on Windows #40

1.3.0

  • Improved completions by adding support for

    • Suggestions based on the programs on your PATH #17
    • Suggestions based on the bash builtins #33
  • Implemented the onHover message that now shows documentation for programs and builtins when you hover your cursor over words in the document. #17 #33

  • Improved outline hierarchy #31

  • Upgraded tree-sitter bash and other libraries. #28

1.1.2

Update tree-sitter to 0.10.0 and tree-sitter-bash to 0.6.0. This improves the Bash parser. There are still known parsing issues. For more information following the progress on this issue over at tree-sitter/tree-sitter-bash#9