mirror of
https://github.com/sxyazi/yazi.git
synced 2024-12-18 14:21:32 +03:00
feat: add is_exec
and is_sticky
to Cha
bindings (#875)
This commit is contained in:
parent
d04b549f4e
commit
4755654224
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -3071,6 +3071,7 @@ dependencies = [
|
||||
"clap_complete_fig",
|
||||
"clap_complete_nushell",
|
||||
"serde",
|
||||
"uzers",
|
||||
"vergen",
|
||||
"yazi-adaptor",
|
||||
"yazi-config",
|
||||
@ -3139,6 +3140,7 @@ dependencies = [
|
||||
"serde_json",
|
||||
"tokio",
|
||||
"tracing",
|
||||
"uzers",
|
||||
"yazi-boot",
|
||||
"yazi-shared",
|
||||
]
|
||||
|
@ -23,3 +23,6 @@ clap_complete = "4.5.1"
|
||||
clap_complete_nushell = "4.5.1"
|
||||
clap_complete_fig = "4.5.0"
|
||||
vergen = { version = "8.3.1", features = [ "build", "git", "gitcl" ] }
|
||||
|
||||
[target."cfg(unix)".dependencies]
|
||||
uzers = "0.11.3"
|
||||
|
@ -9,7 +9,13 @@ pub use boot::*;
|
||||
pub static ARGS: RoCell<Args> = RoCell::new();
|
||||
pub static BOOT: RoCell<Boot> = RoCell::new();
|
||||
|
||||
#[cfg(unix)]
|
||||
pub static USERS_CACHE: yazi_shared::RoCell<uzers::UsersCache> = yazi_shared::RoCell::new();
|
||||
|
||||
pub fn init() {
|
||||
ARGS.with(Default::default);
|
||||
BOOT.with(Default::default);
|
||||
|
||||
#[cfg(unix)]
|
||||
USERS_CACHE.with(Default::default);
|
||||
}
|
||||
|
@ -22,3 +22,6 @@ tokio = { version = "1.37.0", features = [ "full" ] }
|
||||
|
||||
# Logging
|
||||
tracing = { version = "0.1.40", features = [ "max_level_debug", "release_max_level_warn" ] }
|
||||
|
||||
[target."cfg(unix)".dependencies]
|
||||
uzers = "0.11.3"
|
||||
|
@ -37,6 +37,9 @@ impl<'a> Body<'a> {
|
||||
"hi" | "hey" | "cd" | "hover" | "rename" | "bulk" | "yank" => {
|
||||
Err("Cannot construct system event from Lua").into_lua_err()?
|
||||
}
|
||||
_ if !kind.bytes().all(|b| b.is_ascii_alphanumeric() || b == b'-') => {
|
||||
Err("Kind must be alphanumeric with dashes").into_lua_err()?
|
||||
}
|
||||
_ => BodyCustom::from_lua(kind, value)?,
|
||||
})
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ impl Client {
|
||||
) -> (Lines<BufReader<ReadHalf<UnixStream>>>, WriteHalf<UnixStream>) {
|
||||
let mut first = true;
|
||||
loop {
|
||||
if let Ok(stream) = UnixStream::connect("/tmp/yazi.sock").await {
|
||||
if let Ok(stream) = UnixStream::connect(Server::socket_file()).await {
|
||||
Pubsub::pub_from_hi();
|
||||
let (reader, writer) = tokio::io::split(stream);
|
||||
return (BufReader::new(reader).lines(), writer);
|
||||
|
@ -61,7 +61,7 @@ impl Server {
|
||||
continue;
|
||||
}
|
||||
|
||||
if receiver == 0 && sender > 0 && sender <= u16::MAX as u64 {
|
||||
if receiver == 0 && sender <= u16::MAX as u64 {
|
||||
let Some(body) = parts.next() else { continue };
|
||||
if !STATE.set(kind, sender as u16, body) { continue }
|
||||
}
|
||||
@ -78,11 +78,23 @@ impl Server {
|
||||
}))
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[inline]
|
||||
pub(super) fn socket_file() -> std::path::PathBuf {
|
||||
use uzers::Users;
|
||||
use yazi_boot::USERS_CACHE;
|
||||
use yazi_shared::Xdg;
|
||||
|
||||
Xdg::cache_dir().join(format!(".dds-{}.sock", USERS_CACHE.get_current_uid()))
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[inline]
|
||||
async fn bind() -> Result<tokio::net::UnixListener> {
|
||||
tokio::fs::remove_file("/tmp/yazi.sock").await.ok();
|
||||
Ok(tokio::net::UnixListener::bind("/tmp/yazi.sock")?)
|
||||
let p = Self::socket_file();
|
||||
|
||||
tokio::fs::remove_file(&p).await.ok();
|
||||
Ok(tokio::net::UnixListener::bind(p)?)
|
||||
}
|
||||
|
||||
#[cfg(not(unix))]
|
||||
|
@ -17,6 +17,8 @@ impl Cha {
|
||||
reg.add_field_method_get("is_char_device", |_, me| Ok(me.is_char_device()));
|
||||
reg.add_field_method_get("is_fifo", |_, me| Ok(me.is_fifo()));
|
||||
reg.add_field_method_get("is_socket", |_, me| Ok(me.is_socket()));
|
||||
reg.add_field_method_get("is_exec", |_, me| Ok(me.is_exec()));
|
||||
reg.add_field_method_get("is_sticky", |_, me| Ok(me.is_sticky()));
|
||||
|
||||
#[cfg(unix)]
|
||||
{
|
||||
|
@ -16,7 +16,6 @@ pub(super) fn init_lua() {
|
||||
|
||||
fn stage_1(lua: &'static Lua) -> Result<()> {
|
||||
crate::Config::new(lua).install_boot()?.install_manager()?.install_theme()?;
|
||||
crate::utils::init();
|
||||
crate::utils::install(lua)?;
|
||||
|
||||
// Base
|
||||
|
@ -28,10 +28,6 @@ impl Pubsub {
|
||||
ps.raw_set(
|
||||
"pub_static",
|
||||
lua.create_function(|_, (severity, kind, value): (u16, mlua::String, Value)| {
|
||||
if severity < 1 {
|
||||
return Err("Severity must be at least 1").into_lua_err();
|
||||
}
|
||||
|
||||
yazi_dds::Pubsub::pub_static(
|
||||
severity,
|
||||
Body::from_lua(kind.to_str()?, value).into_lua_err()?,
|
||||
|
@ -6,9 +6,10 @@ impl Utils {
|
||||
#[cfg(unix)]
|
||||
pub(super) fn user(lua: &Lua, ya: &Table) -> mlua::Result<()> {
|
||||
use uzers::{Groups, Users};
|
||||
use yazi_boot::USERS_CACHE;
|
||||
use yazi_shared::hostname;
|
||||
|
||||
use crate::utils::{HOSTNAME_CACHE, USERS_CACHE};
|
||||
use crate::utils::HOSTNAME_CACHE;
|
||||
|
||||
ya.raw_set("uid", lua.create_function(|_, ()| Ok(USERS_CACHE.get_current_uid()))?)?;
|
||||
|
||||
|
@ -1,6 +1,3 @@
|
||||
#[cfg(unix)]
|
||||
pub(super) static USERS_CACHE: yazi_shared::RoCell<uzers::UsersCache> = yazi_shared::RoCell::new();
|
||||
|
||||
#[cfg(unix)]
|
||||
pub(super) static HOSTNAME_CACHE: std::sync::OnceLock<Option<String>> = std::sync::OnceLock::new();
|
||||
|
||||
@ -43,8 +40,3 @@ pub fn install_isolate(lua: &mlua::Lua) -> mlua::Result<()> {
|
||||
|
||||
lua.globals().raw_set("ya", ya)
|
||||
}
|
||||
|
||||
pub fn init() {
|
||||
#[cfg(unix)]
|
||||
USERS_CACHE.with(Default::default);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user