1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-12-03 07:31:03 +01:00

zsh: group plugins in a separate directory

Make it more scalable to prevent crowding the main folder.

Signed-off-by: Austin Horstman <khaneliman12@gmail.com>
This commit is contained in:
Austin Horstman 2025-07-11 23:17:30 -05:00
parent 26b987cf88
commit 196487c54f
7 changed files with 145 additions and 112 deletions

View file

@ -0,0 +1,136 @@
{
config,
lib,
...
}:
let
inherit (lib) mkOption types;
cfg = config.programs.zsh;
relToDotDir = file: (lib.optionalString (cfg.dotDir != null) (cfg.dotDir + "/")) + file;
in
{
imports = [
./oh-my-zsh.nix
./prezto.nix
./zprof.nix
./zsh-abbr.nix
];
options =
let
pluginModule = types.submodule (
{ config, ... }:
{
options = {
src = mkOption {
type = types.path;
description = ''
Path to the plugin folder.
Will be added to {env}`fpath` and {env}`PATH`.
'';
};
name = mkOption {
type = types.str;
description = ''
The name of the plugin.
'';
};
file = mkOption {
type = types.str;
description = ''
The plugin script to source.
Required if the script name does not match {file}`name.plugin.zsh`
using the plugin {option}`name` from the plugin {option}`src`.
'';
};
completions = mkOption {
default = [ ];
type = types.listOf types.str;
description = "Paths of additional functions to add to {env}`fpath`.";
};
};
config.file = lib.mkDefault "${config.name}.plugin.zsh";
}
);
in
{
programs.zsh.plugins = mkOption {
type = types.listOf pluginModule;
default = [ ];
example = lib.literalExpression ''
[
{
name = "enhancd";
file = "init.sh";
src = pkgs.fetchFromGitHub {
owner = "b4b4r07";
repo = "enhancd";
rev = "v2.2.1";
sha256 = "0iqa9j09fwm6nj5rpip87x3hnvbbz9w9ajgm6wkrd5fls8fn8i5g";
};
}
{
name = "wd";
src = pkgs.zsh-wd;
file = "share/wd/wd.plugin.zsh";
completions = [ "share/zsh/site-functions" ];
}
]
'';
description = "Plugins to source in {file}`.zshrc`.";
};
};
config =
let
pluginsDir = if cfg.dotDir != null then relToDotDir "plugins" else ".zsh/plugins";
in
lib.mkIf (cfg.plugins != [ ]) {
home.file = lib.foldl' (a: b: a // b) { } (
map (plugin: { "${pluginsDir}/${plugin.name}".source = plugin.src; }) cfg.plugins
);
programs.zsh = {
# Many plugins require compinit to be called
# but allow the user to opt out.
enableCompletion = lib.mkDefault true;
initContent = lib.mkMerge [
(lib.mkOrder 560 (
lib.concatStrings (
map (plugin: ''
path+="$HOME/${pluginsDir}/${plugin.name}"
fpath+="$HOME/${pluginsDir}/${plugin.name}"
${
(lib.optionalString (plugin.completions != [ ]) ''
fpath+=(${
lib.concatMapStringsSep " " (
completion: "\"$HOME/${pluginsDir}/${plugin.name}/${completion}\""
) plugin.completions
})
'')
}
'') cfg.plugins
)
))
(lib.mkOrder 900 (
lib.concatStrings (
map (plugin: ''
if [[ -f "$HOME/${pluginsDir}/${plugin.name}/${plugin.file}" ]]; then
source "$HOME/${pluginsDir}/${plugin.name}/${plugin.file}"
fi
'') cfg.plugins
)
))
];
};
};
}

View file

