Closed sohanemon closed 1 month ago
It would be helpful if there were a built-in function to do this
There is fs.cha()
function you can use to check if the file exists, see https://yazi-rs.github.io/docs/plugins/utils#fs.cha
Closing as already exists
Could you please help me identify why this code is not working? I would like to know if there are any syntax errors present.
return {
entry = function(self, args)
for _, path in ipairs(args) do
local cha, err = fs.cha(path, true)
if cha ~= nil then
ya.manager_emit("cd", { path })
return
end
end
end,
}
And the corresponding keymap configuration:
{ on = [
"g",
"u",
], run = "plugin cdx --args='$CWD/components/ui $CWD/components'", desc = "Go UI Components" },
Objective: I am attempting to use a plugin to provide a list of path names. If a path exists, the program should cd
into that path and then exit the loop. If the path does not exist, it should continue to the next path in the list.
Could you please review this and suggest any corrections? Thank you.
fs.cha()
needs a Url, not a string path, https://yazi-rs.github.io/docs/plugins/types#shared.url.
Also make sure you have a directory with the name $CWD
, otherwise you may need to replace it to a actual name
I'm going to lock this issue because it has been closed for 30 days. ⏳ This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please file a new issue and complete the issue template so we can capture all the details necessary to investigate further.
yazi --debug
outputPlease describe the problem you're trying to solve
I want to check if a directory is available or not using its pathname before I cd into it.
Would you be willing to contribute this feature?
Describe the solution you'd like
It would be helpful if there were a built-in function to do this. Or a code snippets.
Additional context
No response
Validations