From 0a12aafde42ddecfd268a21aa6ada4c0946cd30f Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Sun, 23 Apr 2017 21:17:31 +0200 Subject: zsh-syntax-highlighting: Add more configuration options and move to module (#25153) * programs.zsh: factor zsh-syntax-highlighting out into its own module * programs.zsh.syntax-highlighting: add `highlighters` option * programs.zsh: document BC break introduced by moving zsh-syntax-completion into its own module --- nixos/modules/module-list.nix | 1 + .../programs/zsh/zsh-syntax-highlighting.nix | 43 ++++++++++++++++++++++ nixos/modules/programs/zsh/zsh.nix | 16 +------- nixos/modules/rename.nix | 3 ++ 4 files changed, 48 insertions(+), 15 deletions(-) create mode 100644 nixos/modules/programs/zsh/zsh-syntax-highlighting.nix (limited to 'nixos') diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 6e99ead5862..4ff069f48ab 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -104,6 +104,7 @@ ./programs/xonsh.nix ./programs/zsh/oh-my-zsh.nix ./programs/zsh/zsh.nix + ./programs/zsh/zsh-syntax-highlighting.nix ./rename.nix ./security/acme.nix ./security/apparmor.nix diff --git a/nixos/modules/programs/zsh/zsh-syntax-highlighting.nix b/nixos/modules/programs/zsh/zsh-syntax-highlighting.nix new file mode 100644 index 00000000000..962c1f920a8 --- /dev/null +++ b/nixos/modules/programs/zsh/zsh-syntax-highlighting.nix @@ -0,0 +1,43 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.programs.zsh.syntax-highlighting; +in + { + options = { + programs.zsh.syntax-highlighting = { + enable = mkOption { + default = false; + type = types.bool; + description = '' + Enable zsh-syntax-highlighting. + ''; + }; + + highlighters = mkOption { + default = [ "main" ]; + type = types.listOf(types.str); + description = '' + Specifies the highlighters to be used by zsh-syntax-highlighting. + + The following defined options can be found here: + https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters.md + ''; + }; + }; + }; + + config = mkIf cfg.enable { + environment.systemPackages = with pkgs; [ zsh-syntax-highlighting ]; + + programs.zsh.interactiveShellInit = with pkgs; with builtins; '' + source ${zsh-syntax-highlighting}/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh + + ${optionalString (length(cfg.highlighters) > 0) + "ZSH_HIGHLIGHT_HIGHLIGHTERS=(${concatStringsSep " " cfg.highlighters})" + } + ''; + }; + } diff --git a/nixos/modules/programs/zsh/zsh.nix b/nixos/modules/programs/zsh/zsh.nix index a39c06c0913..acb3e987aee 100644 --- a/nixos/modules/programs/zsh/zsh.nix +++ b/nixos/modules/programs/zsh/zsh.nix @@ -84,14 +84,6 @@ in type = types.bool; }; - enableSyntaxHighlighting = mkOption { - default = false; - description = '' - Enable zsh-syntax-highlighting - ''; - type = types.bool; - }; - enableAutosuggestions = mkOption { default = false; description = '' @@ -99,7 +91,6 @@ in ''; }; - }; }; @@ -131,10 +122,6 @@ in ${if cfg.enableCompletion then "autoload -U compinit && compinit" else ""} - ${optionalString (cfg.enableSyntaxHighlighting) - "source ${pkgs.zsh-syntax-highlighting}/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" - } - ${optionalString (cfg.enableAutosuggestions) "source ${pkgs.zsh-autosuggestions}/share/zsh-autosuggestions/zsh-autosuggestions.zsh" } @@ -206,8 +193,7 @@ in environment.etc."zinputrc".source = ./zinputrc; environment.systemPackages = [ pkgs.zsh ] - ++ optional cfg.enableCompletion pkgs.nix-zsh-completions - ++ optional cfg.enableSyntaxHighlighting pkgs.zsh-syntax-highlighting; + ++ optional cfg.enableCompletion pkgs.nix-zsh-completions; environment.pathsToLink = optional cfg.enableCompletion "/share/zsh"; diff --git a/nixos/modules/rename.nix b/nixos/modules/rename.nix index 0174fe544e3..8a313f6c7fc 100644 --- a/nixos/modules/rename.nix +++ b/nixos/modules/rename.nix @@ -204,5 +204,8 @@ with lib; "Set the option `services.xserver.displayManager.sddm.package' instead.") (mkRemovedOptionModule [ "fonts" "fontconfig" "forceAutohint" ] "") (mkRemovedOptionModule [ "fonts" "fontconfig" "renderMonoTTFAsBitmap" ] "") + + # ZSH + (mkRenamedOptionModule [ "programs" "zsh" "enableSyntaxHighlighting" ] [ "programs" "zsh" "syntax-highlighting" "enable" ]) ]; } -- cgit 1.4.1