Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zellij: add fish completions & autostart options #5333

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions modules/lib/maintainers.nix
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,12 @@
keys =
[{ fingerprint = "75F0 AB7C FE01 D077 AEE6 CAFD 353E 4A18 EE0F AB72"; }];
};
tennox = {
name = "Manu";
github = "tennox";
githubId = 2084639;
matrix = "@tennox:matrix.org";
};
tensor5 = {
github = "tensor5";
githubId = 1545895;
Expand Down
41 changes: 29 additions & 12 deletions modules/programs/git.nix
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,13 @@ in {

package = mkPackageOption pkgs "difftastic" { };

enableAsDifftool = mkEnableOption "" // {
description = ''
Enable the {command}`difftastic` syntax highlighter as a git difftool.
See <https://github.com/Wilfred/difftastic>.
'';
};

background = mkOption {
type = types.enum [ "light" "dark" ];
default = "light";
Expand Down Expand Up @@ -590,18 +597,28 @@ in {
};
})

(mkIf cfg.difftastic.enable {
home.packages = [ cfg.difftastic.package ];

programs.git.iniContent = let
difftCommand = concatStringsSep " " [
"${getExe cfg.difftastic.package}"
"--color ${cfg.difftastic.color}"
"--background ${cfg.difftastic.background}"
"--display ${cfg.difftastic.display}"
];
in { diff.external = difftCommand; };
})
(let
difftCommand = concatStringsSep " " [
"${getExe cfg.difftastic.package}"
"--color ${cfg.difftastic.color}"
"--background ${cfg.difftastic.background}"
"--display ${cfg.difftastic.display}"
];
in (lib.mkMerge [
(mkIf cfg.difftastic.enable {
home.packages = [ cfg.difftastic.package ];
programs.git.iniContent = { diff.external = difftCommand; };
})
(mkIf cfg.difftastic.enableAsDifftool {
home.packages = [ cfg.difftastic.package ];
programs.git.iniContent = {
diff = { tool = lib.mkDefault "difftastic"; };
difftool = {
difftastic = { cmd = "${difftCommand} $LOCAL $REMOTE"; };
};
};
})
]))

(let
deltaPackage = cfg.delta.package;
Expand Down
45 changes: 38 additions & 7 deletions modules/programs/zellij.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let
zellijCmd = getExe cfg.package;

in {
meta.maintainers = [ hm.maintainers.mainrs ];
meta.maintainers = with hm.maintainers; [ mainrs tennox ];

options.programs.zellij = {
enable = mkEnableOption "zellij";
Expand Down Expand Up @@ -49,9 +49,27 @@ in {
default = false;
};

enableFishIntegration = mkEnableOption "Fish integration" // {
default = false;
enableFishIntegration = mkEnableOption
"enable fish integration (enables both enableFishAutoStart and enableFishCompletions)"
// {
default = false;
};
enableFishCompletions = mkEnableOption "load zellij completions" // {
default = true;
};
enableFishAutoStart =
mkEnableOption "autostart zellij in interactive sessions" // {
default = false;
};
autoStartAttachIfSessionExists = mkEnableOption
"attach to the default session, if a zellij session already exists (otherwise starting a new session)"
// {
default = false;
};
autoStartExitShellOnZellijExit =
mkEnableOption "exit the shell when zellij exits." // {
default = false;
};
};

config = mkIf cfg.enable {
Expand All @@ -77,9 +95,22 @@ in {
eval "$(${zellijCmd} setup --generate-auto-start zsh)"
'');

programs.fish.interactiveShellInit = mkIf cfg.enableFishIntegration
(mkOrder 200 ''
eval (${zellijCmd} setup --generate-auto-start fish | string collect)
'');
home.sessionVariables = {
ZELLIJ_AUTO_ATTACH =
if cfg.autoStartAttachIfSessionExists then "true" else "false";
ZELLIJ_AUTO_EXIT =
if cfg.autoStartExitShellOnZellijExit then "true" else "false";
};

programs.fish.interactiveShellInit = mkIf (cfg.enableFishIntegration
|| cfg.enableFishAutoStart || cfg.enableFishCompletions) (mkOrder 200
((if cfg.enableFishIntegration || cfg.enableFishCompletions then ''
eval (${zellijCmd} setup --generate-completion fish | string collect)
'' else
"") + (if cfg.enableFishIntegration || cfg.enableFishAutoStart then ''
eval (${zellijCmd} setup --generate-auto-start fish | string collect)
'' else
"")));

};
}
14 changes: 14 additions & 0 deletions tests/modules/programs/zellij/enable-shells.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
enableBashIntegration = true;
enableZshIntegration = true;
enableFishIntegration = true;
enableFishAutoStart = true;
enableFishCompletions = true;
autoStartAttachIfSessionExists = true;
autoStartExitShellOnZellijExit = true;
};
bash.enable = true;
zsh.enable = true;
Expand Down Expand Up @@ -37,5 +41,15 @@
assertFileContains \
home-files/.config/fish/config.fish \
'eval (@zellij@/bin/dummy setup --generate-auto-start fish | string collect)'
assertFileContains \
home-files/.config/fish/config.fish \
'eval (@zellij@/bin/dummy setup --generate-completion fish | string collect)'
assertFileExists home-path/etc/profile.d/hm-session-vars.sh
assertFileContains \
home-path/etc/profile.d/hm-session-vars.sh \
'export ZELLIJ_AUTO_ATTACH="true"'
assertFileContains \
home-path/etc/profile.d/hm-session-vars.sh \
'export ZELLIJ_AUTO_EXIT="true"'
'';
}
Loading