From b4b8bfb0059da1945f78c2fff8d9f62a923ddaac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Fri, 27 Sep 2024 13:49:34 -0600 Subject: [PATCH 1/2] Implement tab completion for ~/ Fixes #87. --- crates/shell/src/completion.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crates/shell/src/completion.rs b/crates/shell/src/completion.rs index fec1dae..7ae620c 100644 --- a/crates/shell/src/completion.rs +++ b/crates/shell/src/completion.rs @@ -62,6 +62,9 @@ fn complete_filenames(_is_start: bool, word: &str, matches: &mut Vec) { // Determine the full directory path to search let search_dir = if dir_path.starts_with('/') { dir_path.to_string() + } else if dir_path.starts_with('~') { + let home_dir = dirs::home_dir().unwrap(); + format!("{}{}", home_dir.display(), &dir_path[1..]) } else { format!("./{}", dir_path) }; From e7de678d8ab1e3aca44228b632873b18e9d2e266 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Fri, 27 Sep 2024 13:56:03 -0600 Subject: [PATCH 2/2] Fix clippy --- crates/shell/src/completion.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/shell/src/completion.rs b/crates/shell/src/completion.rs index 7ae620c..5410797 100644 --- a/crates/shell/src/completion.rs +++ b/crates/shell/src/completion.rs @@ -62,9 +62,9 @@ fn complete_filenames(_is_start: bool, word: &str, matches: &mut Vec) { // Determine the full directory path to search let search_dir = if dir_path.starts_with('/') { dir_path.to_string() - } else if dir_path.starts_with('~') { + } else if let Some(stripped) = dir_path.strip_prefix('~') { let home_dir = dirs::home_dir().unwrap(); - format!("{}{}", home_dir.display(), &dir_path[1..]) + format!("{}{}", home_dir.display(), stripped) } else { format!("./{}", dir_path) };