Skip to content

Commit

Permalink
yazi: add xonsh integration
Browse files Browse the repository at this point in the history
  • Loading branch information
inmaldrerah committed Apr 3, 2024
1 parent 5d688e1 commit aa56eda
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
20 changes: 20 additions & 0 deletions modules/programs/yazi.nix
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@ let
rm -fp $tmp
}
'';

xonshIntegration = ''
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 {
meta.maintainers = [ maintainers.xyenon ];

Expand All @@ -60,6 +75,8 @@ in {

enableNushellIntegration = mkEnableOption "Nushell integration";

enableXonshIntegration = mkEnableOption "Xonsh integration";

keymap = mkOption {
type = tomlFormat.type;
default = { };
Expand Down Expand Up @@ -150,6 +167,9 @@ in {
programs.nushell.extraConfig =
mkIf cfg.enableNushellIntegration nushellIntegration;

programs.xonsh.rcFiles."yazi.xsh".text =
mkIf cfg.enableXonshIntegration xonshIntegration;

xdg.configFile = {
"yazi/keymap.toml" = mkIf (cfg.keymap != { }) {
source = tomlFormat.generate "yazi-keymap" cfg.keymap;
Expand Down
1 change: 1 addition & 0 deletions tests/modules/programs/yazi/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,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;
}
31 changes: 31 additions & 0 deletions tests/modules/programs/yazi/xonsh-integration-enabled.nix
Original file line number Diff line number Diff line change
@@ -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.d/yazi.xsh '${shellIntegration}'
'';
}

0 comments on commit aa56eda

Please sign in to comment.