Add support for '~' as a shortcut for home directory (#149)#156
Closed
BiswajitThakur wants to merge 4 commits intorust-lang:masterfrom
BiswajitThakur:feature/support-tilde-home-dir
Closed
Add support for '~' as a shortcut for home directory (#149)#156BiswajitThakur wants to merge 4 commits intorust-lang:masterfrom BiswajitThakur:feature/support-tilde-home-dir
BiswajitThakur wants to merge 4 commits intorust-lang:masterfrom
BiswajitThakur:feature/support-tilde-home-dir
Conversation
tgross35
requested changes
Aug 11, 2025
Contributor
There was a problem hiding this comment.
We should follow https://man7.org/linux/man-pages/man3/glob.3.html's GLOB_TILDE here and make this an off-by-default setting on MatchOptions. This is a breaking change but we want to make it #[non_exhaustive] anyway.
Comment on lines
+609
to
+634
| if let (Some(first_char), second_char) = (chars.first(), chars.get(1)) { | ||
| #[cfg(not(windows))] | ||
| match (*first_char, second_char) { | ||
| ('~', None) | ('~', Some(&'/')) => { | ||
| if let Ok(home_dir) = std::env::var("HOME") { | ||
| for ch in home_dir.chars() { | ||
| tokens.push(PatternToken::Char(ch)); | ||
| } | ||
| i += 1; | ||
| } | ||
| } | ||
| _ => {} | ||
| } | ||
| #[cfg(windows)] | ||
| match (*first_char, second_char) { | ||
| ('~', None) | ('~', Some(&'/')) | ('~', Some(&'\\')) => { | ||
| if let Ok(home_dir) = std::env::var("USERPROFILE") { | ||
| for ch in home_dir.chars() { | ||
| tokens.push(PatternToken::Char(ch)); | ||
| } | ||
| i += 1; | ||
| } | ||
| } | ||
| _ => {} | ||
| } | ||
| } |
Contributor
There was a problem hiding this comment.
Few simplifications:
- This can use
pattern.starts_with("~/")rather than matching on chars - Use https://doc.rust-lang.org/std/env/fn.home_dir.html to get the home directory. Has a niche case of not working well on pre-1.85 rust, but we can tolerate that.
|
Why has this been closed? The review sounded like it would be nearly ready for merging. |
Author
|
sorry for closing. i got error when i send pull request thats why i closed it and i resend a pull request again.
|
|
Thank you for your work! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.