@ -0,0 +1,102 @@
{
config,
lib,
pkgs,
...
}:
let
inherit (lib) mkOption optionalString types;
relToDotDir =
file:
(lib.optionalString (config.programs.zsh.dotDir != null) (config.programs.zsh.dotDir + "/")) + file;
cfg = config.programs.zsh;
ohMyZshModule = types.submodule {
options = {
enable = lib.mkEnableOption "oh-my-zsh";
package = lib.mkPackageOption pkgs "oh-my-zsh" { };
plugins = mkOption {
default = [ ];
example = [
"git"
"sudo"
];
type = types.listOf types.str;
description = ''
List of oh-my-zsh plugins
'';
};
custom = mkOption {
default = "";
type = types.str;
example = "$HOME/my_customizations";
description = ''
Path to a custom oh-my-zsh package to override config of
oh-my-zsh. See <https://github.com/robbyrussell/oh-my-zsh/wiki/Customization>
for more information.
'';
};
theme = mkOption {
default = "";
example = "robbyrussell";
type = types.str;
description = ''
Name of the theme to be used by oh-my-zsh.
'';
};
extraConfig = mkOption {
default = "";
example = ''
zstyle :omz:plugins:ssh-agent identities id_rsa id_rsa2 id_github
'';
type = types.lines;
description = ''
Extra settings for plugins.
'';
};
};
};
in
{
options.programs.zsh.oh-my-zsh = mkOption {
type = ohMyZshModule;
default = { };
description = "Options to configure oh-my-zsh.";
};
config = lib.mkIf cfg.oh-my-zsh.enable {
home = {
packages = [ cfg.oh-my-zsh.package ];
file = {
"${relToDotDir ".zshenv"}".text = ''
ZSH="${cfg.oh-my-zsh.package}/share/oh-my-zsh";
ZSH_CACHE_DIR="${config.xdg.cacheHome}/oh-my-zsh";
'';
# Make sure we create a cache directory since some plugins expect it to exist
# See: https://github.com/nix-community/home-manager/issues/761
"${config.xdg.cacheHome}/oh-my-zsh/.keep".text = "";
};
};
programs.zsh.initContent = lib.mkOrder 800 ''
# oh-my-zsh extra settings for plugins
${cfg.oh-my-zsh.extraConfig}
# oh-my-zsh configuration generated by NixOS
${optionalString (
cfg.oh-my-zsh.plugins != [ ]
) "plugins=(${lib.concatStringsSep " " cfg.oh-my-zsh.plugins})"}
${optionalString (cfg.oh-my-zsh.custom != "") ''ZSH_CUSTOM="${cfg.oh-my-zsh.custom}"''}
${optionalString (cfg.oh-my-zsh.theme != "") ''ZSH_THEME="${cfg.oh-my-zsh.theme}"''}
source $ZSH/oh-my-zsh.sh
'';
};
}

View file

