diff options
Diffstat (limited to 'src/completion.rs')
| -rw-r--r-- | src/completion.rs | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/completion.rs b/src/completion.rs index 63ac866..cb030a1 100644 --- a/src/completion.rs +++ b/src/completion.rs @@ -6,7 +6,7 @@ pub struct Suggestion { full: BString, } -pub fn _path_completion(mut prefix: BString) -> io::Result<Vec<Suggestion>> { +fn _path_completion(mut prefix: BString) -> io::Result<Vec<Suggestion>> { let mut partial_entry = BString::new(); while let Some(c) = prefix.last().cloned() { if c == b'/' { @@ -19,6 +19,10 @@ pub fn _path_completion(mut prefix: BString) -> io::Result<Vec<Suggestion>> { let mut sugs = Vec::new(); + if prefix.is_empty() { + prefix.push(b'.'); + } + for entry in fs::read_dir(OsStr::from_bytes(&prefix))? { let entry = entry?; let name = entry.file_name().as_bytes().to_vec(); @@ -32,3 +36,13 @@ pub fn _path_completion(mut prefix: BString) -> io::Result<Vec<Suggestion>> { Ok(sugs) } + +pub fn path_completion(prefix: BString) -> Vec<Suggestion> { + match _path_completion(prefix) { + Ok(suggestions) => suggestions, + Err(err) => { + println!("path completion failed: {err:?}\r"); + Vec::new() + } + } +} |
