nushell: add abbreviations option

Add `programs.nushell.abbreviations`, mirroring `shellAliases`, to
declaratively configure fish-style abbreviations (nushell 0.113.0+).
The set is emitted as `$env.config.abbreviations = { ... }` after the
aliases so it survives a wholesale `$env.config = { ... }` written in
`extraConfig`.

Unlike aliases, abbreviations expand inline in the line editor, so the
expanded command is what ends up in history.
This commit is contained in:
Dzming Li 2026-06-07 13:38:40 +08:00 committed by Austin Horstman
parent ddb7082625
commit d4d5d9bb4a
3 changed files with 31 additions and 0 deletions

View file

@ -191,6 +191,21 @@ in
'';
};
abbreviations = lib.mkOption {
type = types.attrsOf types.str;
default = { };
example = {
ll = "ls -l";
gs = "git status";
};
description = ''
An attribute set that maps each abbreviation (the top level attribute
names in this option) to its expansion. Unlike aliases, abbreviations
are expanded inline in the line editor when a space or enter is pressed,
so the expanded command is what ends up in the command history.
'';
};
environmentVariables = lib.mkOption {
type = types.attrsOf lib.hm.types.nushellValue;
default = { };
@ -232,11 +247,16 @@ in
|| cfg.extraConfig != ""
|| aliasesStr != ""
|| cfg.settings != { }
|| cfg.abbreviations != { }
|| cfg.environmentVariables != { };
aliasesStr = lib.concatLines (
lib.mapAttrsToList (k: v: "alias ${toNushell { } k} = ${v}") cfg.shellAliases
);
abbreviationsStr =
lib.optionalString (cfg.abbreviations != { })
"$env.config.abbreviations = ${toNushell { } cfg.abbreviations}";
in
lib.mkIf writeConfig {
"${cfg.configDir}/config.nu".text = lib.mkMerge [
@ -275,6 +295,7 @@ in
(lib.mkIf (cfg.configFile != null) cfg.configFile.text)
cfg.extraConfig
aliasesStr
abbreviationsStr
];
}
)

View file

@ -29,3 +29,8 @@ let config = {
alias "ll" = ls -a
alias "multi word alias" = cd -
alias "z" = __zoxide_z
$env.config.abbreviations = {
"gs": "git status"
"ll": "ls -l"
}

View file

@ -38,6 +38,11 @@
"z" = "__zoxide_z";
};
abbreviations = {
"gs" = "git status";
"ll" = "ls -l";
};
settings = {
show_banner = false;
display_errors.exit_code = false;