mirror of
https://github.com/nix-community/home-manager.git
synced 2024-12-14 11:57:55 +00:00
starship: add enableInteractive
option for fish
Some fish plugins such as https://github.com/acomagu/fish-async-prompt require that starship be initialized as non-interactive. When the `programs.starship.enableInteractive` option is enabled, starship is initialized at the end of the init script, outside the interactive block.
This commit is contained in:
parent
1cd17a2f76
commit
86ee1290d7
5 changed files with 100 additions and 1 deletions
|
@ -1847,6 +1847,20 @@ in {
|
||||||
output.
|
output.
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
time = "2024-12-04T20:00:00+00:00";
|
||||||
|
condition = let
|
||||||
|
sCfg = config.programs.starship;
|
||||||
|
fCfg = config.programs.fish;
|
||||||
|
in sCfg.enable && sCfg.enableFishIntegration && fCfg.enable;
|
||||||
|
message = ''
|
||||||
|
A new option 'programs.starship.enableInteractive' is available for
|
||||||
|
the Fish shell that only enables starship if the shell is interactive.
|
||||||
|
|
||||||
|
Some plugins require this to be set to 'false' to function correctly.
|
||||||
|
'';
|
||||||
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,8 @@ let
|
||||||
|
|
||||||
starshipCmd = "${config.home.profileDirectory}/bin/starship";
|
starshipCmd = "${config.home.profileDirectory}/bin/starship";
|
||||||
|
|
||||||
|
initFish =
|
||||||
|
if cfg.enableInteractive then "interactiveShellInit" else "shellInitLast";
|
||||||
in {
|
in {
|
||||||
meta.maintainers = [ ];
|
meta.maintainers = [ ];
|
||||||
|
|
||||||
|
@ -71,6 +73,17 @@ in {
|
||||||
default = true;
|
default = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enableInteractive = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = true;
|
||||||
|
description = ''
|
||||||
|
Only enable starship when the shell is interactive. This option is only
|
||||||
|
valid for the Fish shell.
|
||||||
|
|
||||||
|
Some plugins require this to be set to `false` to function correctly.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
enableTransience = mkOption {
|
enableTransience = mkOption {
|
||||||
type = types.bool;
|
type = types.bool;
|
||||||
default = false;
|
default = false;
|
||||||
|
@ -104,7 +117,7 @@ in {
|
||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
|
|
||||||
programs.fish.interactiveShellInit = mkIf cfg.enableFishIntegration ''
|
programs.fish.${initFish} = mkIf cfg.enableFishIntegration ''
|
||||||
if test "$TERM" != "dumb"
|
if test "$TERM" != "dumb"
|
||||||
eval (${starshipCmd} init fish)
|
eval (${starshipCmd} init fish)
|
||||||
${lib.optionalString cfg.enableTransience "enable_transience"}
|
${lib.optionalString cfg.enableTransience "enable_transience"}
|
||||||
|
|
|
@ -2,4 +2,6 @@
|
||||||
starship-settings = ./settings.nix;
|
starship-settings = ./settings.nix;
|
||||||
starship-fish-with-transience = ./fish_with_transience.nix;
|
starship-fish-with-transience = ./fish_with_transience.nix;
|
||||||
starship-fish-without-transience = ./fish_without_transience.nix;
|
starship-fish-without-transience = ./fish_without_transience.nix;
|
||||||
|
starship-fish-with-interactive = ./fish_with_interactive.nix;
|
||||||
|
starship-fish-without-interactive = ./fish_without_interactive.nix;
|
||||||
}
|
}
|
||||||
|
|
27
tests/modules/programs/starship/fish_with_interactive.nix
Normal file
27
tests/modules/programs/starship/fish_with_interactive.nix
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
|
with lib;
|
||||||
|
|
||||||
|
{
|
||||||
|
config = {
|
||||||
|
programs = {
|
||||||
|
fish.enable = true;
|
||||||
|
starship.enable = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
nmt.script = ''
|
||||||
|
assertFileExists home-files/.config/fish/config.fish
|
||||||
|
|
||||||
|
export GOT="$(tail -n 5 `_abs home-files/.config/fish/config.fish`)"
|
||||||
|
export NOT_EXPECTED="
|
||||||
|
if test \"\$TERM\" != dumb
|
||||||
|
/home/hm-user/.nix-profile/bin/starship init fish | source
|
||||||
|
|
||||||
|
end"
|
||||||
|
|
||||||
|
if [[ "$GOT" == "$NOT_EXPECTED" ]]; then
|
||||||
|
fail "Expected starship init to be inside the 'is-interactive' block but it wasn't."
|
||||||
|
fi
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
43
tests/modules/programs/starship/fish_without_interactive.nix
Normal file
43
tests/modules/programs/starship/fish_without_interactive.nix
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
|
with lib;
|
||||||
|
|
||||||
|
{
|
||||||
|
config = {
|
||||||
|
programs = {
|
||||||
|
fish.enable = true;
|
||||||
|
|
||||||
|
starship = {
|
||||||
|
enable = true;
|
||||||
|
enableInteractive = false;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
nmt.script = ''
|
||||||
|
assertFileExists home-files/.config/fish/config.fish
|
||||||
|
|
||||||
|
export GOT="$(tail -n 5 `_abs home-files/.config/fish/config.fish`)"
|
||||||
|
export EXPECTED="
|
||||||
|
if test \"\$TERM\" != dumb
|
||||||
|
eval (/home/hm-user/.nix-profile/bin/starship init fish)
|
||||||
|
|
||||||
|
end"
|
||||||
|
|
||||||
|
export MESSAGE="
|
||||||
|
==========
|
||||||
|
Expected
|
||||||
|
==========
|
||||||
|
$EXPECTED
|
||||||
|
==========
|
||||||
|
Got
|
||||||
|
==========
|
||||||
|
$GOT
|
||||||
|
==========
|
||||||
|
"
|
||||||
|
|
||||||
|
if [[ "$GOT" != "$EXPECTED" ]]; then
|
||||||
|
fail "$MESSAGE"
|
||||||
|
fi
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in a new issue