From 215af6252d939a936b41dbd85e94d22e874ad990 Mon Sep 17 00:00:00 2001 From: Janik <80165193+Janik-Haag@users.noreply.github.com> Date: Wed, 15 Mar 2023 11:52:48 +0100 Subject: [PATCH] atuin: add disable key options (#3754) Co-authored-by: Janik H --- modules/programs/atuin.nix | 18 +++++++--- tests/modules/programs/atuin/bash.nix | 2 +- tests/modules/programs/atuin/default.nix | 1 + tests/modules/programs/atuin/fish.nix | 2 +- tests/modules/programs/atuin/set-flags.nix | 39 ++++++++++++++++++++++ tests/modules/programs/atuin/zsh.nix | 2 +- 6 files changed, 57 insertions(+), 7 deletions(-) create mode 100644 tests/modules/programs/atuin/set-flags.nix diff --git a/modules/programs/atuin.nix b/modules/programs/atuin.nix index 9a38f5421..c427866f8 100644 --- a/modules/programs/atuin.nix +++ b/modules/programs/atuin.nix @@ -50,6 +50,15 @@ in { ''; }; + flags = mkOption { + default = [ ]; + type = types.listOf types.str; + example = [ "--disable-up-arrow" "--disable-ctrl-r" ]; + description = '' + Flags to append to the shell hook. + ''; + }; + settings = mkOption { type = with types; let @@ -78,7 +87,8 @@ in { }; }; - config = mkIf cfg.enable { + config = let flagsStr = escapeShellArgs cfg.flags; + in mkIf cfg.enable { # Always add the configured `atuin` package. home.packages = [ cfg.package ]; @@ -91,18 +101,18 @@ in { programs.bash.initExtra = mkIf cfg.enableBashIntegration '' if [[ :$SHELLOPTS: =~ :(vi|emacs): ]]; then source "${pkgs.bash-preexec}/share/bash/bash-preexec.sh" - eval "$(${cfg.package}/bin/atuin init bash)" + eval "$(${cfg.package}/bin/atuin init bash ${flagsStr})" fi ''; programs.zsh.initExtra = mkIf cfg.enableZshIntegration '' if [[ $options[zle] = on ]]; then - eval "$(${cfg.package}/bin/atuin init zsh)" + eval "$(${cfg.package}/bin/atuin init zsh ${flagsStr})" fi ''; programs.fish.interactiveShellInit = mkIf cfg.enableFishIntegration '' - ${cfg.package}/bin/atuin init fish | source + ${cfg.package}/bin/atuin init fish ${flagsStr} | source ''; }; } diff --git a/tests/modules/programs/atuin/bash.nix b/tests/modules/programs/atuin/bash.nix index 521886b2e..a84ea99e3 100644 --- a/tests/modules/programs/atuin/bash.nix +++ b/tests/modules/programs/atuin/bash.nix @@ -18,6 +18,6 @@ assertFileExists home-files/.bashrc assertFileContains \ home-files/.bashrc \ - 'eval "$(@atuin@/bin/atuin init bash)"' + 'eval "$(@atuin@/bin/atuin init bash )"' ''; } diff --git a/tests/modules/programs/atuin/default.nix b/tests/modules/programs/atuin/default.nix index ee22818a3..51bf653e2 100644 --- a/tests/modules/programs/atuin/default.nix +++ b/tests/modules/programs/atuin/default.nix @@ -5,4 +5,5 @@ atuin-fish = ./fish.nix; atuin-no-shell = ./no-shell.nix; atuin-zsh = ./zsh.nix; + atuin-set-flags = ./set-flags.nix; } diff --git a/tests/modules/programs/atuin/fish.nix b/tests/modules/programs/atuin/fish.nix index 527943d67..ae3122cf1 100644 --- a/tests/modules/programs/atuin/fish.nix +++ b/tests/modules/programs/atuin/fish.nix @@ -19,6 +19,6 @@ assertFileExists home-files/.config/fish/config.fish assertFileContains \ home-files/.config/fish/config.fish \ - 'atuin init fish | source' + '@atuin@/bin/atuin init fish | source' ''; } diff --git a/tests/modules/programs/atuin/set-flags.nix b/tests/modules/programs/atuin/set-flags.nix new file mode 100644 index 000000000..7e3a7982f --- /dev/null +++ b/tests/modules/programs/atuin/set-flags.nix @@ -0,0 +1,39 @@ +{ lib, ... }: + +{ + programs = { + atuin.enable = true; + atuin.flags = [ "--disable-ctrl-r" "--disable-up-arrow" ]; + bash = { + enable = true; + enableCompletion = false; + }; + zsh.enable = true; + fish.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 = { + atuin = { }; + bash-preexec = { }; + }; + + nmt.script = '' + assertFileExists home-files/.bashrc + assertFileContains \ + home-files/.bashrc \ + "eval \"\$(@atuin@/bin/atuin init bash '--disable-ctrl-r' '--disable-up-arrow')\"" + + assertFileExists home-files/.zshrc + assertFileContains \ + home-files/.zshrc \ + "eval \"\$(@atuin@/bin/atuin init zsh '--disable-ctrl-r' '--disable-up-arrow')\"" + assertFileExists home-files/.config/fish/config.fish + assertFileContains \ + home-files/.config/fish/config.fish \ + "@atuin@/bin/atuin init fish --disable-ctrl-r --disable-up-arrow | source" + ''; +} diff --git a/tests/modules/programs/atuin/zsh.nix b/tests/modules/programs/atuin/zsh.nix index 45f0254ca..14adddcac 100644 --- a/tests/modules/programs/atuin/zsh.nix +++ b/tests/modules/programs/atuin/zsh.nix @@ -15,6 +15,6 @@ assertFileExists home-files/.zshrc assertFileContains \ home-files/.zshrc \ - 'eval "$(@atuin@/bin/atuin init zsh)"' + 'eval "$(@atuin@/bin/atuin init zsh )"' ''; }