From 4481a16d1ac5bff4a77c608cefe08c9b9efe840d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=AFl=20Senhaji?= <134528+iSma@users.noreply.github.com> Date: Tue, 14 Jan 2025 17:52:56 +0100 Subject: [PATCH] yazi: improve fish integration Calls yazi as `command yazi`, allowing to use "yazi" as `shellWrapperName`. Also defines the wrapper with `programs.fish.functions` instead of `interactiveShellInit`. --- modules/misc/news.nix | 13 +++++++++++++ modules/programs/yazi.nix | 14 ++++++-------- .../yazi/fish-integration-enabled.nix | 19 +++++-------------- .../yazi/fish-integration-expected.fish | 8 ++++++++ 4 files changed, 32 insertions(+), 22 deletions(-) create mode 100644 tests/modules/programs/yazi/fish-integration-expected.fish diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 7a3604be..c578d237 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -1960,6 +1960,19 @@ in { as well as wf-shell. ''; } + + { + time = "2025-01-21T17:28:13+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. + ''; + } ]; }; } + diff --git a/modules/programs/yazi.nix b/modules/programs/yazi.nix index 314c4c5e..a17f2952 100644 --- a/modules/programs/yazi.nix +++ b/modules/programs/yazi.nix @@ -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 = '' @@ -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 = diff --git a/tests/modules/programs/yazi/fish-integration-enabled.nix b/tests/modules/programs/yazi/fish-integration-enabled.nix index 2231035b..8e54e5e7 100644 --- a/tests/modules/programs/yazi/fish-integration-enabled.nix +++ b/tests/modules/programs/yazi/fish-integration-enabled.nix @@ -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} ''; } diff --git a/tests/modules/programs/yazi/fish-integration-expected.fish b/tests/modules/programs/yazi/fish-integration-expected.fish new file mode 100644 index 00000000..d8f11f28 --- /dev/null +++ b/tests/modules/programs/yazi/fish-integration-expected.fish @@ -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