-
Notifications
You must be signed in to change notification settings - Fork 84
Add support for '~' as a shortcut for home directory (#149) #156
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
Add support for '~' as a shortcut for home directory (#149) #156
Conversation
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.
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.
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; | ||
} | ||
} | ||
_ => {} | ||
} | ||
} |
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.
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. |
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! |
No description provided.