Skip to main content

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/MethodSignatureDescription
from_strUrl.from_str(s: string) -> UrlCreate a URL from a string
is_localurl:is_local() -> boolWhether the URL points to a local file
is_regularurl:is_regular() -> boolWhether the URL has a regular scheme (file://)
fragmentsurl: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/MethodSignatureDescription
parentpath:parent() -> PathParent directory path
filenamepath:filename() -> stringFile name with extension
stempath:stem() -> stringFile name without extension
extensionpath:extension() -> stringFile extension (without dot)
is_absolutepath:is_absolute() -> boolWhether path is absolute
is_relativepath:is_relative() -> boolWhether path is relative
existspath:exists() -> boolWhether the path exists on disk
joinpath:join(other: Path) -> PathJoin two path segments

File

A file entry combining its URL and metadata.

FieldTypeDescription
urlUrlThe file's URL
chaChaFile metadata (see below)
namestringFile name
is_hiddenboolWhether the file is hidden
is_linkboolWhether 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).

FieldTypeDescription
is_dirboolIs a directory
is_fileboolIs a regular file
is_symlinkboolIs a symbolic link
lenintegerFile size in bytes
permissionsstringPermission string (e.g., rwxr-xr-x)
uidintegerOwner user ID
gidintegerOwner group ID
mtimeintegerLast modification time (Unix timestamp)
accessedintegerLast access time
createdintegerCreation 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.

MethodSignatureDescription
from_fileMimetype.from_file(url: Url) -> stringDetect MIME type from a file on disk
from_strMimetype.from_str(s: string) -> stringDetect 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.