1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-04-09 10:34:44 +00:00

yazi: add xonsh integration

This commit is contained in:
In'Maldrerah Eyllisitryanmitore 2024-03-19 13:34:58 +00:00 committed by paki23
parent dd3ce8fed8
commit 35a843c2fa
No known key found for this signature in database
GPG key ID: 13160FFB4CEB03F2
3 changed files with 53 additions and 0 deletions
modules/programs
tests/modules/programs/yazi

View file

@ -6,6 +6,8 @@ let
cfg = config.programs.yazi;
tomlFormat = pkgs.formats.toml { };
in {
meta.maintainers = with lib.maintainers; [ eljamm khaneliman xyenon ];
@ -35,6 +37,8 @@ in {
enableZshIntegration =
lib.hm.shell.mkZshIntegrationOption { inherit config; };
enableXonshIntegration = mkEnableOption "Xonsh integration";
keymap = mkOption {
type = tomlFormat.type;
default = { };
@ -193,6 +197,21 @@ in {
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 {
bash.initExtra = mkIf cfg.enableBashIntegration bashIntegration;
@ -205,6 +224,8 @@ in {
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;

View file

@ -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;
}

View file

@ -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}'
'';
}