nixfiles/home-manager/modules/elvish.nix
2022-11-11 16:09:41 -07:00

83 lines
2.0 KiB
Nix

{
config,
lib,
pkgs,
...
}:
with lib; let
cfg = config.programs.elvish;
in {
options.programs.elvish = {
enable = mkEnableOption "Elvish, a friendly interactive shell and an expressive programming";
defaultFromBash = mkOption {
type = types.bool;
default = cfg.enable;
description = ''
Launch automatically when an interactive Bash shell is started
'';
};
zoxide = mkOption {
type = types.bool;
default = false;
description = ''
Enable zoxide smart directory switcher
'';
};
starship = mkOption {
type = types.bool;
default = false;
description = ''
Use the starship prompt
'';
};
package = mkOption {
type = types.package;
default = pkgs.elvish;
defaultText = literalExpression "pkgs.elvish";
description = ''
The elvish package to install. May be used to change the version.
'';
};
initExtra = mkOption {
type = types.lines;
default = "";
description = ''
Elvish code called during interactive elvish shell
initialisation.
'';
};
};
config = mkIf cfg.enable {
home.packages = [cfg.package];
# programs.man.generateCaches = mkDefault true;
xdg.configFile."elvish/rc.elv".text = cfg.initExtra;
programs.bash.enable = mkIf cfg.defaultFromBash true;
programs.bash.initExtra = mkIf cfg.defaultFromBash "exec elvish";
programs.starship.enable = mkIf cfg.starship true;
programs.zoxide.enable = mkIf cfg.zoxide true;
programs.starship.enableBashIntegration = mkIf cfg.defaultFromBash false;
programs.elvish.initExtra = mkMerge [
(mkIf cfg.starship ''
if (and (not-eq $E:TERM "dumb") (or (not (has-env "INSIDE_EMACS")) (eq $E:INSIDE_EMACS "vterm"))) {
eval (${config.home.profileDirectory}/bin/starship init elvish)
}
'')
(mkIf cfg.zoxide ''
eval (${config.programs.zoxide.package}/bin/zoxide init elvish | slurp)
'')
];
};
}