From 99c9076713433a49fb23182375c0d2e0cc1bf52e Mon Sep 17 00:00:00 2001 From: Dave Gallant Date: Sat, 26 Jun 2021 20:23:13 -0400 Subject: [PATCH] zsh: add `enableSyntaxHighlighting` option Add a simple way to enable syntax highlighting for zsh using https://github.com/zsh-users/zsh-syntax-highlighting or https://github.com/zdharma/fast-syntax-highlighting. --- modules/programs/zsh.nix | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/modules/programs/zsh.nix b/modules/programs/zsh.nix index 896e4fe83fa9..5a8f25b28f63 100644 --- a/modules/programs/zsh.nix +++ b/modules/programs/zsh.nix @@ -34,6 +34,11 @@ let vicmd = "bindkey -a"; }; + highlighters = { + zsh-fast-syntax-highlighting = "source ${pkgs.zsh-fast-syntax-highlighting}/share/zsh/site-functions/fast-syntax-highlighting.plugin.zsh"; + zsh-syntax-highlighting = "source ${pkgs.zsh-syntax-highlighting}/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh"; + }; + stateVersion = config.home.stateVersion; historyModule = types.submodule ({ config, ... }: { @@ -290,6 +295,17 @@ in description = "Enable zsh autosuggestions"; }; + syntaxHighlighting = { + enable = mkOption { + default = false; + description = "Enable syntax highlighting"; + }; + highlighter = mkOption { + default = "zsh-syntax-highlighting"; + description = "The package name of the highlighter"; + }; + }; + history = mkOption { type = historyModule; default = {}; @@ -482,6 +498,10 @@ in "source ${pkgs.zsh-autosuggestions}/share/zsh-autosuggestions/zsh-autosuggestions.zsh" } + ${optionalString cfg.syntaxHighlighting.enable + highlighters."${cfg.syntaxHighlighting.highlighter}" + } + # Environment variables . "${config.home.profileDirectory}/etc/profile.d/hm-session-vars.sh" ${envVarsStr}