From 55ce64c3ca031eefb1adac85bb0025887ed7a221 Mon Sep 17 00:00:00 2001 From: ilaumjd Date: Sun, 1 Oct 2023 17:17:06 +0700 Subject: [PATCH] scmpuff: enable or disable aliases --- modules/programs/scmpuff.nix | 22 +++++++++--- tests/modules/programs/scmpuff/bash.nix | 2 +- tests/modules/programs/scmpuff/default.nix | 1 + tests/modules/programs/scmpuff/fish.nix | 2 +- tests/modules/programs/scmpuff/no-aliases.nix | 34 +++++++++++++++++++ tests/modules/programs/scmpuff/no-bash.nix | 2 +- tests/modules/programs/scmpuff/no-shell.nix | 4 +-- tests/modules/programs/scmpuff/zsh.nix | 2 +- 8 files changed, 58 insertions(+), 11 deletions(-) create mode 100644 tests/modules/programs/scmpuff/no-aliases.nix diff --git a/modules/programs/scmpuff.nix b/modules/programs/scmpuff.nix index 5f2fba53b..a85ae8d9c 100644 --- a/modules/programs/scmpuff.nix +++ b/modules/programs/scmpuff.nix @@ -39,22 +39,34 @@ in { Whether to enable fish integration. ''; }; + + enableAliases = mkOption { + default = true; + type = types.bool; + description = '' + Whether to enable aliases (e.g. gs, ga, gd, gco). + ''; + }; }; - config = mkIf cfg.enable { + config = mkIf cfg.enable (let + mkArgs = shell: + concatStringsSep " " ([ "--shell=${shell}" ] + ++ optional (!cfg.enableAliases) "--aliases=false"); + in { home.packages = [ cfg.package ]; programs.bash.initExtra = mkIf cfg.enableBashIntegration '' - eval "$(${cfg.package}/bin/scmpuff init -s)" + eval "$(${cfg.package}/bin/scmpuff init ${mkArgs "bash"})" ''; programs.zsh.initExtra = mkIf cfg.enableZshIntegration '' - eval "$(${cfg.package}/bin/scmpuff init -s)" + eval "$(${cfg.package}/bin/scmpuff init ${mkArgs "zsh"})" ''; programs.fish.interactiveShellInit = mkIf cfg.enableFishIntegration (mkAfter '' - ${cfg.package}/bin/scmpuff init -s --shell=fish | source + ${cfg.package}/bin/scmpuff init ${mkArgs "fish"} | source ''); - }; + }); } diff --git a/tests/modules/programs/scmpuff/bash.nix b/tests/modules/programs/scmpuff/bash.nix index 942d472f9..8f97caa6f 100644 --- a/tests/modules/programs/scmpuff/bash.nix +++ b/tests/modules/programs/scmpuff/bash.nix @@ -12,6 +12,6 @@ assertFileExists home-files/.bashrc assertFileContains \ home-files/.bashrc \ - 'eval "$(@scmpuff@/bin/scmpuff init -s)"' + 'eval "$(@scmpuff@/bin/scmpuff init --shell=bash)"' ''; } diff --git a/tests/modules/programs/scmpuff/default.nix b/tests/modules/programs/scmpuff/default.nix index bf162a9bb..ec73b5337 100644 --- a/tests/modules/programs/scmpuff/default.nix +++ b/tests/modules/programs/scmpuff/default.nix @@ -6,4 +6,5 @@ scmpuff-zsh = ./zsh.nix; scmpuff-fish = ./fish.nix; scmpuff-no-fish = ./no-fish.nix; + scmpuff-no-aliases = ./no-aliases.nix; } diff --git a/tests/modules/programs/scmpuff/fish.nix b/tests/modules/programs/scmpuff/fish.nix index 920196b16..a1abbffa3 100644 --- a/tests/modules/programs/scmpuff/fish.nix +++ b/tests/modules/programs/scmpuff/fish.nix @@ -16,6 +16,6 @@ assertFileExists home-files/.config/fish/config.fish assertFileContains \ home-files/.config/fish/config.fish \ - '@scmpuff@/bin/scmpuff init -s --shell=fish | source' + '@scmpuff@/bin/scmpuff init --shell=fish | source' ''; } diff --git a/tests/modules/programs/scmpuff/no-aliases.nix b/tests/modules/programs/scmpuff/no-aliases.nix new file mode 100644 index 000000000..0636c8791 --- /dev/null +++ b/tests/modules/programs/scmpuff/no-aliases.nix @@ -0,0 +1,34 @@ +{ lib, ... }: + +{ + programs = { + scmpuff.enable = true; + scmpuff.enableAliases = false; + bash.enable = true; + fish.enable = true; + zsh.enable = true; + }; + + # Needed to avoid error with dummy fish package. + xdg.dataFile."fish/home-manager_generated_completions".source = + lib.mkForce (builtins.toFile "empty" ""); + + test.stubs.scmpuff = { }; + + nmt.script = '' + assertFileExists home-files/.bashrc + assertFileContains \ + home-files/.bashrc \ + 'eval "$(@scmpuff@/bin/scmpuff init --shell=bash --aliases=false)"' + + assertFileExists home-files/.zshrc + assertFileContains \ + home-files/.zshrc \ + 'eval "$(@scmpuff@/bin/scmpuff init --shell=zsh --aliases=false)"' + + assertFileExists home-files/.config/fish/config.fish + assertFileContains \ + home-files/.config/fish/config.fish \ + '@scmpuff@/bin/scmpuff init --shell=fish --aliases=false | source' + ''; +} diff --git a/tests/modules/programs/scmpuff/no-bash.nix b/tests/modules/programs/scmpuff/no-bash.nix index e76295a53..5594738ae 100644 --- a/tests/modules/programs/scmpuff/no-bash.nix +++ b/tests/modules/programs/scmpuff/no-bash.nix @@ -12,6 +12,6 @@ test.stubs.scmpuff = { }; nmt.script = '' - assertFileNotRegex home-files/.bashrc '@scmpuff@/bin/scmpuff' + assertFileNotRegex home-files/.bashrc '@scmpuff@' ''; } diff --git a/tests/modules/programs/scmpuff/no-shell.nix b/tests/modules/programs/scmpuff/no-shell.nix index 1f479efda..8c33a2b27 100644 --- a/tests/modules/programs/scmpuff/no-shell.nix +++ b/tests/modules/programs/scmpuff/no-shell.nix @@ -17,7 +17,7 @@ }; nmt.script = '' - assertFileNotRegex home-files/.zshrc '@scmpuff@ init -s' - assertFileNotRegex home-files/.bashrc '@scmpuff@ init -s' + assertFileNotRegex home-files/.zshrc '@scmpuff@' + assertFileNotRegex home-files/.bashrc '@scmpuff@' ''; } diff --git a/tests/modules/programs/scmpuff/zsh.nix b/tests/modules/programs/scmpuff/zsh.nix index ce0a0eaeb..8a4e2e54c 100644 --- a/tests/modules/programs/scmpuff/zsh.nix +++ b/tests/modules/programs/scmpuff/zsh.nix @@ -15,6 +15,6 @@ assertFileExists home-files/.zshrc assertFileContains \ home-files/.zshrc \ - 'eval "$(@scmpuff@/bin/scmpuff init -s)"' + 'eval "$(@scmpuff@/bin/scmpuff init --shell=zsh)"' ''; }