diff --git a/yazi-core/src/mgr/commands/update_mimes.rs b/yazi-core/src/mgr/commands/update_mimes.rs index 638aacac..05f4e570 100644 --- a/yazi-core/src/mgr/commands/update_mimes.rs +++ b/yazi-core/src/mgr/commands/update_mimes.rs @@ -7,14 +7,14 @@ use yazi_shared::{event::CmdCow, url::Url}; use crate::{mgr::{LINKED, Mgr}, tasks::Tasks}; pub struct Opt { - updates: HashMap, Cow<'static, str>>, + updates: HashMap>, } impl TryFrom for Opt { type Error = (); fn try_from(mut c: CmdCow) -> Result { - Ok(Self { updates: c.try_take("updates").ok_or(())?.into_dict_string() }) + Ok(Self { updates: c.try_take("updates").ok_or(())?.into_dict() }) } } @@ -28,7 +28,6 @@ impl Mgr { let updates = opt .updates .into_iter() - .flat_map(|(url, mime)| Url::try_from(url.as_ref()).map(|u| (u, mime))) .filter(|(url, mime)| self.mimetype.by_url(url) != Some(mime)) .fold(HashMap::new(), |mut map, (u, m)| { for u in linked.from_file(&u) { diff --git a/yazi-plugin/preset/plugins/mime.lua b/yazi-plugin/preset/plugins/mime.lua index 1ba263a9..a7f91d78 100644 --- a/yazi-plugin/preset/plugins/mime.lua +++ b/yazi-plugin/preset/plugins/mime.lua @@ -12,7 +12,7 @@ end function M:fetch(job) local urls = {} for _, file in ipairs(job.files) do - urls[#urls + 1] = tostring(file.url) + urls[#urls + 1] = file.url end local cmd = os.getenv("YAZI_FILE_ONE") or "file" diff --git a/yazi-plugin/src/process/command.rs b/yazi-plugin/src/process/command.rs index 8a224dba..31f8ac6a 100644 --- a/yazi-plugin/src/process/command.rs +++ b/yazi-plugin/src/process/command.rs @@ -146,8 +146,33 @@ impl UserData for Command { me.inner.arg(String::from_utf8_lossy(&s.as_bytes()).as_ref()); } Value::Table(t) => { - for s in t.sequence_values::() { - me.inner.arg(String::from_utf8_lossy(&s?.as_bytes()).as_ref()); + for v in t.sequence_values::() { + match &v? { + Value::String(s) => { + me.inner.arg(String::from_utf8_lossy(&s.as_bytes()).as_ref()); + } + Value::UserData(ud) => { + if let Some(t) = ud.type_id() { + if t == TypeId::of::() { + let url = ud.borrow::()?; + me.inner.arg(url.as_os_str()); + } else { + return Err( + "arg must be a string or Url, or table of strings or Urls.".into_lua_err(), + ); + } + } else { + return Err( + "arg must be a string or Url, or table of strings or Urls.".into_lua_err(), + ); + } + } + _ => { + return Err( + "arg must be a string or Url, or table of strings or Urls.".into_lua_err(), + ); + } + } } } _ => return Err("arg must be a string or table of strings".into_lua_err()), diff --git a/yazi-shared/src/event/data.rs b/yazi-shared/src/event/data.rs index 3b7a8109..dc09c339 100644 --- a/yazi-shared/src/event/data.rs +++ b/yazi-shared/src/event/data.rs @@ -63,14 +63,14 @@ impl Data { } } - pub fn into_dict_string(self) -> HashMap, Cow<'static, str>> { + pub fn into_dict(self) -> HashMap> { let Self::Dict(dict) = self else { return Default::default(); }; let mut map = HashMap::with_capacity(dict.len()); for pair in dict { - if let (DataKey::String(k), Self::String(v)) = pair { + if let (DataKey::Url(k), Self::String(v)) = pair { map.insert(k, v); } }