Skip to content

Commit bb581bf

Browse files
Add support for '~' as a shortcut for home directory (#149)
1 parent 7a17f11 commit bb581bf

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,20 @@ impl Pattern {
606606
let mut is_recursive = false;
607607
let mut i = 0;
608608

609+
#[cfg(not(windows))]
610+
if let (Some(first_char), second_char) = (chars.first(), chars.get(1)) {
611+
match (*first_char, second_char) {
612+
('~', None) | ('~', Some('/')) => {
613+
if let Ok(home_dir) = std::env::var("HOME") {
614+
for ch in home_dir.chars() {
615+
tokens.push(PatternToken::Char(ch));
616+
}
617+
i += 1;
618+
}
619+
}
620+
_ => {}
621+
}
622+
}
609623
while i < chars.len() {
610624
match chars[i] {
611625
'?' => {

0 commit comments

Comments
 (0)