Plugin Types
Yazi exposes Rust-native types as Lua objects with field access and method calls.
Url
Represents a URL which can be a local file path or a remote resource.
| Field/Method | Signature | Description |
|---|---|---|
from_str | Url.from_str(s: string) -> Url | Create a URL from a string |
is_local | url:is_local() -> bool | Whether the URL points to a local file |
is_regular | url:is_regular() -> bool | Whether the URL has a regular scheme (file://) |
fragments | url:fragments() -> [string] | Return URL path fragments/components |
local u = Url.from_str("/home/user/doc.txt")
ya.err(u:is_local()) -- true
ya.err(u:fragments()) -- { "", "home", "user", "doc.txt" }
Path
A filesystem path derived from a Url.
| Field/Method | Signature | Description |
|---|---|---|
parent | path:parent() -> Path | Parent directory path |
filename | path:filename() -> string | File name with extension |
stem | path:stem() -> string | File name without extension |
extension | path:extension() -> string | File extension (without dot) |
is_absolute | path:is_absolute() -> bool | Whether path is absolute |
is_relative | path:is_relative() -> bool | Whether path is relative |
exists | path:exists() -> bool | Whether the path exists on disk |
join | path:join(other: Path) -> Path | Join two path segments |
File
A file entry combining its URL and metadata.
| Field | Type | Description |
|---|---|---|
url | Url | The file's URL |
cha | Cha | File metadata (see below) |
name | string | File name |
is_hidden | bool | Whether the file is hidden |
is_link | bool | Whether the file is a symlink |
local file = cx.active.current.hovered
if file then
ya.err(file.name) -- "document.pdf"
ya.err(file.cha.len) -- 102400
end
Cha
File metadata (equivalent to stat on Unix).
| Field | Type | Description |
|---|---|---|
is_dir | bool | Is a directory |
is_file | bool | Is a regular file |
is_symlink | bool | Is a symbolic link |
len | integer | File size in bytes |
permissions | string | Permission string (e.g., rwxr-xr-x) |
uid | integer | Owner user ID |
gid | integer | Owner group ID |
mtime | integer | Last modification time (Unix timestamp) |
accessed | integer | Last access time |
created | integer | Creation time (platform-dependent) |
-- Check if a file is executable
local function is_executable(file)
return file.cha.permissions:match("x")
end
Mimetype
Detected MIME type for a file.
| Method | Signature | Description |
|---|---|---|
from_file | Mimetype.from_file(url: Url) -> string | Detect MIME type from a file on disk |
from_str | Mimetype.from_str(s: string) -> string | Detect MIME type from a byte string |
local mime = Mimetype.from_file(file.url)
ya.err(mime) -- "application/pdf"
tip
Use Mimetype.from_file in async contexts (it performs I/O). In sync contexts, prefer reading the mime field from the file system if available.