Skip to content

k8s-1/bashls

Repository files navigation

bashls

CI crates.io

A Rust alternative to bash-language-server, shipped as a single binary with no Node.js and minimal runtime dependencies.

bashls demo

Motivation

bash-language-server errors had pushed my logs past 1 GB. My editor was slowing down. I wanted something self-contained.

Features

  • Hover documentation
  • Completions (variables, functions, executables, builtins, snippets)
  • Jump to definition
  • Find references
  • Rename
  • Document and workspace symbols
  • Diagnostics via shellcheck
  • Formatting via shfmt

Installation

Diagnostics and formatting require additional tools:

Binary

Download from releases page, extract, and place bashls somewhere on your $PATH.

Cargo

cargo install bashls

From source

git clone https://github.com/k8s-1/bashls
cd bashls
cargo build --release

Editor support

bashls works with any editor that supports LSP.

Neovim

vim.lsp.config('bashls', {
  cmd = { 'bashls' },
  filetypes = { 'sh' },
  root_markers = { '.git' },
  -- init_options = {
  --   bashIde = { shellcheckPath = '/usr/bin/shellcheck' },
  -- },
})
vim.lsp.enable('bashls')

Helix

[[language]]
name = "bash"
language-servers = ["bashls"]

[language-server.bashls]
command = "bashls"

Zed

{
  "lsp": {
    "bash-language-server": {
      "binary": {
        "path": "bashls",
      }
    }
  }
}

Emacs

(add-to-list 'eglot-server-programs
             '(sh-mode . ("bashls")))

Configuration

Settings can be provided as LSP initialization options (under bashIde) or as environment variables (e.g. bashIde.shellcheckPathSHELLCHECK_PATH).

Setting (bashIde.*) Default Description
shellcheckPath shellcheck Path to shellcheck binary. Set to empty string to disable.
shellcheckArguments [] Additional arguments passed to shellcheck.
shfmt.path shfmt Path to shfmt binary. Set to empty string to disable.
shfmt.* See shfmt for remaining options.
globPattern **/*@(.sh|.inc|.bash|.command) Files the server treats as bash.
backgroundAnalysisMaxFiles 500 Max files to analyse in background for workspace-wide features.
includeAllWorkspaceSymbols false Return functions and variables from all workspace files in symbol search, not just open files.
enableSourceErrorDiagnostics false Show diagnostics when a source/. command cannot be resolved.
logLevel info Log level.

Limitations

  • No explainshell integration. Supporting this would require pulling in an HTTP/TLS stack (~50 crates); skipped intentionally to keep the dependency footprint small.
  • Linux and macOS only. This is a bash language server — if you're on Windows, use WSL.

Benchmarks

Measured against bash-language-server 5.6.0 using 50 .sh files from oh-my-bash as a corpus. Startup is measured cold (no prior Node.js activity); 1600 ms is the minimum observed across runs (average ~2600 ms). See examples/lsp_bench.rs for the full methodology and instructions to reproduce.

Benchmark results comparing bashls to bash-language-server.

License

This project is released under the MIT License.

About

A Rust alternative to bash-language-server, shipped as a single binary with no Node.js and minimal runtime dependencies.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages