This is an experimental Tree-sitter grammar for Direnv files (.envrc). The
goal is to provides syntax highlighting and parsing for Direnv files, including:
- Direnv-specific functions (
has,use,layout, etc.) - Path manipulation functions (
PATH_add,source_env, etc.) - Shell scripting constructs
- Variable expansions and command substitutions
- Comments and strings
without using editor-specific syntax files, such as a syntax.vim. This
project was designed to be used alongside my Neovim plugin for Direnv, but
should work fine with any editor that supports Tree-sitter directly. If you are
knowledgable in other editors, feel free to update the documentation for your
own editor below!
Important
tree-sitter-direnv is alpha quality software. While it should work as intended, and is very unlikely to destroy anything you are almost guaranteed to run into bugs and general annoyances. Testing is welcome and appreciated, but please expect bugs and remember to report them accordingly!
git clone https://github.com/notashelf/tree-sitter-direnv.git
cd tree-sitter-direnv
# You will need the tree-sitter CLI installed.
tree-sitter buildAdd the following to your Neovim configuration:
require('nvim-treesitter.configs').setup {
ensure_installed = { "direnv" },
highlight = {
enable = true,
},
}Note
Emacs support is best effort. I use Neovim, and below configuration was inferred from online documentation.
(add-to-list 'tree-sitter-major-mode-language-alist '(direnv-mode . direnv))tree-sitter buildtree-sitter testtree-sitter generateThis project is made available under Mozilla Public License (MPL) version 2.0. See LICENSE for more details on the exact conditions. An online copy is provided here.