From cb80ca81da9b62c210360ffa2aedbf237571f686 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Istv=C3=A1n=20Donk=C3=B3?= Date: Mon, 15 Jan 2024 17:30:43 +0100 Subject: [PATCH] feat: add `YAZI_LEVEL` env variable for shells (#514) --- yazi-plugin/src/external/shell.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/yazi-plugin/src/external/shell.rs b/yazi-plugin/src/external/shell.rs index c93115a1..fe9fc9c2 100644 --- a/yazi-plugin/src/external/shell.rs +++ b/yazi-plugin/src/external/shell.rs @@ -1,4 +1,4 @@ -use std::{ffi::OsString, process::Stdio}; +use std::{env, ffi::OsString, process::Stdio}; use anyhow::Result; use tokio::process::{Child, Command}; @@ -29,9 +29,12 @@ impl ShellOpt { } pub fn shell(opt: ShellOpt) -> Result { + let level = env::var("YAZI_LEVEL").ok().and_then(|s| s.parse::().ok()).unwrap_or(0); + #[cfg(unix)] return Ok(unsafe { Command::new("sh") + .env("YAZI_LEVEL", (level + 1).to_string()) .arg("-c") .stdin(opt.stdio()) .stdout(opt.stdio()) @@ -56,6 +59,7 @@ pub fn shell(opt: ShellOpt) -> Result { let expanded = parser::parse(opt.cmd.to_string_lossy().as_ref(), &args_); Ok( Command::new("cmd") + .env("YAZI_LEVEL", (level + 1).to_string()) .arg("/C") .args(&expanded) .stdin(opt.stdio())