@ -0,0 +1,592 @@
{
config,
pkgs,
lib,
...
}:
let
inherit (lib)
mkOption
optionalString
strings
types
;
cfg = config.programs.zsh.prezto;
relToDotDir =
file:
(optionalString (config.programs.zsh.dotDir != null) (config.programs.zsh.dotDir + "/")) + file;
preztoModule = types.submodule {
options = {
enable = lib.mkEnableOption "prezto";
package = lib.mkPackageOption pkgs "prezto" { default = "zsh-prezto"; };
caseSensitive = mkOption {
type = types.nullOr types.bool;
# See <https://github.com/nix-community/home-manager/issues/2255>.
default = true;
example = true;
description = "Set case-sensitivity for completion, history lookup, etc.";
};
color = mkOption {
type = types.nullOr types.bool;
default = true;
example = false;
description = ''
Color output (automatically set to `false` on dumb terminals).
'';
};
pmoduleDirs = mkOption {
type = types.listOf types.path;
default = [ ];
example = lib.literalExpression ''[ "''${config.home.homeDirectory}/.zprezto-contrib" ]'';
description = "Add additional directories to load prezto modules from.";
};
extraConfig = mkOption {
type = types.lines;
default = "";
description = ''
Additional configuration to add to {file}`.zpreztorc`.
'';
};
extraModules = mkOption {
type = types.listOf types.str;
default = [ ];
example = [
"attr"
"stat"
];
description = ''
Set the Zsh modules to load ({manpage}`zshmodules(1)`).
'';
};
extraFunctions = mkOption {
type = types.listOf types.str;
default = [ ];
example = [
"zargs"
"zmv"
];
description = ''
Set the Zsh functions to load ({manpage}`zshcontrib(1)`).
'';
};
pmodules = mkOption {
type = types.listOf types.str;
default = [
"environment"
"terminal"
"editor"
"history"
"directory"
"spectrum"
"utility"
"completion"
"prompt"
];
description = "Set the Prezto modules to load (browse modules). The order matters.";
};
autosuggestions.color = mkOption {
type = types.nullOr types.str;
default = null;
example = "fg=blue";
description = "Set the query found color.";
};
completions.ignoredHosts = mkOption {
type = types.listOf types.str;
default = [ ];
example = [
"0.0.0.0"
"127.0.0.1"
];
description = ''
Set the entries to ignore in static {file}`/etc/hosts` for
host completion.
'';
};
editor = {
keymap = mkOption {
type = types.nullOr (
types.enum [
"emacs"
"vi"
]
);
default = "emacs";
example = "vi";
description = ''
Set the key mapping style to `emacs` or `vi`.
'';
};
dotExpansion = mkOption {
type = types.nullOr types.bool;
default = null;
example = true;
description = ''
Automatically convert `....` to `../..`
'';
};
promptContext = mkOption {
type = types.nullOr types.bool;
default = null;
example = true;
description = "Allow the Zsh prompt context to be shown.";
};
};
git.submoduleIgnore = mkOption {
type = types.nullOr (
types.enum [
"dirty"
"untracked"
"all"
"none"
]
);
default = null;
example = "all";
description = ''
Ignore submodules when they are `dirty`, `untracked`, `all`,
or `none`.
'';
};
gnuUtility.prefix = mkOption {
type = types.nullOr types.str;
default = null;
example = "g";
description = "Set the command prefix on non-GNU systems.";
};
historySubstring = {
foundColor = mkOption {
type = types.nullOr types.str;
default = null;
example = "fg=blue";
description = "Set the query found color.";
};
notFoundColor = mkOption {
type = types.nullOr types.str;
default = null;
example = "fg=red";
description = "Set the query not found color.";
};
globbingFlags = mkOption {
type = types.nullOr types.str;
default = null;
description = "Set the search globbing flags.";
};
};
macOS.dashKeyword = mkOption {
type = types.nullOr types.str;
default = null;
example = "manpages";
description = ''
Set the keyword used by {command}`mand` to open man pages
in Dash.app.
'';
};
prompt = {
theme = mkOption {
type = types.nullOr types.str;
default = "sorin";
example = "pure";
description = ''
Set the prompt theme to load. Setting it to `random`
loads a random theme. Automatically set to `off` on dumb
terminals.
'';
};
pwdLength = mkOption {
type = types.nullOr (
types.enum [
"short"
"long"
"full"
]
);
default = null;
example = "short";
description = ''
Set the working directory prompt display length. By
default, it is set to `short`. Set it to `long` (without `~`
expansion) for longer or `full` (with `~` expansion) for
even longer prompt display.
'';
};
showReturnVal = mkOption {
type = types.nullOr types.bool;
default = null;
example = true;
description = ''
Set the prompt to display the return code along with an
indicator for non-zero return codes. This is not supported by all prompts.
'';
};
};
python = {
virtualenvAutoSwitch = mkOption {
type = types.nullOr types.bool;
default = null;
example = true;
description = "Auto switch to Python virtualenv on directory change.";
};
virtualenvInitialize = mkOption {
type = types.nullOr types.bool;
default = null;
example = true;
description = "Automatically initialize virtualenvwrapper if pre-requisites are met.";
};
};
ruby.chrubyAutoSwitch = mkOption {
type = types.nullOr types.bool;
default = null;
example = true;
description = "Auto switch the Ruby version on directory change.";
};
screen = {
autoStartLocal = mkOption {
type = types.nullOr types.bool;
default = null;
example = true;
description = "Auto start a session when Zsh is launched in a local terminal.";
};
autoStartRemote = mkOption {
type = types.nullOr types.bool;
default = null;
example = true;
description = "Auto start a session when Zsh is launched in a SSH connection.";
};
};
ssh.identities = mkOption {
type = types.listOf types.str;
default = [ ];
example = [
"id_rsa"
"id_rsa2"
"id_github"
];
description = "Set the SSH identities to load into the agent.";
};
syntaxHighlighting = {
highlighters = mkOption {
type = types.listOf types.str;
default = [ ];
example = [
"main"
"brackets"
"pattern"
"line"
"cursor"
"root"
];
description = ''
Set syntax highlighters. By default, only the main
highlighter is enabled.
'';
};
styles = mkOption {
type = types.attrsOf types.str;
default = { };
example = {
builtin = "bg=blue";
command = "bg=blue";
function = "bg=blue";
};
description = "Set syntax highlighting styles.";
};
pattern = mkOption {
type = types.attrsOf types.str;
default = { };
example = {
"rm*-rf*" = "fg=white,bold,bg=red";
};
description = "Set syntax pattern styles.";
};
};
terminal = {
autoTitle = mkOption {
type = types.nullOr types.bool;
default = null;
example = true;
description = "Auto set the tab and window titles.";
};
windowTitleFormat = mkOption {
type = types.nullOr types.str;
default = null;
example = "%n@%m: %s";
description = "Set the window title format.";
};
tabTitleFormat = mkOption {
type = types.nullOr types.str;
default = null;
example = "%m: %s";
description = "Set the tab title format.";
};
multiplexerTitleFormat = mkOption {
type = types.nullOr types.str;
default = null;
example = "%s";
description = "Set the multiplexer title format.";
};
};
tmux = {
autoStartLocal = mkOption {
type = types.nullOr types.bool;
default = null;
example = true;
description = "Auto start a session when Zsh is launched in a local terminal.";
};
autoStartRemote = mkOption {
type = types.nullOr types.bool;
default = null;
example = true;
description = "Auto start a session when Zsh is launched in a SSH connection.";
};
itermIntegration = mkOption {
type = types.nullOr types.bool;
default = null;
example = true;
description = "Integrate with iTerm2.";
};
defaultSessionName = mkOption {
type = types.nullOr types.str;
default = null;
example = "YOUR DEFAULT SESSION NAME";
description = "Set the default session name.";
};
};
utility.safeOps = mkOption {
type = types.nullOr types.bool;
default = null;
example = true;
description = ''
Enabled safe options. This aliases {command}`cp`,
{command}`ln`, {command}`mv` and {command}`rm` so that they
prompt before deleting or overwriting files. Set to `no` to
disable this safer behavior.
'';
};
};
};
in
{
meta.maintainers = [ lib.maintainers.nickhu ];
options = {
programs.zsh = {
prezto = mkOption {
type = preztoModule;
default = { };
description = "Options to configure prezto.";
};
};
};
config = lib.mkIf cfg.enable (
lib.mkMerge [
{
home.packages = [ cfg.package ];
home.file."${relToDotDir ".zprofile"}".text = ''
# Generated by Nix
source ${cfg.package}/share/zsh-prezto/runcoms/zprofile
'';
home.file."${relToDotDir ".zlogin"}".text = ''
# Generated by Nix
source ${cfg.package}/share/zsh-prezto/runcoms/zlogin
'';
home.file."${relToDotDir ".zlogout"}".text = ''
# Generated by Nix
source ${cfg.package}/share/zsh-prezto/runcoms/zlogout
'';
# Using mkAfter to make sure we load Home-Manager's environment
# variables first (see modules/prgrams/zsh.nix)
home.file."${relToDotDir ".zshenv"}".text = lib.mkAfter ''
# Generated by Nix
source ${cfg.package}/share/zsh-prezto/runcoms/zshenv
'';
home.file."${relToDotDir ".zpreztorc"}".text = ''
# Generated by Nix
${optionalString (cfg.caseSensitive != null) ''
zstyle ':prezto:*:*' case-sensitive '${lib.hm.booleans.yesNo cfg.caseSensitive}'
''}
${optionalString (cfg.color != null) ''
zstyle ':prezto:*:*' color '${lib.hm.booleans.yesNo cfg.color}'
''}
${optionalString (cfg.pmoduleDirs != [ ]) ''
zstyle ':prezto:load' pmodule-dirs ${builtins.concatStringsSep " " cfg.pmoduleDirs}
''}
${optionalString (cfg.extraModules != [ ]) ''
zstyle ':prezto:load' zmodule ${
strings.concatMapStringsSep " " strings.escapeShellArg cfg.extraModules
}
''}
${optionalString (cfg.extraFunctions != [ ]) ''
zstyle ':prezto:load' zfunction ${
strings.concatMapStringsSep " " strings.escapeShellArg cfg.extraFunctions
}
''}
${optionalString (cfg.pmodules != [ ]) ''
zstyle ':prezto:load' pmodule \
${strings.concatMapStringsSep " \\\n " strings.escapeShellArg cfg.pmodules}
''}
${optionalString (cfg.autosuggestions.color != null) ''
zstyle ':prezto:module:autosuggestions:color' found '${cfg.autosuggestions.color}'
''}
${optionalString (cfg.completions.ignoredHosts != [ ]) ''
zstyle ':prezto:module:completion:*:hosts' etc-host-ignores \
${strings.concatMapStringsSep " " strings.escapeShellArg cfg.completions.ignoredHosts}
''}
${optionalString (cfg.editor.keymap != null) ''
zstyle ':prezto:module:editor' key-bindings '${cfg.editor.keymap}'
''}
${optionalString (cfg.editor.dotExpansion != null) ''
zstyle ':prezto:module:editor' dot-expansion '${lib.hm.booleans.yesNo cfg.editor.dotExpansion}'
''}
${optionalString (cfg.editor.promptContext != null) ''
zstyle ':prezto:module:editor' ps-context '${lib.hm.booleans.yesNo cfg.editor.promptContext}'
''}
${optionalString (cfg.git.submoduleIgnore != null) ''
zstyle ':prezto:module:git:status:ignore' submodules '${cfg.git.submoduleIgnore}'
''}
${optionalString (cfg.gnuUtility.prefix != null) ''
zstyle ':prezto:module:gnu-utility' prefix '${cfg.gnuUtility.prefix}'
''}
${optionalString (cfg.historySubstring.foundColor != null) ''
zstyle ':prezto:module:history-substring-search:color' found '${cfg.historySubstring.foundColor}'
''}
${optionalString (cfg.historySubstring.notFoundColor != null) ''
zstyle ':prezto:module:history-substring-search:color' not-found '${cfg.historySubstring.notFoundColor}'
''}
${optionalString (cfg.historySubstring.globbingFlags != null) ''
zstyle ':prezto:module:history-substring-search:color' globbing-flags '${cfg.historySubstring.globbingFlags}'
''}
${optionalString (cfg.macOS.dashKeyword != null) ''
zstyle ':prezto:module:osx:man' dash-keyword '${cfg.macOS.dashKeyword}'
''}
${optionalString (cfg.prompt.theme != null) ''
zstyle ':prezto:module:prompt' theme '${cfg.prompt.theme}'
''}
${optionalString (cfg.prompt.pwdLength != null) ''
zstyle ':prezto:module:prompt' pwd-length '${cfg.prompt.pwdLength}'
''}
${optionalString (cfg.prompt.showReturnVal != null) ''
zstyle ':prezto:module:prompt' show-return-val '${lib.hm.booleans.yesNo cfg.prompt.showReturnVal}'
''}
${optionalString (cfg.python.virtualenvAutoSwitch != null) ''
zstyle ':prezto:module:python:virtualenv' auto-switch '${lib.hm.booleans.yesNo cfg.python.virtualenvAutoSwitch}'
''}
${optionalString (cfg.python.virtualenvInitialize != null) ''
zstyle ':prezto:module:python:virtualenv' initialize '${lib.hm.booleans.yesNo cfg.python.virtualenvInitialize}'
''}
${optionalString (cfg.ruby.chrubyAutoSwitch != null) ''
zstyle ':prezto:module:ruby:chruby' auto-switch '${lib.hm.booleans.yesNo cfg.ruby.chrubyAutoSwitch}'
''}
${optionalString (cfg.screen.autoStartLocal != null) ''
zstyle ':prezto:module:screen:auto-start' local '${lib.hm.booleans.yesNo cfg.screen.autoStartLocal}'
''}
${optionalString (cfg.screen.autoStartRemote != null) ''
zstyle ':prezto:module:screen:auto-start' remote '${lib.hm.booleans.yesNo cfg.screen.autoStartRemote}'
''}
${optionalString (cfg.ssh.identities != [ ]) ''
zstyle ':prezto:module:ssh:load' identities \
${strings.concatMapStringsSep " " strings.escapeShellArg cfg.ssh.identities}
''}
${optionalString (cfg.syntaxHighlighting.highlighters != [ ]) ''
zstyle ':prezto:module:syntax-highlighting' highlighters \
${strings.concatMapStringsSep " \\\n " strings.escapeShellArg
cfg.syntaxHighlighting.highlighters
}
''}
${optionalString (cfg.syntaxHighlighting.styles != { }) ''
zstyle ':prezto:module:syntax-highlighting' styles \
${builtins.concatStringsSep " \\\n" (
lib.attrsets.mapAttrsToList (
k: v: strings.escapeShellArg k + " " + strings.escapeShellArg v
) cfg.syntaxHighlighting.styles
)}
''}
${optionalString (cfg.syntaxHighlighting.pattern != { }) ''
zstyle ':prezto:module:syntax-highlighting' pattern \
${builtins.concatStringsSep " \\\n" (
lib.attrsets.mapAttrsToList (
k: v: strings.escapeShellArg k + " " + strings.escapeShellArg v
) cfg.syntaxHighlighting.pattern
)}
''}
${optionalString (cfg.terminal.autoTitle != null) ''
zstyle ':prezto:module:terminal' auto-title '${lib.hm.booleans.yesNo cfg.terminal.autoTitle}'
''}
${optionalString (cfg.terminal.windowTitleFormat != null) ''
zstyle ':prezto:module:terminal:window-title' format '${cfg.terminal.windowTitleFormat}'
''}
${optionalString (cfg.terminal.tabTitleFormat != null) ''
zstyle ':prezto:module:terminal:tab-title' format '${cfg.terminal.tabTitleFormat}'
''}
${optionalString (cfg.terminal.multiplexerTitleFormat != null) ''
zstyle ':prezto:module:terminal:multiplexer-title' format '${cfg.terminal.multiplexerTitleFormat}'
''}
${optionalString (cfg.tmux.autoStartLocal != null) ''
zstyle ':prezto:module:tmux:auto-start' local '${lib.hm.booleans.yesNo cfg.tmux.autoStartLocal}'
''}
${optionalString (cfg.tmux.autoStartRemote != null) ''
zstyle ':prezto:module:tmux:auto-start' remote '${lib.hm.booleans.yesNo cfg.tmux.autoStartRemote}'
''}
${optionalString (cfg.tmux.itermIntegration != null) ''
zstyle ':prezto:module:tmux:iterm' integrate '${lib.hm.booleans.yesNo cfg.tmux.itermIntegration}'
''}
${optionalString (cfg.tmux.defaultSessionName != null) ''
zstyle ':prezto:module:tmux:session' name '${cfg.tmux.defaultSessionName}'
''}
${optionalString (cfg.utility.safeOps != null) ''
zstyle ':prezto:module:utility' safe-ops '${lib.hm.booleans.yesNo cfg.utility.safeOps}'
''}
${cfg.extraConfig}
'';
programs.zsh.initContent = lib.mkOrder 850 ''
# Load prezto
source ${cfg.package}/share/zsh-prezto/runcoms/zshrc
'';
}
]
);
}

