From 4192e77ac38140f9ad6c2e2e275dbeedc37357b4 Mon Sep 17 00:00:00 2001 From: sehnryr Date: Fri, 24 Mar 2023 17:19:04 +0100 Subject: [PATCH] fix: better listing and completion --- src/shell/helper.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/shell/helper.rs b/src/shell/helper.rs index c233675..7e1fed6 100644 --- a/src/shell/helper.rs +++ b/src/shell/helper.rs @@ -79,7 +79,8 @@ impl Completer for Helper<'_> { if child_directory.borrow().name().starts_with(uncompleted) { candidates.push(format!( "{}/", - child_directory.borrow().path().display().to_string() + &child_directory.borrow().path().display().to_string() + [current_dir.display().to_string().len()..] )); } } @@ -87,11 +88,17 @@ impl Completer for Helper<'_> { // Get matching files for child_file in current_dir_node.borrow().children_files() { if child_file.borrow().name().starts_with(uncompleted) { - candidates.push(child_file.borrow().path().display().to_string()); + candidates.push( + child_file.borrow().path().display().to_string() + [current_dir.display().to_string().len()..].to_string(), + ); } } - Ok((last_arg_pos, candidates)) + // Sort the candidates + candidates.sort(); + + Ok((last_arg_pos + arg_path.len(), candidates)) } fn update(&self, line: &mut LineBuffer, start: usize, elected: &str) {