From 1f679ed2a2ebe3894bad9f89fb0bd9f141c28a68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=AB=E3=83=AF=E3=83=AA=E3=83=9F=E4=BA=BA=E5=BD=A2?= Date: Sat, 29 Mar 2025 23:42:13 +0900 Subject: [PATCH] zsh-abbr: Add global abbreviations (#6720) zsh-abbr has a global abbreviations feature. The global abbreviations expand anywhere on the line and are defined by using the -g option. https://zsh-abbr.olets.dev/types.html#global --- modules/programs/zsh/zsh-abbr.nix | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/modules/programs/zsh/zsh-abbr.nix b/modules/programs/zsh/zsh-abbr.nix index 096e5da5a..0cc35322b 100644 --- a/modules/programs/zsh/zsh-abbr.nix +++ b/modules/programs/zsh/zsh-abbr.nix @@ -24,9 +24,32 @@ in { 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 = mkIf cfg.enable { + config = let + abbreviations = + mapAttrsToList (k: v: "abbr ${escapeShellArg k}=${escapeShellArg v}") + cfg.abbreviations; + + globalAbbreviations = + mapAttrsToList (k: v: "abbr -g ${escapeShellArg k}=${escapeShellArg v}") + cfg.globalAbbreviations; + + allAbbreviations = abbreviations ++ globalAbbreviations; + in mkIf cfg.enable { programs.zsh.plugins = [{ name = "zsh-abbr"; src = cfg.package; @@ -34,9 +57,8 @@ in { }]; xdg.configFile = { - "zsh-abbr/user-abbreviations".text = concatStringsSep "\n" - (mapAttrsToList (k: v: "abbr ${escapeShellArg k}=${escapeShellArg v}") - cfg.abbreviations) + "\n"; + "zsh-abbr/user-abbreviations".text = + concatStringsSep "\n" allAbbreviations + "\n"; }; }; }