View file

@ -0,0 +1,37 @@
{
config,
lib,
...
}:
let
inherit (lib) mkOption types;
cfg = config.programs.zsh;
in
{
imports = [
(lib.mkRenamedOptionModule [ "programs" "zsh" "zproof" ] [ "programs" "zsh" "zprof" ])
];
options.programs.zsh.zprof = {
enable = mkOption {
type = types.bool;
default = false;
description = ''
Enable zprof in your zshrc.
'';
};
};
config = lib.mkIf cfg.zprof.enable {
programs.zsh.initContent = lib.mkMerge [
# zprof must be loaded before everything else, since it
# benchmarks the shell initialization.
(lib.mkOrder 400 ''
zmodload zsh/zprof
'')
(lib.mkOrder 1450 "zprof")
];
};
}

View file

@ -0,0 +1,72 @@
{
config,
lib,
pkgs,
...
}:
let
inherit (lib) escapeShellArg mkOption types;
cfg = config.programs.zsh.zsh-abbr;
in
{
meta.maintainers = [ lib.maintainers.ilaumjd ];
options.programs.zsh.zsh-abbr = {
enable = lib.mkEnableOption "zsh-abbr - zsh manager for auto-expanding abbreviations";
package = lib.mkPackageOption pkgs "zsh-abbr" { };
abbreviations = mkOption {
type = types.attrsOf types.str;
default = { };
example = {
l = "less";
gco = "git checkout";
};
description = ''
An attribute set that maps aliases (the top level attribute names
in this option) to abbreviations. Abbreviations are expanded with
the longer phrase after they are entered.
'';
};
globalAbbreviations = mkOption {
type = types.attrsOf types.str;
default = { };
example = {
G = "| grep";
L = "| less -R";
};
description = ''
Similar to [](#opt-programs.zsh.zsh-abbr.abbreviations),
but are expanded anywhere on a line.
'';
};
};
config =
let
abbreviations = lib.mapAttrsToList (
k: v: "abbr ${escapeShellArg k}=${escapeShellArg v}"
) cfg.abbreviations;
globalAbbreviations = lib.mapAttrsToList (
k: v: "abbr -g ${escapeShellArg k}=${escapeShellArg v}"
) cfg.globalAbbreviations;
allAbbreviations = abbreviations ++ globalAbbreviations;
in
lib.mkIf cfg.enable {
programs.zsh.plugins = [
{
name = "zsh-abbr";
src = cfg.package;
file = "share/zsh/zsh-abbr/zsh-abbr.plugin.zsh";
}
];
xdg.configFile = {
"zsh-abbr/user-abbreviations".text = lib.concatStringsSep "\n" allAbbreviations + "\n";
};
};
}