Skip to content

Commit

Permalink
yazi: improve fish integration
Browse files Browse the repository at this point in the history
Calls yazi as `command yazi`, allowing to use "yazi" as `shellWrapperName`.
Also defines the wrapper with `programs.fish.functions` instead of
`interactiveShellInit`.
  • Loading branch information
iSma committed Jan 16, 2025
1 parent fc52a21 commit 0483361
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 22 deletions.
12 changes: 12 additions & 0 deletions modules/misc/news.nix
Original file line number Diff line number Diff line change
Expand Up @@ -1960,6 +1960,18 @@ in {
as well as wf-shell.
'';
}
{
time = "2025-01-16T18:00:00+00:00";
condition = with config.programs.yazi; enable && enableFishIntegration;
message = ''
Yazi's fish shell integration wrapper now calls the 'yazi' executable
directly, ignoring any shell aliases with the same name.
Your configuration may break if you rely on the wrapper calling a
'yazi' alias.
'';
}
];
};
}

14 changes: 6 additions & 8 deletions modules/programs/yazi.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ let
'';

fishIntegration = ''
function ${cfg.shellWrapperName}
set tmp (mktemp -t "yazi-cwd.XXXXX")
yazi $argv --cwd-file="$tmp"
if set cwd (cat -- "$tmp"); and [ -n "$cwd" ]; and [ "$cwd" != "$PWD" ]
builtin cd -- "$cwd"
end
rm -f -- "$tmp"
set -l tmp (mktemp -t "yazi-cwd.XXXXX")
command yazi $argv --cwd-file="$tmp"
if set cwd (cat -- "$tmp"); and [ -n "$cwd" ]; and [ "$cwd" != "$PWD" ]
builtin cd -- "$cwd"
end
rm -f -- "$tmp"
'';

nushellIntegration = ''
Expand Down Expand Up @@ -202,7 +200,7 @@ in {

programs.zsh.initExtra = mkIf cfg.enableZshIntegration bashIntegration;

programs.fish.interactiveShellInit =
programs.fish.functions.${cfg.shellWrapperName} =
mkIf cfg.enableFishIntegration fishIntegration;

programs.nushell.extraConfig =
Expand Down
19 changes: 5 additions & 14 deletions tests/modules/programs/yazi/fish-integration-enabled.nix
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
{ ... }:
{ config, ... }:

let
shellIntegration = ''
function yy
set tmp (mktemp -t "yazi-cwd.XXXXX")
yazi $argv --cwd-file="$tmp"
if set cwd (cat -- "$tmp"); and [ -n "$cwd" ]; and [ "$cwd" != "$PWD" ]
builtin cd -- "$cwd"
end
rm -f -- "$tmp"
end
'';
in {
{
programs.fish.enable = true;

programs.yazi = {
enable = true;
shellWrapperName = "yy";
enableFishIntegration = true;
};

test.stubs.yazi = { };

nmt.script = ''
assertFileContains home-files/.config/fish/config.fish '${shellIntegration}'
assertFileContent home-files/.config/fish/functions/${config.programs.yazi.shellWrapperName}.fish \
${./fish-integration-expected.fish}
'';
}
8 changes: 8 additions & 0 deletions tests/modules/programs/yazi/fish-integration-expected.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function yy
set -l tmp (mktemp -t "yazi-cwd.XXXXX")
command yazi $argv --cwd-file="$tmp"
if set cwd (cat -- "$tmp"); and [ -n "$cwd" ]; and [ "$cwd" != "$PWD" ]
builtin cd -- "$cwd"
end
rm -f -- "$tmp"
end

0 comments on commit 0483361

Please sign in to comment.