diff options
Diffstat (limited to 'src/key_command/impl_from_str.rs')
-rw-r--r-- | src/key_command/impl_from_str.rs | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/src/key_command/impl_from_str.rs b/src/key_command/impl_from_str.rs index 55a7fd7..74bac5d 100644 --- a/src/key_command/impl_from_str.rs +++ b/src/key_command/impl_from_str.rs @@ -113,8 +113,11 @@ impl std::str::FromStr for Command { Self::CustomSearchInteractive(arg.split(' ').map(|x| x.to_string()).collect()) ); simple_command_conversion_case!(command, CMD_SUBDIR_FZF, Self::SubdirFzf); - simple_command_conversion_case!(command, CMD_ZOXIDE, Self::Zoxide(arg.to_string())); - simple_command_conversion_case!(command, CMD_ZOXIDE_INTERACTIVE, Self::ZoxideInteractive); + simple_command_conversion_case!( + command, + CMD_ZOXIDE_INTERACTIVE, + Self::ZoxideInteractive(arg.to_string()) + ); if command == CMD_QUIT { match arg { @@ -602,6 +605,28 @@ impl std::str::FromStr for Command { Ok(Self::FilterString { pattern: arg.to_string(), }) + } else if command == CMD_ZOXIDE { + match arg { + "" => match HOME_DIR.as_ref() { + Some(s) => Ok(Self::ChangeDirectory { path: s.clone() }), + None => Err(AppError::new( + AppErrorKind::EnvVarNotPresent, + format!("{}: Cannot find home directory", command), + )), + }, + ".." => Ok(Self::ParentDirectory), + "-" => Ok(Self::PreviousDirectory), + arg => { + let (head, tail) = match arg.find(' ') { + Some(i) => (&arg[..i], &arg[i..]), + None => (arg, ""), + }; + let head = unix::expand_shell_string_cow(head); + let mut args = String::from(head); + args.push_str(tail); + Ok(Self::Zoxide(args)) + } + } } else { Err(AppError::new( AppErrorKind::UnrecognizedCommand, |