-
-
Notifications
You must be signed in to change notification settings - Fork 805
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Path and MetaData objects + wezterm.<functions>
#4493
base: main
Are you sure you want to change the base?
Conversation
(I'm holding off looking at this in earnest until the table PR is merged, because this one is layered on top of that and I prefer not to have to mentally filter it out here) |
That's fine. I plan to do another cleanup of this too taking care of some similar problems as in the other PR. |
This pull request is a combination of #4330 and #4343, but I have now added the Path and MetaData objects discussed in the matrix chat.
This ended up being a quite large pull request, and I have a few different things of note to discuss before this is ready to be merged.
wezterm.home_path
. I haven't made any otherwezterm.<name>_dir
commands, but I do think it makes sense to do forwezterm.home_dir
. (The current PR includeswezterm.home_path
.)wezterm.read_dir
? The current code allows you to sort the directories multiple times since I thought that might be useful for sorting stuff with a lot of overlaps in one of your sorting criteria. I.e., if you source by the length of the names of files, and you have a lot of files with names of 4 or 5 characters, then you can additionally sort by some other criteria like time since you last accessed the file first. I haven't found much use for this though, and one sort only could simplify the code.wezterm.read_dir
return strings instead ofPath
objects? It used to return strings, but for now I have changed it to returnPath
objects. Because of a workaround mentioned in the notes at the end, I don't think this should cause any problems.try_exists
? The other functions of this type usesmol::fs
to make it async, butsmol::fs
doesn't seem to have atry_exists
.__concat
meta method for thePath
object treats the paths as strings and does string concatenation (since I think that is more intuitive). Would it be better to do a Rustjoin
of the paths instead?Path
objects include non-async (or async viametadata
/symlink_metadata
) versions ofis_dir
,is_file
andis_symlink
? For now I didn't include these, since I think that it is fine to get these throughpath:metadata():is_<dir or file>
orpath:symlink_metadata():is_<symlink>()
.file_prefix
when it is stable in Rust.mlua::MultiValue
s in thePath
versions of thestring
functions, since I think it gives nicer errors, because you get the errors ofstring.<func_name>
that you expect. Is it better to add more details in the Rust code? (Then we could write more descriptive errors, but I think it complicates the code and I don't like these errors more anyways.)wezterm.<func_name>
functions I have included in this PR make sense? Should I include something else? Or leave something out?Notes:
Path
objects as strings, I have implemented all the string functions where the first argument is a string (not formatting string or other type), since these are the ones people expect to be able to use as methods. So ifpath
is aPath
object, you can do something likepath:gsub(...)
. The way I implement these is by converting thePath
object to a string and then calling the string method with the given arguments. I don't try to change it back to aPath
object at the end, since if you use thestring
method, you presumably want a string.e2e::sftp
test errors look like they might be related to this pull request since they also work with filesystem stuff, they don't have anything to do with this pull request. Those tests also fail on the current main branch.Please let me know if you have any comments or questions in general about this pull request.