Merge branch 'suggestion-for-similar-session-name' of https://github.com/ken-matsui/zellij into ken-matsui-suggestion-for-similar-session-name
This commit is contained in:
commit
be692fd6b0
3 changed files with 31 additions and 3 deletions
16
Cargo.lock
generated
16
Cargo.lock
generated
|
|
@ -1174,6 +1174,12 @@ version = "0.2.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67"
|
checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lev_distance"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4d234d89ecf5621c935b69a4c7266c9a634a95e465081682be47358617ce825b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.106"
|
version = "0.2.106"
|
||||||
|
|
@ -2152,6 +2158,15 @@ dependencies = [
|
||||||
"syn",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "suggestion"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "015336207b7660be204f5012fcdb84b3ff35442b26cea77ebe6103929a56e54b"
|
||||||
|
dependencies = [
|
||||||
|
"lev_distance",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "1.0.81"
|
version = "1.0.81"
|
||||||
|
|
@ -2868,6 +2883,7 @@ dependencies = [
|
||||||
"names",
|
"names",
|
||||||
"rand 0.8.4",
|
"rand 0.8.4",
|
||||||
"ssh2",
|
"ssh2",
|
||||||
|
"suggestion",
|
||||||
"zellij-client",
|
"zellij-client",
|
||||||
"zellij-server",
|
"zellij-server",
|
||||||
"zellij-utils",
|
"zellij-utils",
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ zellij-server = { path = "zellij-server/", version = "0.21.0" }
|
||||||
zellij-utils = { path = "zellij-utils/", version = "0.21.0" }
|
zellij-utils = { path = "zellij-utils/", version = "0.21.0" }
|
||||||
log = "0.4.14"
|
log = "0.4.14"
|
||||||
dialoguer = "0.9.0"
|
dialoguer = "0.9.0"
|
||||||
|
suggestion = "0.1.0"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
insta = { version = "1.6.0", features = ["backtrace"] }
|
insta = { version = "1.6.0", features = ["backtrace"] }
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
use std::os::unix::fs::FileTypeExt;
|
use std::os::unix::fs::FileTypeExt;
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
use std::{fs, io, process};
|
use std::{fs, io, process};
|
||||||
|
use suggestion::Suggest;
|
||||||
use zellij_utils::{
|
use zellij_utils::{
|
||||||
consts::ZELLIJ_SOCK_DIR,
|
consts::ZELLIJ_SOCK_DIR,
|
||||||
envs,
|
envs,
|
||||||
|
|
@ -149,9 +150,19 @@ pub(crate) fn session_exists(name: &str) -> Result<bool, io::ErrorKind> {
|
||||||
|
|
||||||
pub(crate) fn assert_session(name: &str) {
|
pub(crate) fn assert_session(name: &str) {
|
||||||
match session_exists(name) {
|
match session_exists(name) {
|
||||||
Ok(result) if result => return,
|
Ok(result) => {
|
||||||
Ok(_) => println!("No session named {:?} found.", name),
|
if result {
|
||||||
Err(e) => eprintln!("Error occurred: {:?}", e),
|
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) => {
|
||||||
|
eprintln!("Error occurred: {:?}", e);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
process::exit(1);
|
process::exit(1);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue