Skip to content

Commit

Permalink
git-worktree-switcher: init module
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusauler committed Dec 23, 2024
1 parent 66c5d8b commit 10f961f
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 0 deletions.
11 changes: 11 additions & 0 deletions modules/misc/news.nix
Original file line number Diff line number Diff line change
Expand Up @@ -1899,6 +1899,17 @@ in {
registry with the option 'programs.nushell.plugins'.
'';
}

{
time = "2024-12-14T20:35:07+00:00";
message = ''
A new module is available: 'programs.git-worktree-switcher'.
git-worktree-switcher allows you to quickly switch git worktrees.
It includes shell completions for Bash, Fish and Zsh.
See https://github.com/mateusauler/git-worktree-switcher for more.
'';
}
];
};
}
1 change: 1 addition & 0 deletions modules/modules.nix
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ let
./programs/gh-dash.nix
./programs/git-cliff.nix
./programs/git-credential-oauth.nix
./programs/git-worktree-switcher.nix
./programs/git.nix
./programs/gitui.nix
./programs/gnome-shell.nix
Expand Down
52 changes: 52 additions & 0 deletions modules/programs/git-worktree-switcher.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{ pkgs, config, lib, ... }:

let
inherit (lib) mkEnableOption mkOption mkPackageOption optionalString;

cfg = config.programs.git-worktree-switcher;

initScript = shell:
if (shell == "fish") then ''
${lib.getExe pkgs.git-worktree-switcher} init ${shell} | source
'' else ''
eval "$(${lib.getExe pkgs.git-worktree-switcher} init ${shell})"
'';
in {
meta.maintainers = [ lib.maintainers.mateusauler ];

options.programs.git-worktree-switcher = {
enable = mkEnableOption "git-worktree-switcher";
package = mkPackageOption pkgs "git-worktree-switcher" { };
enableBashIntegration = mkOption {
type = lib.types.bool;
default = true;
description = ''
Whether to enable git-worktree-switcher's Bash integration.
'';
};
enableFishIntegration = mkOption {
type = lib.types.bool;
default = config.programs.fish.enable;
description = ''
Whether to enable git-worktree-switcher's Fish integration.
'';
};
enableZshIntegration = mkOption {
type = lib.types.bool;
default = config.programs.zsh.enable;
description = ''
Whether to enable git-worktree-switcher's Zsh integration.
'';
};
};

config = lib.mkIf cfg.enable {
home.packages = [ cfg.package ];
programs.bash.initExtra =
optionalString cfg.enableBashIntegration (initScript "bash");
programs.fish.interactiveShellInit =
optionalString cfg.enableFishIntegration (initScript "fish");
programs.zsh.initExtra =
optionalString cfg.enableZshIntegration (initScript "zsh");
};
}
1 change: 1 addition & 0 deletions tests/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ in import nmtSrc {
./modules/programs/git
./modules/programs/git-cliff
./modules/programs/git-credential-oauth
./modules/programs/git-worktree-switcher
./modules/programs/gpg
./modules/programs/gradle
./modules/programs/granted
Expand Down
17 changes: 17 additions & 0 deletions tests/modules/programs/git-worktree-switcher/bash.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{ ... }:

{
programs = {
bash.enable = true;
git-worktree-switcher.enable = true;
};

test.stubs.git-worktree-switcher = { name = "git-worktree-switcher"; };

nmt.script = ''
assertFileExists home-files/.bashrc
assertFileContains \
home-files/.bashrc \
'eval "$(@git-worktree-switcher@/bin/git-worktree-switcher init bash)"'
'';
}
5 changes: 5 additions & 0 deletions tests/modules/programs/git-worktree-switcher/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
git-worktree-switcher-bash = ./bash.nix;
git-worktree-switcher-fish = ./fish.nix;
git-worktree-switcher-zsh = ./zsh.nix;
}
17 changes: 17 additions & 0 deletions tests/modules/programs/git-worktree-switcher/fish.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{ ... }:

{
programs = {
fish.enable = true;
git-worktree-switcher.enable = true;
};

test.stubs.git-worktree-switcher = { name = "git-worktree-switcher"; };

nmt.script = ''
assertFileExists home-files/.config/fish/config.fish
assertFileContains \
home-files/.config/fish/config.fish \
'@git-worktree-switcher@/bin/git-worktree-switcher init fish | source'
'';
}
17 changes: 17 additions & 0 deletions tests/modules/programs/git-worktree-switcher/zsh.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{ ... }:

{
programs = {
zsh.enable = true;
git-worktree-switcher.enable = true;
};

test.stubs.git-worktree-switcher = { name = "git-worktree-switcher"; };

nmt.script = ''
assertFileExists home-files/.zshrc
assertFileContains \
home-files/.zshrc \
'eval "$(@git-worktree-switcher@/bin/git-worktree-switcher init zsh)"'
'';
}

0 comments on commit 10f961f

Please sign in to comment.