-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Fix issue with opening a relative directory with hx <dir>
introduced in #8498
#8520
Conversation
Does this fix #8515? |
Yes, it should |
4669f57
to
2cfcce9
Compare
The new solution should work well together with working_directory. I have also rebased against master. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to avoid passing around a flag like this, it seems leaky / ad-hoc to me. I think it should work to turn all relative paths we get in the args to absolute, relative to the current working directory at start-up time (before we switch the working directory to the one specified with -w
). That should also have less confusing behavior when using the -w
flag: hx -w path/to/helix Cargo.toml
should open the Cargo.toml
in the current directory rather than Helix's Cargo.toml
IMO
I also didn't like that flag, but it was the cleanest I could come up with while keeping the original behaviour. Since that was to be relative from This is also how all other tools I know work. If you run I also thought about joining |
Another issue with your suggestion is non existing paths. As canonicalize needs the path to exist. |
Hmm yeah, let's follow other tools then and keep those files relative to the working path rather than cwd at invocation. The behavior here seems ok then but I'd still like to clean up that rogue flag - it seems like that's leaking out of |
The reason I didn't do this is that I wanted to leave the args parsing without side-effects. And since I depend on setting the working directory before I check if it is a directory, that wouldn't work. I could make it mutable in |
Yeah that's what I had in mind - making it |
2cfcce9
to
68f806f
Compare
I may have unintentionally lied about other tools. At least for tar, it will open the file from -f from the current directory, then change, and create all files in the new location. So it might actually make sense to iterate trough all files in main() and resolve to full path before altering the directory. Should I look into this, or just leave it as it is now? |
Hmm yeah, let's resolve the paths before altering the directory. IMO that behavior is more intuitive and I believe shell completion should help with that approach (it should assume files are relative to the shell's cwd) |
When opening the editor using
hx <dir>
where<dir>
is relative it would either open the wrong directory in the picker, or a new file.This was introduced by #8498
My solution is to replace the first argument by "." when it is a directory and override
args.working_directory
. This should effectively leave the original logic in place while still solve the config issue.