-
-
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 expansion of ~
#284
Fix expansion of ~
#284
Conversation
// This function is used instead of `std::fs::canonicalize` because we don't want to verify | ||
// here if the path exists, just normalize it's components. | ||
pub fn canonicalize_path(path: &Path) -> std::io::Result<PathBuf> { | ||
std::env::current_dir().map(|current_dir| normalize_path(¤t_dir.join(path))) |
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.
You still want this because paths need to be converted to absolute. Not taking current_dir()
into account will consider myfile.c
and /full/path/to/myfile.c
as two separate files.
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.
Tilde expansion should be a step before normalization: https://github.com/netvl/shellexpand/blob/e707d07a0a2638df7ab26b152f814e80ce3b3992/src/lib.rs#L665-L690
Autocompletion for |
The display part should be fixed by modifying this: helix/helix-view/src/document.rs Lines 687 to 693 in a364d6c
|
~
, dont use directory relative to cwd.~
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.
Tested and works good, let's change doc.relative_path
to replace the home path with ~
as well
@@ -1070,8 +1070,8 @@ mod cmd { | |||
.filter(|doc| doc.is_modified()) | |||
.map(|doc| { | |||
doc.relative_path() | |||
.and_then(|path| path.to_str()) | |||
.unwrap_or("[scratch]") | |||
.map(|path| path.to_string_lossy().to_string()) |
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.
No need for to_string()
here, it's already a Cow
I think.
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.
Unfortunatelly:
error[E0515]: cannot return value referencing function parameter `path`
--> helix-term/src/commands.rs:1073:33
|
1073 | .map(|path| path.to_string_lossy())
| ----^^^^^^^^^^^^^^^^^^
| |
| returns a value referencing data owned by the current function
| `path` is borrowed here
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.
It is a consequence of changing the return type of relative_path
to be owned PathBuf
not &Path
but I'm not sure I can return a &Path
while still folding home directory into tilde.
Closes: #280