2021-12-23 23:22:39 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.programs.starship;
|
|
|
|
|
|
|
|
settingsFormat = pkgs.formats.toml { };
|
|
|
|
|
|
|
|
settingsFile = settingsFormat.generate "starship.toml" cfg.settings;
|
|
|
|
|
2023-03-13 02:22:44 +01:00
|
|
|
initOption =
|
|
|
|
if cfg.interactiveOnly then
|
|
|
|
"promptInit"
|
|
|
|
else
|
|
|
|
"shellInit";
|
|
|
|
|
|
|
|
in
|
|
|
|
{
|
2021-12-23 23:22:39 +01:00
|
|
|
options.programs.starship = {
|
|
|
|
enable = mkEnableOption (lib.mdDoc "the Starship shell prompt");
|
|
|
|
|
2023-03-13 02:22:44 +01:00
|
|
|
interactiveOnly = mkOption {
|
|
|
|
default = true;
|
|
|
|
example = false;
|
|
|
|
type = types.bool;
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
Whether to enable starship only when the shell is interactive.
|
|
|
|
Some plugins require this to be set to false to function correctly.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-12-23 23:22:39 +01:00
|
|
|
settings = mkOption {
|
|
|
|
inherit (settingsFormat) type;
|
|
|
|
default = { };
|
2022-07-20 12:32:04 +02:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
Configuration included in `starship.toml`.
|
2021-12-23 23:22:39 +01:00
|
|
|
|
|
|
|
See https://starship.rs/config/#prompt for documentation.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2023-03-13 02:22:44 +01:00
|
|
|
programs.bash.${initOption} = ''
|
2023-06-26 20:37:10 +02:00
|
|
|
if [[ $TERM != "dumb" ]]; then
|
2021-12-23 23:22:39 +01:00
|
|
|
export STARSHIP_CONFIG=${settingsFile}
|
|
|
|
eval "$(${pkgs.starship}/bin/starship init bash)"
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
2023-03-13 02:22:44 +01:00
|
|
|
programs.fish.${initOption} = ''
|
2023-06-26 20:37:10 +02:00
|
|
|
if test "$TERM" != "dumb"
|
2021-12-23 23:22:39 +01:00
|
|
|
set -x STARSHIP_CONFIG ${settingsFile}
|
|
|
|
eval (${pkgs.starship}/bin/starship init fish)
|
|
|
|
end
|
|
|
|
'';
|
|
|
|
|
2023-03-13 02:22:44 +01:00
|
|
|
programs.zsh.${initOption} = ''
|
2023-06-26 20:37:10 +02:00
|
|
|
if [[ $TERM != "dumb" ]]; then
|
2021-12-23 23:22:39 +01:00
|
|
|
export STARSHIP_CONFIG=${settingsFile}
|
|
|
|
eval "$(${pkgs.starship}/bin/starship init zsh)"
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
meta.maintainers = pkgs.starship.meta.maintainers;
|
|
|
|
}
|