From 7413408b047c12125cf3b76e5d8fa53c297ac1ee Mon Sep 17 00:00:00 2001 From: XYenon Date: Fri, 22 Sep 2023 19:00:16 +0800 Subject: [PATCH] yazi: add fish and nushell integration PR #4493 --- modules/programs/yazi.nix | 39 +++++++++++++++++-- tests/modules/programs/yazi/default.nix | 2 + .../yazi/fish-integration-enabled.nix | 27 +++++++++++++ .../yazi/nushell-integration-enabled.nix | 33 ++++++++++++++++ 4 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 tests/modules/programs/yazi/fish-integration-enabled.nix create mode 100644 tests/modules/programs/yazi/nushell-integration-enabled.nix diff --git a/modules/programs/yazi.nix b/modules/programs/yazi.nix index bb0f07e4..3dc167bc 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 65104a8b..09d52ac3 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 00000000..5568f5b5 --- /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 00000000..d12f747f --- /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}' + ''; +}