From 2c663347ee679279eb2c1a1a466c1a3ee7129ce5 Mon Sep 17 00:00:00 2001 From: Noah Masur <7386960+nmasur@users.noreply.github.com> Date: Sun, 9 Jul 2023 14:50:41 -0600 Subject: [PATCH] inject bash highlighting in nix shell scripts --- flake.nix | 1 + modules/common/neovim/config/syntax.nix | 19 ++++++++++++++----- .../plugin/after/queries/nix/injections.scm | 8 ++++++++ overlays/tree-sitter-bash.nix | 16 ++++++++++++++++ 4 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 modules/common/neovim/plugin/after/queries/nix/injections.scm create mode 100644 overlays/tree-sitter-bash.nix diff --git a/flake.nix b/flake.nix index 99f9f5e..8cf02a2 100644 --- a/flake.nix +++ b/flake.nix @@ -144,6 +144,7 @@ (import ./overlays/neovim-plugins.nix inputs) (import ./overlays/calibre-web.nix) (import ./overlays/disko.nix inputs) + (import ./overlays/tree-sitter-bash.nix) ]; # System types to support. diff --git a/modules/common/neovim/config/syntax.nix b/modules/common/neovim/config/syntax.nix index d30d342..04c8964 100644 --- a/modules/common/neovim/config/syntax.nix +++ b/modules/common/neovim/config/syntax.nix @@ -3,19 +3,28 @@ plugins = [ (pkgs.vimPlugins.nvim-treesitter.withPlugins (_plugins: with pkgs.tree-sitter-grammars; [ - tree-sitter-hcl - tree-sitter-python - tree-sitter-lua - tree-sitter-nix + tree-sitter-bash tree-sitter-fish + tree-sitter-hcl + tree-sitter-json + tree-sitter-lua + tree-sitter-markdown + tree-sitter-markdown-inline + tree-sitter-nix + tree-sitter-python tree-sitter-toml tree-sitter-yaml - tree-sitter-json ])) pkgs.vimPlugins.vim-matchup # Better % jumping in languages + pkgs.vimPlugins.playground # Tree-sitter experimenting pkgs.vimPlugins.nginx-vim pkgs.vimPlugins.vim-helm pkgs.vimPlugins.vim-puppet + (pkgs.vimUtils.buildVimPluginFrom2Nix { + pname = "nmasur"; + version = "0.1"; + src = ../plugin; + }) ]; setup."nvim-treesitter.configs" = { diff --git a/modules/common/neovim/plugin/after/queries/nix/injections.scm b/modules/common/neovim/plugin/after/queries/nix/injections.scm new file mode 100644 index 0000000..2274126 --- /dev/null +++ b/modules/common/neovim/plugin/after/queries/nix/injections.scm @@ -0,0 +1,8 @@ +expression: (apply_expression + function: (apply_expression + function: (select_expression + attrpath: (attrpath) @writeshell (#match? @writeshell "^writeShell.*$") + ) + ) + (indented_string_expression) @bash +) diff --git a/overlays/tree-sitter-bash.nix b/overlays/tree-sitter-bash.nix new file mode 100644 index 0000000..911b063 --- /dev/null +++ b/overlays/tree-sitter-bash.nix @@ -0,0 +1,16 @@ +# Fix: bash highlighting doesn't work as of this commit: +# https://github.com/NixOS/nixpkgs/commit/49cce41b7c5f6b88570a482355d9655ca19c1029 + +_final: prev: { + tree-sitter-grammars = prev.tree-sitter-grammars // { + tree-sitter-bash = prev.tree-sitter-grammars.tree-sitter-bash.overrideAttrs + (old: { + src = prev.fetchFromGitHub { + owner = "tree-sitter"; + repo = "tree-sitter-bash"; + rev = "493646764e7ad61ce63ce3b8c59ebeb37f71b841"; + sha256 = "sha256-gl5F3IeZa2VqyH/qFj8ey2pRbGq4X8DL5wiyvRrH56U="; + }; + }); + }; +}