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

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
This commit is contained in:
カワリミ人形 2025-03-29 23:42:13 +09:00 committed by GitHub
parent 3527c8c778
commit 1f679ed2a2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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";
};
};
}