From 5f8bb123b9b6d0a9e9bbc82a958d9013007f4955 Mon Sep 17 00:00:00 2001 From: Kyure_A <49436968+Kyure-A@users.noreply.github.com> Date: Thu, 25 Jul 2024 22:10:16 +0900 Subject: [PATCH] sheldon: init module sheldon: add module sheldon: some fixes Revert "sheldon: some fixes" This reverts commit ea859bc3e332aa5e50d98d5885d0749fb01dd981. sheldon: fix missed variable name sheldon: add description and example (blank) sheldon: add shell configs sheldon: format code sheldon: add test case maintainers: add Kyure-A as maintainer sheldon: add completions option and various fixes sheldon: fix missed file name sheldon: fix setting to simple sheldon: add option to enable completion script sheldon: change default value of options to enable completions to true sheldon: fix how commands are combined sheldon: fix missing prefix sheldon: change mkIf to be enclosed in parentheses sheldon: fix expression type sheldon: add mainrs as maintainer --- modules/programs/sheldon.nix | 63 +++++++++++++++++++++ tests/modules/programs/sheldon/default.nix | 25 ++++++++ tests/modules/programs/sheldon/plugins.toml | 7 +++ 3 files changed, 95 insertions(+) create mode 100644 modules/programs/sheldon.nix create mode 100644 tests/modules/programs/sheldon/default.nix create mode 100644 tests/modules/programs/sheldon/plugins.toml diff --git a/modules/programs/sheldon.nix b/modules/programs/sheldon.nix new file mode 100644 index 000000000..f1055514d --- /dev/null +++ b/modules/programs/sheldon.nix @@ -0,0 +1,63 @@ +{ + config, + lib, + pkgs, + ... +}: + +let + inherit (lib) + hm + mkEnableOption + mkIf + mkOption + ; + cfg = config.programs.sheldon; + tomlFormat = pkgs.formats.toml { }; +in +{ + meta.maintainers = with hm.maintainers; [ + Kyure-A + mainrs + elanora96 + ]; + + options.programs.sheldon = { + enable = mkEnableOption "sheldon"; + + package = lib.mkPackageOption pkgs "sheldon" { }; + + settings = mkOption { + inherit (tomlFormat) type; + default = { }; + description = ""; + example = lib.literalExpression ""; + }; + + enableZshIntegration = hm.shell.mkZshIntegrationOption { inherit config; }; + + enableBashIntegration = hm.shell.mkBashIntegrationOption { inherit config; }; + + enableFishIntegration = hm.shell.mkFishIntegrationOption { inherit config; }; + }; + + config = mkIf cfg.enable { + home.packages = [ cfg.package ]; + + xdg.configFile."sheldon/plugins.toml" = mkIf (cfg.settings != { }) { + source = tomlFormat.generate "sheldon-config" cfg.settings; + }; + + programs.bash.initExtra = mkIf cfg.enableBashIntegration '' + eval "$(sheldon source)" + ''; + + programs.zsh.initExtra = mkIf cfg.enableZshIntegration '' + eval "$(sheldon source)" + ''; + + programs.fish.interactiveShellInit = mkIf cfg.enableFishIntegration '' + eval "$(sheldon source)" + ''; + }; +} diff --git a/tests/modules/programs/sheldon/default.nix b/tests/modules/programs/sheldon/default.nix new file mode 100644 index 000000000..31001ab71 --- /dev/null +++ b/tests/modules/programs/sheldon/default.nix @@ -0,0 +1,25 @@ +{ + config = { + programs.sheldon = { + enable = true; + settings = { + shell = "zsh"; + plugins = { + zsh-syntax-highlighting = { + github = "zsh-users/zsh-syntax-highlighting"; + apply = [ "defer" ]; + }; + }; + templates = { + defer = '' + {{ hooks | get: "pre" | nl }}{% for file in files %}zsh-defer source "{{ file }}" + {% endfor %}{{ hooks | get: "post" | nl }}''; + }; + }; + }; + }; + + test.stubs.sheldon = { }; + + nmt.script = "assertFileContent home-files/.config/sheldon/plugins.toml ${./plugins.toml}"; +} diff --git a/tests/modules/programs/sheldon/plugins.toml b/tests/modules/programs/sheldon/plugins.toml new file mode 100644 index 000000000..f40b27cf2 --- /dev/null +++ b/tests/modules/programs/sheldon/plugins.toml @@ -0,0 +1,7 @@ +shell = "zsh" +[plugins.zsh-syntax-highlighting] +apply = ["defer"] +github = "zsh-users/zsh-syntax-highlighting" + +[templates] +defer = "{{ hooks | get: \"pre\" | nl }}{% for file in files %}zsh-defer source \"{{ file }}\"\n{% endfor %}{{ hooks | get: \"post\" | nl }}"