diff options
author | Ken Matsui <26405363+ken-matsui@users.noreply.github.com> | 2021-11-08 09:12:31 +0900 |
---|---|---|
committer | Ken Matsui <26405363+ken-matsui@users.noreply.github.com> | 2021-11-11 13:14:59 +0900 |
commit | 00b47b3058b6adc6f4e17651ea6b73f81435b8b6 (patch) | |
tree | dcdb215a04077d925107a4c6bd83b3f6039457d7 | |
parent | c9f92409696f6e43df4984a70ef57c7a0d17f158 (diff) |
feat(sessions): Suggestion for a similar session name
Remove unnecessary to_string
Replace `garando_syntax` crate with `lev_distance` which is much smaller
Replace `lev_distance` crate with `suggestion` to simplify the code
-rw-r--r-- | Cargo.lock | 16 | ||||
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | src/sessions.rs | 4 |
3 files changed, 21 insertions, 0 deletions
diff --git a/Cargo.lock b/Cargo.lock index 859c316e8..72c766b08 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1175,6 +1175,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" [[package]] +name = "lev_distance" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d234d89ecf5621c935b69a4c7266c9a634a95e465081682be47358617ce825b" + +[[package]] name = "libc" version = "0.2.106" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2153,6 +2159,15 @@ dependencies = [ ] [[package]] +name = "suggestion" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "015336207b7660be204f5012fcdb84b3ff35442b26cea77ebe6103929a56e54b" +dependencies = [ + "lev_distance", +] + +[[package]] name = "syn" version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2868,6 +2883,7 @@ dependencies = [ "names", "rand 0.8.4", "ssh2", + "suggestion", "zellij-client", "zellij-server", "zellij-utils", diff --git a/Cargo.toml b/Cargo.toml index c964af417..0830ddd7e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,7 @@ zellij-server = { path = "zellij-server/", version = "0.20.0" } zellij-utils = { path = "zellij-utils/", version = "0.20.0" } log = "0.4.14" dialoguer = "0.9.0" +suggestion = "0.1.0" [dev-dependencies] insta = { version = "1.6.0", features = ["backtrace"] } diff --git a/src/sessions.rs b/src/sessions.rs index bf44d0885..4d2fe5fb9 100644 --- a/src/sessions.rs +++ b/src/sessions.rs @@ -1,6 +1,7 @@ use std::os::unix::fs::FileTypeExt; use std::time::SystemTime; use std::{fs, io, process}; +use suggestion::Suggest; use zellij_utils::{ consts::ZELLIJ_SOCK_DIR, interprocess::local_socket::LocalSocketStream, @@ -177,6 +178,9 @@ pub(crate) fn assert_session(name: &str) { return; } else { println!("No session named {:?} found.", name); + if let Some(sugg) = get_sessions().unwrap().suggest(name) { + println!(" help: Did you mean `{}`?", sugg); + } } } Err(e) => { |