diff --git a/modules/programs/yazi.nix b/modules/programs/yazi.nix index bb0f07e48..3dc167bc1 100644 --- a/modules/programs/yazi.nix +++ b/modules/programs/yazi.nix @@ -6,7 +6,7 @@ let cfg = config.programs.yazi; tomlFormat = pkgs.formats.toml { }; - shellIntegration = '' + bashIntegration = '' function ya() { tmp="$(mktemp -t "yazi-cwd.XXXXX")" yazi --cwd-file="$tmp" @@ -16,6 +16,29 @@ let rm -f -- "$tmp" } ''; + + fishIntegration = '' + function ya + set tmp (mktemp -t "yazi-cwd.XXXXX") + yazi --cwd-file="$tmp" + if set cwd (cat -- "$tmp") && [ -n "$cwd" ] && [ "$cwd" != "$PWD" ] + cd -- "$cwd" + end + rm -f -- "$tmp" + end + ''; + + nushellIntegration = '' + def-env ya [] { + let tmp = (mktemp -t "yazi-cwd.XXXXX") + yazi --cwd-file $tmp + let cwd = (cat -- $tmp) + if $cwd != "" and $cwd != $env.PWD { + cd $cwd + } + rm -f $tmp + } + ''; in { meta.maintainers = [ maintainers.xyenon ]; @@ -33,6 +56,10 @@ in { enableZshIntegration = mkEnableOption "Zsh integration"; + enableFishIntegration = mkEnableOption "Fish integration"; + + enableNushellIntegration = mkEnableOption "Nushell integration"; + keymap = mkOption { type = tomlFormat.type; default = { }; @@ -113,9 +140,15 @@ in { config = mkIf cfg.enable { home.packages = [ cfg.package ]; - programs.bash.initExtra = mkIf cfg.enableBashIntegration shellIntegration; + programs.bash.initExtra = mkIf cfg.enableBashIntegration bashIntegration; - programs.zsh.initExtra = mkIf cfg.enableZshIntegration shellIntegration; + programs.zsh.initExtra = mkIf cfg.enableZshIntegration bashIntegration; + + programs.fish.interactiveShellInit = + mkIf cfg.enableFishIntegration fishIntegration; + + programs.nushell.extraConfig = + mkIf cfg.enableNushellIntegration nushellIntegration; xdg.configFile = { "yazi/keymap.toml" = mkIf (cfg.keymap != { }) { diff --git a/tests/modules/programs/yazi/default.nix b/tests/modules/programs/yazi/default.nix index 65104a8b4..09d52ac3d 100644 --- a/tests/modules/programs/yazi/default.nix +++ b/tests/modules/programs/yazi/default.nix @@ -2,4 +2,6 @@ yazi-settings = ./settings.nix; yazi-bash-integration-enabled = ./bash-integration-enabled.nix; yazi-zsh-integration-enabled = ./zsh-integration-enabled.nix; + yazi-fish-integration-enabled = ./fish-integration-enabled.nix; + yazi-nushell-integration-enabled = ./nushell-integration-enabled.nix; } diff --git a/tests/modules/programs/yazi/fish-integration-enabled.nix b/tests/modules/programs/yazi/fish-integration-enabled.nix new file mode 100644 index 000000000..5568f5b5c --- /dev/null +++ b/tests/modules/programs/yazi/fish-integration-enabled.nix @@ -0,0 +1,27 @@ +{ ... }: + +let + shellIntegration = '' + function ya + set tmp (mktemp -t "yazi-cwd.XXXXX") + yazi --cwd-file="$tmp" + if set cwd (cat -- "$tmp") && [ -n "$cwd" ] && [ "$cwd" != "$PWD" ] + cd -- "$cwd" + end + rm -f -- "$tmp" + end + ''; +in { + programs.fish.enable = true; + + programs.yazi = { + enable = true; + enableFishIntegration = true; + }; + + test.stubs.yazi = { }; + + nmt.script = '' + assertFileContains home-files/.config/fish/config.fish '${shellIntegration}' + ''; +} diff --git a/tests/modules/programs/yazi/nushell-integration-enabled.nix b/tests/modules/programs/yazi/nushell-integration-enabled.nix new file mode 100644 index 000000000..d12f747fa --- /dev/null +++ b/tests/modules/programs/yazi/nushell-integration-enabled.nix @@ -0,0 +1,33 @@ +{ pkgs, ... }: + +let + shellIntegration = '' + def-env ya [] { + let tmp = (mktemp -t "yazi-cwd.XXXXX") + yazi --cwd-file $tmp + let cwd = (cat -- $tmp) + if $cwd != "" and $cwd != $env.PWD { + cd $cwd + } + rm -f $tmp + } + ''; +in { + programs.nushell.enable = true; + + programs.yazi = { + enable = true; + enableNushellIntegration = true; + }; + + test.stubs.yazi = { }; + + nmt.script = let + configPath = if pkgs.stdenv.isDarwin then + "home-files/Library/Application Support/nushell/config.nu" + else + "home-files/.config/nushell/config.nu"; + in '' + assertFileContains '${configPath}' '${shellIntegration}' + ''; +}