Skip to content

Commit

Permalink
feat: add YAZI_LEVEL env variable for shells (#514)
Browse files Browse the repository at this point in the history
  • Loading branch information
isti115 committed Jan 15, 2024
1 parent ca78f4c commit cb80ca8
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion yazi-plugin/src/external/shell.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -29,9 +29,12 @@ impl ShellOpt {
}

pub fn shell(opt: ShellOpt) -> Result<Child> {
let level = env::var("YAZI_LEVEL").ok().and_then(|s| s.parse::<u32>().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())
Expand All @@ -56,6 +59,7 @@ pub fn shell(opt: ShellOpt) -> Result<Child> {
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())
Expand Down

0 comments on commit cb80ca8

Please sign in to comment.