home-manager/modules/programs/sheldon.nix

83 lines
2 KiB
Nix
Raw Normal View History

2024-07-25 15:10:16 +02:00
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.programs.sheldon;
2024-07-25 17:31:47 +02:00
tomlFormat = pkgs.formats.toml { };
2024-07-31 12:36:31 +02:00
sheldonCmd = "${config.home.profileDirectory}/bin/sheldon";
2024-07-25 15:10:16 +02:00
in {
2024-07-26 17:58:03 +02:00
meta.maintainers = [ maintainers.Kyure-A ];
2024-07-25 15:10:16 +02:00
options.programs.sheldon = {
enable = mkEnableOption "sheldon";
package = mkOption {
type = types.package;
default = pkgs.sheldon;
defaultText = literalExpression "pkgs.sheldon";
description = "The package to use for the sheldon binary.";
};
settings = mkOption {
inherit (tomlFormat) type;
default = { };
2024-07-25 17:31:47 +02:00
description = "";
example = literalExpression "";
2024-07-25 15:10:16 +02:00
};
enableZshCompletions = mkEnableOption "Zsh completions" // {
default = true;
};
enableBashCompletions = mkEnableOption "Bash completions" // {
default = true;
};
enableFishCompletions = mkEnableOption "Fish completions" // {
default = true;
};
2024-07-25 15:10:16 +02:00
};
config = mkIf cfg.enable {
2024-07-25 16:12:40 +02:00
home.packages = [ cfg.package ];
2024-07-25 15:10:16 +02:00
xdg.configFile."sheldon/plugins.toml" = mkIf (cfg.settings != { }) {
source = tomlFormat.generate "sheldon-config" cfg.settings;
};
2024-07-25 17:19:55 +02:00
2024-07-31 12:36:31 +02:00
programs.bash.initExtra = ''
${optionalString (cfg.settings != { }) ''
2024-07-30 14:29:22 +02:00
eval "$(sheldon source)"
2024-07-31 12:36:31 +02:00
''}
${optionalString cfg.enableBashCompletions ''
2024-07-30 14:29:22 +02:00
if [[ $TERM != "dumb" ]]; then
2024-07-31 12:36:31 +02:00
eval "$(${sheldonCmd} completions --shell=bash)"
2024-07-30 14:29:22 +02:00
fi
2024-07-31 12:36:31 +02:00
''}
'';
2024-07-25 17:19:55 +02:00
2024-07-31 12:36:31 +02:00
programs.zsh.initExtra = ''
${optionalString (cfg.settings != { }) ''
2024-07-30 14:29:22 +02:00
eval "$(sheldon source)"
2024-07-31 12:36:31 +02:00
''}
${optionalString cfg.enableZshCompletions ''
2024-07-30 14:29:22 +02:00
if [[ $TERM != "dumb" ]]; then
2024-07-31 12:36:31 +02:00
eval "$(${sheldonCmd} completions --shell=zsh)"
2024-07-30 14:29:22 +02:00
fi
2024-07-31 12:36:31 +02:00
''}
'';
2024-07-31 12:36:31 +02:00
programs.fish.interactiveShellInit = ''
${optionalString (cfg.settings != { }) ''
2024-07-30 14:29:22 +02:00
eval "$(sheldon source)"
2024-07-31 12:36:31 +02:00
''}
${optionalString cfg.enableFishCompletions ''
2024-07-30 14:29:22 +02:00
if test "$TERM" != "dumb"
2024-07-31 12:36:31 +02:00
eval "$(${sheldonCmd} completions --shell=fish)"
2024-07-30 14:29:22 +02:00
end
2024-07-31 12:36:31 +02:00
''}
'';
2024-07-25 15:10:16 +02:00
};
}