diff --git a/modules/programs/nushell.nix b/modules/programs/nushell.nix index 21e9045c5..78842c442 100644 --- a/modules/programs/nushell.nix +++ b/modules/programs/nushell.nix @@ -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 ]; } ) diff --git a/tests/modules/programs/nushell/config-expected.nu b/tests/modules/programs/nushell/config-expected.nu index 57bc16ee8..73c4af777 100644 --- a/tests/modules/programs/nushell/config-expected.nu +++ b/tests/modules/programs/nushell/config-expected.nu @@ -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" +} \ No newline at end of file diff --git a/tests/modules/programs/nushell/example-settings.nix b/tests/modules/programs/nushell/example-settings.nix index 0ec457943..b6c77b51a 100644 --- a/tests/modules/programs/nushell/example-settings.nix +++ b/tests/modules/programs/nushell/example-settings.nix @@ -38,6 +38,11 @@ "z" = "__zoxide_z"; }; + abbreviations = { + "gs" = "git status"; + "ll" = "ls -l"; + }; + settings = { show_banner = false; display_errors.exit_code = false;