diff --git a/yazi-plugin/preset/plugins/archive.lua b/yazi-plugin/preset/plugins/archive.lua index b39ca58d..c1c99a29 100644 --- a/yazi-plugin/preset/plugins/archive.lua +++ b/yazi-plugin/preset/plugins/archive.lua @@ -54,10 +54,8 @@ function M:seek(units) end function M:spawn_tar(args) - local command = "tar" - local stdout = args[1] == "l" and Command.PIPED or Command.NULL - local child, code = Command(command):args(args):stdout(stdout):stderr(Command.PIPED):spawn() + local child, code = Command("tar"):args(args):stdout(stdout):stderr(Command.PIPED):spawn() if not child then return nil, "Failed to spawn, error code: " .. tostring(code) end diff --git a/yazi-plugin/src/fs/fs.rs b/yazi-plugin/src/fs/fs.rs index 13e5fb3d..474aea51 100644 --- a/yazi-plugin/src/fs/fs.rs +++ b/yazi-plugin/src/fs/fs.rs @@ -3,7 +3,12 @@ use mlua::{ExternalError, ExternalResult, IntoLuaMulti, Lua, Table, Value}; use tokio::fs; use yazi_shared::fs::remove_dir_clean; -use crate::{bindings::Cast, cha::Cha, file::File, url::{Url, UrlRef}}; +use crate::{ + bindings::Cast, + cha::Cha, + file::File, + url::{Url, UrlRef}, +}; pub fn install(lua: &Lua) -> mlua::Result<()> { lua.globals().raw_set( @@ -52,6 +57,21 @@ pub fn install(lua: &Lua) -> mlua::Result<()> { } })?, ), + ( + "create", + lua.create_async_function(|lua, (type_, url): (mlua::String, UrlRef)| async move { + let result = match type_.to_str()? { + "file" => fs::File::create(&*url).await.map(|_| ()), + "dir" => fs::create_dir(&*url).await, + _ => Err("Creation type must be 'file', 'dir'".into_lua_err())?, + }; + + match result { + Ok(_) => (true, Value::Nil).into_lua_multi(lua), + Err(e) => (false, e.raw_os_error()).into_lua_multi(lua), + } + })?, + ), ( "read_dir", lua.create_async_function(|lua, (dir, options): (UrlRef, Table)| async move {