Skip to content

Commit c7848ff

Browse files
authored
Merge pull request #6094 from epage/home
feat(complete): Expand ~ in native completions
2 parents 09969d3 + 60184fb commit c7848ff

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

clap_complete/src/engine/custom.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,16 @@ pub(crate) fn complete_path(
295295
let current = current.to_string_lossy();
296296
let search_root = if prefix.is_absolute() {
297297
prefix.to_owned()
298+
} else if prefix.iter().next() == Some(OsStr::new("~")) {
299+
let prefix = prefix.strip_prefix("~").unwrap_or(prefix);
300+
let home_dir = match std::env::home_dir() {
301+
Some(home_dir) => home_dir,
302+
None => {
303+
// Can't complete without a `home_dir`
304+
return completions;
305+
}
306+
};
307+
home_dir.join(prefix)
298308
} else {
299309
let current_dir = match current_dir {
300310
Some(current_dir) => current_dir,

0 commit comments

Comments
 (0)