From f06a43dca05fb7f1aa44742bf861d9c827b45122 Mon Sep 17 00:00:00 2001 From: Will Leinweber Date: Mon, 19 Jun 2023 21:56:48 +0200 Subject: [PATCH] starship: add enable_transience for fish (#3975) Starship has an advanced, experimental feature where fancy stuff in the prompt can be replaced with something more simple after the command is ran. This is very helpful for copy and pasting shell history somewhere else. docs: https://starship.rs/advanced-config/#transientprompt-and-transientrightprompt-in-fish Fish is currently the only shell as far as I can tell that both home-manager and starship support for this feature. Since the function has to be called after starship is loaded, this seems like the best place to put it. format --- modules/programs/starship.nix | 14 +++++++++++++ tests/modules/programs/starship/default.nix | 6 +++++- .../starship/fish_with_transience.nix | 21 +++++++++++++++++++ .../starship/fish_without_transience.nix | 17 +++++++++++++++ 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 tests/modules/programs/starship/fish_with_transience.nix create mode 100644 tests/modules/programs/starship/fish_without_transience.nix diff --git a/modules/programs/starship.nix b/modules/programs/starship.nix index 31136d7e..519c9c02 100644 --- a/modules/programs/starship.nix +++ b/modules/programs/starship.nix @@ -77,6 +77,19 @@ in { enableNushellIntegration = mkEnableOption "Nushell integration" // { default = true; }; + + enableTransience = mkOption { + type = types.bool; + default = false; + description = '' + The TransientPrompt feature of Starship replaces previous prompts with a + custom string. This is only a valid option for the Fish shell. + + For documentation on how to change the default replacement string and + for more information visit + https://starship.rs/advanced-config/#transientprompt-and-transientrightprompt-in-cmd + ''; + }; }; config = mkIf cfg.enable { @@ -101,6 +114,7 @@ in { programs.fish.interactiveShellInit = mkIf cfg.enableFishIntegration '' if test "$TERM" != "dumb" -a \( -z "$INSIDE_EMACS" -o "$INSIDE_EMACS" = "vterm" \) eval (${starshipCmd} init fish) + ${lib.optionalString cfg.enableTransience "enable_transience"} end ''; diff --git a/tests/modules/programs/starship/default.nix b/tests/modules/programs/starship/default.nix index 814aed65..6fed1303 100644 --- a/tests/modules/programs/starship/default.nix +++ b/tests/modules/programs/starship/default.nix @@ -1 +1,5 @@ -{ starship-settings = ./settings.nix; } +{ + starship-settings = ./settings.nix; + starship-fish-with-transience = ./fish_with_transience.nix; + starship-fish-without-transience = ./fish_without_transience.nix; +} diff --git a/tests/modules/programs/starship/fish_with_transience.nix b/tests/modules/programs/starship/fish_with_transience.nix new file mode 100644 index 00000000..c7a0fbf5 --- /dev/null +++ b/tests/modules/programs/starship/fish_with_transience.nix @@ -0,0 +1,21 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + config = { + programs = { + fish.enable = true; + + starship = { + enable = true; + enableTransience = true; + }; + }; + + nmt.script = '' + assertFileExists home-files/.config/fish/config.fish + assertFileRegex home-files/.config/fish/config.fish 'enable_transience' + ''; + }; +} diff --git a/tests/modules/programs/starship/fish_without_transience.nix b/tests/modules/programs/starship/fish_without_transience.nix new file mode 100644 index 00000000..7ba8e67f --- /dev/null +++ b/tests/modules/programs/starship/fish_without_transience.nix @@ -0,0 +1,17 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + config = { + programs = { + fish.enable = true; + starship.enable = true; + }; + + nmt.script = '' + assertFileExists home-files/.config/fish/config.fish + assertFileNotRegex home-files/.config/fish/config.fish 'enable_transience' + ''; + }; +}