From 992b38f29cd7e50d88a2ae069133750beda010a4 Mon Sep 17 00:00:00 2001
From: XYenon <i@xyenon.bid>
Date: Thu, 4 Jan 2024 03:18:53 +0800
Subject: [PATCH] yazi: fix nushell integration

---
 modules/programs/yazi.nix                                 | 8 ++++++--
 .../modules/programs/yazi/nushell-integration-enabled.nix | 8 ++++++--
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/modules/programs/yazi.nix b/modules/programs/yazi.nix
index a3d687262..d0d941d13 100644
--- a/modules/programs/yazi.nix
+++ b/modules/programs/yazi.nix
@@ -30,8 +30,12 @@ let
 
   nushellIntegration = ''
     def --env ya [args?] {
-      let tmp = $"($env.TEMP)(char path_sep)yazi-cwd." + (random chars -l 5)
-      yazi $args --cwd-file $tmp
+      let tmp = (mktemp -t "yazi-cwd.XXXXX")
+      if ($args == null) {
+        yazi --cwd-file $tmp
+      } else {
+        yazi $args --cwd-file $tmp
+      }
       let cwd = (open $tmp)
       if $cwd != "" and $cwd != $env.PWD {
         cd $cwd
diff --git a/tests/modules/programs/yazi/nushell-integration-enabled.nix b/tests/modules/programs/yazi/nushell-integration-enabled.nix
index aefffb9e2..121e27567 100644
--- a/tests/modules/programs/yazi/nushell-integration-enabled.nix
+++ b/tests/modules/programs/yazi/nushell-integration-enabled.nix
@@ -3,8 +3,12 @@
 let
   shellIntegration = ''
     def --env ya [args?] {
-      let tmp = $"($env.TEMP)(char path_sep)yazi-cwd." + (random chars -l 5)
-      yazi $args --cwd-file $tmp
+      let tmp = (mktemp -t "yazi-cwd.XXXXX")
+      if ($args == null) {
+        yazi --cwd-file $tmp
+      } else {
+        yazi $args --cwd-file $tmp
+      }
       let cwd = (open $tmp)
       if $cwd != "" and $cwd != $env.PWD {
         cd $cwd