nushell: add shellAliases option

This allows nushell users to define shell aliases that are inserted
into nushell's `config.nu`.
This commit is contained in:
Mika Naylor 2022-12-27 17:29:16 +01:00 committed by Robert Helgesson
parent 6db559daa9
commit 58b8685e47
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
3 changed files with 28 additions and 1 deletions

View file

@ -111,17 +111,36 @@ in {
Additional configuration to add to the nushell environment variables file. Additional configuration to add to the nushell environment variables file.
''; '';
}; };
shellAliases = mkOption {
type = types.attrsOf types.str;
default = { };
example = { ll = "ls -l"; };
description = ''
An attribute set that maps aliases (the top level attribute names in
this option) to command strings or directly to build outputs.
'';
};
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable {
home.packages = [ cfg.package ]; home.packages = [ cfg.package ];
home.file = mkMerge [ home.file = mkMerge [
(mkIf (cfg.configFile != null || cfg.extraConfig != "") { (let
writeConfig = cfg.configFile != null || cfg.extraConfig != ""
|| aliasesStr != "";
aliasesStr = concatStringsSep "\n"
(mapAttrsToList (k: v: "alias ${k} = ${v}") cfg.shellAliases);
in mkIf writeConfig {
"${configDir}/config.nu".text = mkMerge [ "${configDir}/config.nu".text = mkMerge [
(mkIf (cfg.configFile != null) cfg.configFile.text) (mkIf (cfg.configFile != null) cfg.configFile.text)
cfg.extraConfig cfg.extraConfig
aliasesStr
]; ];
}) })
(mkIf (cfg.envFile != null || cfg.extraEnv != "") { (mkIf (cfg.envFile != null || cfg.extraEnv != "") {
"${configDir}/env.nu".text = mkMerge [ "${configDir}/env.nu".text = mkMerge [
(mkIf (cfg.envFile != null) cfg.envFile.text) (mkIf (cfg.envFile != null) cfg.envFile.text)

View file

@ -4,3 +4,6 @@ let $config = {
use_ls_colors: true use_ls_colors: true
} }
alias ll = ls -a
alias lsname = (ls | get name)

View file

@ -15,6 +15,11 @@
envFile.text = '' envFile.text = ''
let-env FOO = 'BAR' let-env FOO = 'BAR'
''; '';
shellAliases = {
"lsname" = "(ls | get name)";
"ll" = "ls -a";
};
}; };
test.stubs.nushell = { }; test.stubs.nushell = { };