aboutsummaryrefslogtreecommitdiffstats
path: root/src/completion.rs
diff options
context:
space:
mode:
authorJonas Maier <jonas@x77.dev>2026-03-05 23:54:56 +0100
committerJonas Maier <jonas@x77.dev>2026-03-05 23:54:56 +0100
commitfb80e9c1cd4c2dcbb2d2ba1e2be8c7e19b9f0ce1 (patch)
treee6980a3ae362de33f1521c647e18dad16b02363e /src/completion.rs
parentf03a0863ba3da7cf34e938a7de1cf92675b09c41 (diff)
downloadpish-fb80e9c1cd4c2dcbb2d2ba1e2be8c7e19b9f0ce1.tar.gz
very buggy beginning of tab completion
Diffstat (limited to 'src/completion.rs')
-rw-r--r--src/completion.rs16
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()
+ }
+ }
+}