From 8537920706fafab12a2c2a138dfb6f5c35a6b240 Mon Sep 17 00:00:00 2001 From: Evan Stoll Date: Fri, 18 Sep 2020 09:07:40 -0400 Subject: [PATCH] autojump: add module This also deprecates the `programs.bash.enableAutojump` option in favor of this module. --- .github/CODEOWNERS | 3 + modules/misc/news.nix | 10 ++++ modules/modules.nix | 1 + modules/programs/autojump.nix | 56 +++++++++++++++++++ modules/programs/bash.nix | 20 +++---- tests/default.nix | 1 + .../programs/autojump/default-settings.nix | 13 +++++ tests/modules/programs/autojump/default.nix | 1 + 8 files changed, 93 insertions(+), 12 deletions(-) create mode 100644 modules/programs/autojump.nix create mode 100644 tests/modules/programs/autojump/default-settings.nix create mode 100644 tests/modules/programs/autojump/default.nix diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 998d1fa5b..3f335e6f8 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -33,6 +33,9 @@ /modules/programs/aria2.nix @JustinLovinger +/modules/programs/autojump.nix @evanjs +/tests/modules/programs/autojump @evanjs + /modules/programs/autorandr.nix @uvNikita /modules/programs/bash.nix @rycee diff --git a/modules/misc/news.nix b/modules/misc/news.nix index b64300f5b..4ef46aeb9 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -1687,6 +1687,16 @@ in A new module is available: 'programs.mu'. ''; } + + { + time = "2020-10-08T21:28:16+00:00"; + message = '' + A new module is available: 'programs.autojump' + + The option `programs.bash.enableAutojump` is deprecated and this new + module should be used instead. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index 717834302..549e64456 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -49,6 +49,7 @@ let (loadModule ./programs/alot.nix { }) (loadModule ./programs/aria2.nix { }) (loadModule ./programs/astroid.nix { }) + (loadModule ./programs/autojump.nix { }) (loadModule ./programs/autorandr.nix { }) (loadModule ./programs/bash.nix { }) (loadModule ./programs/bat.nix { }) diff --git a/modules/programs/autojump.nix b/modules/programs/autojump.nix new file mode 100644 index 000000000..db3bdaf59 --- /dev/null +++ b/modules/programs/autojump.nix @@ -0,0 +1,56 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.programs.autojump; + package = pkgs.autojump; + +in { + meta.maintainers = [ maintainers.evanjs ]; + + options.programs.autojump = { + enable = mkEnableOption "autojump"; + + enableBashIntegration = mkOption { + default = true; + type = types.bool; + description = '' + Whether to enable Bash integration. + ''; + }; + + enableZshIntegration = mkOption { + default = true; + type = types.bool; + description = '' + Whether to enable Zsh integration. + ''; + }; + + enableFishIntegration = mkOption { + default = true; + type = types.bool; + description = '' + Whether to enable Fish integration. + ''; + }; + }; + + config = mkIf cfg.enable { + home.packages = [ package ]; + + programs.bash.initExtra = mkIf cfg.enableBashIntegration (mkBefore '' + . ${package}/share/autojump/autojump.bash + ''); + + programs.zsh.initExtra = mkIf cfg.enableZshIntegration '' + . ${package}/share/autojump/autojump.zsh + ''; + + programs.fish.promptInit = mkIf cfg.enableFishIntegration '' + . ${package}/share/autojump/autojump.fish + ''; + }; +} diff --git a/modules/programs/bash.nix b/modules/programs/bash.nix index 45fe368bd..6338f5e4a 100644 --- a/modules/programs/bash.nix +++ b/modules/programs/bash.nix @@ -11,6 +11,14 @@ in { meta.maintainers = [ maintainers.rycee ]; + imports = [ + (mkRenamedOptionModule [ "programs" "bash" "enableAutojump" ] [ + "programs" + "autojump" + "enable" + ]) + ]; + options = { programs.bash = { enable = mkEnableOption "GNU Bourne-Again SHell"; @@ -94,12 +102,6 @@ in ''; }; - enableAutojump = mkOption { - default = false; - type = types.bool; - description = "Enable the autojump navigation tool."; - }; - profileExtra = mkOption { default = ""; type = types.lines; @@ -176,9 +178,6 @@ in ${aliasesStr} - ${optionalString cfg.enableAutojump - ". ${pkgs.autojump}/share/autojump/autojump.bash"} - ${cfg.initExtra} fi ''; @@ -216,9 +215,6 @@ in ${cfg.logoutExtra} ''; }; - - home.packages = - optional (cfg.enableAutojump) pkgs.autojump; } ); } diff --git a/tests/default.nix b/tests/default.nix index acb115f8e..e744204a9 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -41,6 +41,7 @@ import nmt { ./modules/programs/alacritty ./modules/programs/alot ./modules/programs/aria2 + ./modules/programs/autojump ./modules/programs/bash ./modules/programs/browserpass ./modules/programs/dircolors diff --git a/tests/modules/programs/autojump/default-settings.nix b/tests/modules/programs/autojump/default-settings.nix new file mode 100644 index 000000000..2f6670272 --- /dev/null +++ b/tests/modules/programs/autojump/default-settings.nix @@ -0,0 +1,13 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + config = { + programs.autojump.enable = true; + + nmt.script = '' + assertFileExists home-path/bin/autojump + ''; + }; +} diff --git a/tests/modules/programs/autojump/default.nix b/tests/modules/programs/autojump/default.nix new file mode 100644 index 000000000..eaaaba3b4 --- /dev/null +++ b/tests/modules/programs/autojump/default.nix @@ -0,0 +1 @@ +{ autojump = ./default-settings.nix; }