From f8405ccf87c80a853eb8d1e1eb208f47f5f9c83a Mon Sep 17 00:00:00 2001 From: In'Maldrerah Eyllisitryanmitore Date: Tue, 19 Mar 2024 13:34:58 +0000 Subject: [PATCH] yazi: add xonsh integration --- modules/programs/yazi.nix | 19 ++++++++++++ tests/modules/programs/yazi/default.nix | 1 + .../yazi/xonsh-integration-enabled.nix | 31 +++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 tests/modules/programs/yazi/xonsh-integration-enabled.nix diff --git a/modules/programs/yazi.nix b/modules/programs/yazi.nix index d7b880200d62..c15f71823a09 100644 --- a/modules/programs/yazi.nix +++ b/modules/programs/yazi.nix @@ -39,6 +39,21 @@ let rm -fp $tmp } ''; + + xonshIntegration = '' + def __yazi_init(): + def yy(args): + tmp = $(mktemp -t "yazi-cwd.XXXXX").strip() + $[yazi @(args) @(f"--cwd-file={tmp}")] + cwd = fp"{tmp}".read_text() + if cwd != "" and cwd != $PWD: + xonsh.dirstack.cd((cwd,)) + $[rm -f -- @(tmp)] + + aliases['yy'] = yy + __yazi_init() + del __yazi_init + ''; in { meta.maintainers = with maintainers; [ xyenon eljamm ]; @@ -64,6 +79,8 @@ in { enableNushellIntegration = mkEnableOption "Nushell integration"; + enableXonshIntegration = mkEnableOption "Xonsh integration"; + keymap = mkOption { type = tomlFormat.type; default = { }; @@ -200,6 +217,8 @@ in { programs.nushell.extraConfig = mkIf cfg.enableNushellIntegration nushellIntegration; + programs.xonsh.xonshrc = mkIf cfg.enableXonshIntegration xonshIntegration; + xdg.configFile = { "yazi/keymap.toml" = mkIf (cfg.keymap != { }) { source = tomlFormat.generate "yazi-keymap" cfg.keymap; diff --git a/tests/modules/programs/yazi/default.nix b/tests/modules/programs/yazi/default.nix index ec543c84d7b6..1e01e7f80ba3 100644 --- a/tests/modules/programs/yazi/default.nix +++ b/tests/modules/programs/yazi/default.nix @@ -5,4 +5,5 @@ yazi-zsh-integration-enabled = ./zsh-integration-enabled.nix; yazi-fish-integration-enabled = ./fish-integration-enabled.nix; yazi-nushell-integration-enabled = ./nushell-integration-enabled.nix; + yazi-xonsh-integration-enabled = ./xonsh-integration-enabled.nix; } diff --git a/tests/modules/programs/yazi/xonsh-integration-enabled.nix b/tests/modules/programs/yazi/xonsh-integration-enabled.nix new file mode 100644 index 000000000000..313198140fe3 --- /dev/null +++ b/tests/modules/programs/yazi/xonsh-integration-enabled.nix @@ -0,0 +1,31 @@ +{ ... }: + +let + shellIntegration = '' + def __yazi_init(): + def ya(args): + tmp = $(mktemp -t "yazi-cwd.XXXXX") + $[yazi @(args) @(f"--cwd-file={tmp}")] + cwd = fp"{tmp}".read_text() + if cwd != "" and cwd != $PWD: + xonsh.dirstack.cd(cwd) + $[rm -f -- @(tmp)] + + aliases['ya'] = ya + __yazi_init() + del __yazi_init + ''; +in { + programs.xonsh.enable = true; + + programs.yazi = { + enable = true; + enableXonshIntegration = true; + }; + + test.stubs.yazi = { }; + + nmt.script = '' + assertFileContains home-files/.config/xonsh/rc.xsh '${shellIntegration}' + ''; +}