Skip to content

Commit 9fd6495

Browse files
committed
..
1 parent c562a1c commit 9fd6495

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

yazi-core/src/tab/commands/shell.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,34 @@ use std::{borrow::Cow, fmt::Display};
33
use anyhow::bail;
44
use yazi_config::{open::Opener, popup::InputCfg};
55
use yazi_proxy::{AppProxy, InputProxy, TasksProxy};
6-
use yazi_shared::event::{CmdCow, Data};
6+
use yazi_shared::{event::{CmdCow, Data}, url::Url};
77

88
use crate::tab::Tab;
99

1010
pub struct Opt {
11-
run: Cow<'static, str>,
11+
run: Cow<'static, str>,
12+
cwd: Option<Url>,
13+
1214
block: bool,
1315
orphan: bool,
1416
interactive: bool,
15-
cursor: Option<usize>,
17+
18+
cursor: Option<usize>,
1619
}
1720

1821
impl TryFrom<CmdCow> for Opt {
1922
type Error = anyhow::Error;
2023

2124
fn try_from(mut c: CmdCow) -> Result<Self, Self::Error> {
2225
let me = Self {
23-
run: c.take_first_str().unwrap_or_default(),
26+
run: c.take_first_str().unwrap_or_default(),
27+
cwd: c.take_url("cwd"),
28+
2429
block: c.bool("block"),
2530
orphan: c.bool("orphan"),
2631
interactive: c.bool("interactive"),
27-
cursor: c.get("cursor").and_then(Data::as_usize),
32+
33+
cursor: c.get("cursor").and_then(Data::as_usize),
2834
};
2935

3036
if me.cursor.is_some_and(|c| c > me.run.chars().count()) {
@@ -46,7 +52,7 @@ impl Tab {
4652
Err(e) => return AppProxy::notify_warn("`shell` command", e),
4753
};
4854

49-
let cwd = self.cwd().clone();
55+
let cwd = opt.cwd.take().unwrap_or_else(|| self.cwd().clone());
5056
let selected = self.hovered_and_selected(true).cloned().collect();
5157
tokio::spawn(async move {
5258
if opt.interactive {

yazi-plugin/preset/plugins/zoxide.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ local function setup(_, opts)
6767
"cd",
6868
function()
6969
ya.manager_emit("shell", {
70+
cwd = fs.cwd(),
7071
orphan = true,
7172
"zoxide add " .. ya.quote(tostring(cx.active.current.cwd)),
7273
})

yazi-plugin/src/fs/fs.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::{Error, bindings::{Cast, Cha}, file::File, url::{Url, UrlRef}};
88
pub fn compose(lua: &Lua) -> mlua::Result<Table> {
99
let index = lua.create_function(|lua, (ts, key): (Table, mlua::String)| {
1010
let value = match key.as_bytes().as_ref() {
11+
b"cwd" => cwd(lua)?,
1112
b"cha" => cha(lua)?,
1213
b"write" => write(lua)?,
1314
b"remove" => remove(lua)?,
@@ -27,6 +28,13 @@ pub fn compose(lua: &Lua) -> mlua::Result<Table> {
2728
Ok(fs)
2829
}
2930

31+
fn cwd(lua: &Lua) -> mlua::Result<Function> {
32+
lua.create_function(|lua, ()| match std::env::current_dir() {
33+
Ok(p) => (Url::cast(lua, p)?, Value::Nil).into_lua_multi(lua),
34+
Err(e) => (Value::Nil, Error::Io(e)).into_lua_multi(lua),
35+
})
36+
}
37+
3038
fn cha(lua: &Lua) -> mlua::Result<Function> {
3139
lua.create_async_function(|lua, (url, follow): (UrlRef, Option<bool>)| async move {
3240
let meta = if follow.unwrap_or(false) {

yazi-plugin/src/lua.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ fn stage_1(lua: &'static Lua) -> Result<()> {
2424
let globals = lua.globals();
2525
globals.raw_set("ui", crate::elements::compose(lua)?)?;
2626
globals.raw_set("ya", crate::utils::compose(lua, false)?)?;
27+
globals.raw_set("fs", crate::fs::compose(lua)?)?;
2728
globals.raw_set("ps", crate::pubsub::compose(lua)?)?;
2829

2930
crate::Error::install(lua)?;

0 commit comments

Comments
 (0)