From d6c4841dbebbeadfd8dc182311bf23dacfcf51b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Fri, 27 Sep 2024 14:16:45 -0600 Subject: [PATCH 1/3] Use CompletionType::List (#163) This is how Bash behaves, it is a lot more natural. --- crates/shell/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/shell/src/main.rs b/crates/shell/src/main.rs index b6c3be3..9b72392 100644 --- a/crates/shell/src/main.rs +++ b/crates/shell/src/main.rs @@ -32,7 +32,7 @@ fn init_state() -> ShellState { async fn interactive() -> anyhow::Result<()> { let config = Config::builder() .history_ignore_space(true) - .completion_type(CompletionType::Circular) + .completion_type(CompletionType::List) .build(); let mut rl = Editor::with_config(config)?; From 2283331a561ba16e16b47227081d239141010123 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Fri, 27 Sep 2024 14:17:44 -0600 Subject: [PATCH 2/3] Implement tab completion for ~/ (#164) * Implement tab completion for ~/ Fixes #87. * Fix clippy --- 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..5410797 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 let Some(stripped) = dir_path.strip_prefix('~') { + let home_dir = dirs::home_dir().unwrap(); + format!("{}{}", home_dir.display(), stripped) } else { format!("./{}", dir_path) }; From 1113c78aa3610e9afbefb954b46cf507e56f7c7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Fri, 27 Sep 2024 14:18:06 -0600 Subject: [PATCH 3/3] Set Ctrl-C signal handler (#123) --- Cargo.lock | 35 ++++++++++++++++++++++++++++++++--- crates/shell/Cargo.toml | 1 + crates/shell/src/main.rs | 5 +++++ 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1ee73ef..8bece03 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -189,6 +189,12 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" +[[package]] +name = "cfg_aliases" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" + [[package]] name = "chrono" version = "0.4.38" @@ -282,6 +288,16 @@ dependencies = [ "typenum", ] +[[package]] +name = "ctrlc" +version = "3.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90eeab0aa92f3f9b4e87f258c72b139c207d251f9cbc1080a0086b86a8870dd3" +dependencies = [ + "nix 0.29.0", + "windows-sys 0.59.0", +] + [[package]] name = "deno_task_shell" version = "0.17.0" @@ -748,7 +764,19 @@ checksum = "ab2156c4fce2f8df6c499cc1c763e4394b7482525bf2a9701c9d79d215f519e4" dependencies = [ "bitflags", "cfg-if", - "cfg_aliases", + "cfg_aliases 0.1.1", + "libc", +] + +[[package]] +name = "nix" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71e2746dc3a24dd78b3cfcb7be93368c6de9963d30f43a6a73998a9cf4b17b46" +dependencies = [ + "bitflags", + "cfg-if", + "cfg_aliases 0.2.1", "libc", ] @@ -1086,7 +1114,7 @@ dependencies = [ "libc", "log", "memchr", - "nix", + "nix 0.28.0", "radix_trie", "rustyline-derive", "unicode-segmentation", @@ -1167,6 +1195,7 @@ version = "0.1.0" dependencies = [ "anyhow", "clap", + "ctrlc", "deno_task_shell", "dirs", "futures", @@ -1468,7 +1497,7 @@ dependencies = [ "glob", "itertools", "libc", - "nix", + "nix 0.28.0", "number_prefix", "once_cell", "os_display", diff --git a/crates/shell/Cargo.toml b/crates/shell/Cargo.toml index e134ed6..fc8c45f 100644 --- a/crates/shell/Cargo.toml +++ b/crates/shell/Cargo.toml @@ -34,6 +34,7 @@ dirs = "5.0.1" which = "6.0.3" uu_uname = "0.0.27" uu_date = "0.0.27" +ctrlc = "3.4.5" [package.metadata.release] # Dont publish the binary diff --git a/crates/shell/src/main.rs b/crates/shell/src/main.rs index 9b72392..583023a 100644 --- a/crates/shell/src/main.rs +++ b/crates/shell/src/main.rs @@ -35,6 +35,11 @@ async fn interactive() -> anyhow::Result<()> { .completion_type(CompletionType::List) .build(); + ctrlc::set_handler(move || { + println!("Received Ctrl+C"); + }) + .expect("Error setting Ctrl-C handler"); + let mut rl = Editor::with_config(config)?; let helper = helper::ShellPromptHelper::default();