1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-11-22 10:19:39 +01:00
home-manager/modules/programs/zsh/zsh-abbr.nix
Austin Horstman cba2f9ce95 treewide: reformat nixfmt-rfc-style
Reformat repository using new nixfmt-rfc-style.
2025-04-08 08:50:05 -07:00

72 lines
1.8 KiB
Nix

{
config,
lib,
pkgs,
...
}:
let
inherit (lib) escapeShellArg mkOption types;
cfg = config.programs.zsh.zsh-abbr;
in
{
meta.maintainers = [ lib.hm.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";
};
};
}