diff options
author | Jeff Zhao <jeff.no.zhao@gmail.com> | 2022-05-04 16:35:43 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-04 16:35:43 -0400 |
commit | 9a2b3b17f53096bacd3cd86b2dbed454b8ff88b2 (patch) | |
tree | 8f3c0575e94252ddce3ca78af294aae6a0c3afd0 | |
parent | 230bc2bf388b56e6da39668c65d242ef1bc1c8d6 (diff) |
Add zoxide integration (#169)
* add initial support for zoxide
* update docs
* inform user how many files was selected when glob selecting
* cargo update
* move input.rs to process_event.rs
* add 'zoxide add' and parsing zoxide errors
* cargo fmt
* remove stderr capture for zoxide interactive
-rw-r--r-- | Cargo.lock | 88 | ||||
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | docs/configuration/keymap.toml.md | 21 | ||||
-rw-r--r-- | src/commands/help.rs | 4 | ||||
-rw-r--r-- | src/commands/mod.rs | 1 | ||||
-rw-r--r-- | src/commands/numbered_command.rs | 4 | ||||
-rw-r--r-- | src/commands/selection.rs | 5 | ||||
-rw-r--r-- | src/commands/show_workers.rs | 14 | ||||
-rw-r--r-- | src/commands/zoxide.rs | 83 | ||||
-rw-r--r-- | src/context/app_context.rs | 1 | ||||
-rw-r--r-- | src/context/commandline_context.rs | 1 | ||||
-rw-r--r-- | src/context/message_queue.rs | 19 | ||||
-rw-r--r-- | src/context/preview_context.rs | 1 | ||||
-rw-r--r-- | src/event/mod.rs | 4 | ||||
-rw-r--r-- | src/event/process_event.rs (renamed from src/util/input.rs) | 0 | ||||
-rw-r--r-- | src/key_command/command.rs | 8 | ||||
-rw-r--r-- | src/key_command/constants.rs | 6 | ||||
-rw-r--r-- | src/key_command/impl_appcommand.rs | 13 | ||||
-rw-r--r-- | src/key_command/impl_appexecute.rs | 18 | ||||
-rw-r--r-- | src/key_command/impl_comment.rs | 8 | ||||
-rw-r--r-- | src/key_command/impl_from_str.rs | 7 | ||||
-rw-r--r-- | src/run.rs | 10 | ||||
-rw-r--r-- | src/ui/views/tui_textfield.rs | 4 | ||||
-rw-r--r-- | src/ui/widgets/tui_prompt.rs | 4 | ||||
-rw-r--r-- | src/util/mod.rs | 1 |
25 files changed, 212 insertions, 114 deletions
@@ -19,11 +19,11 @@ checksum = "77e9c9abb82613923ec78d7a461595d52491ba7240f3c64c0bbe0e6d98e0fce0" [[package]] name = "ansi-to-tui" -version = "0.4.1" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c3fb5747c9d1b444cb6c9f96c84d09a3f7ae9e1eb77f52ec45c8bf30a6e6bdf" +checksum = "432bad6a85e6443b2ba2296fb43c6d843594f2f0daa55a8b86202dd3c1dc0a99" dependencies = [ - "tui 0.16.0", + "tui 0.17.0", ] [[package]] @@ -234,9 +234,9 @@ dependencies = [ [[package]] name = "filetime" -version = "0.2.15" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "975ccf83d8d9d0d84682850a38c8169027be83368805971cc4f238c2b245bc98" +checksum = "c0408e2626025178a6a7f7ffc05a25bc47103229f19c113755de7bf63816290c" dependencies = [ "cfg-if 1.0.0", "libc", @@ -359,7 +359,7 @@ dependencies = [ "termion", "toml", "trash", - "tui 0.17.0", + "tui 0.18.0", "unicode-segmentation", "unicode-width", "users", @@ -369,9 +369,9 @@ dependencies = [ [[package]] name = "kqueue" -version = "1.0.4" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "058a107a784f8be94c7d35c1300f4facced2e93d2fbe5b1452b44e905ddca4a9" +checksum = "4d6112e8f37b59803ac47a42d14f1f3a59bbf72fc6857ffc5be455e28a691f8e" dependencies = [ "kqueue-sys", "libc", @@ -395,24 +395,24 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.121" +version = "0.2.125" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efaa7b300f3b5fe8eb6bf21ce3895e1751d9665086af2d64b42f19701015ff4f" +checksum = "5916d2ae698f6de9bfb891ad7a8d65c09d232dc58cc4ac433c7da3b2fd84bc2b" [[package]] name = "log" -version = "0.4.16" +version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6389c490849ff5bc16be905ae24bc913a9c8892e19b2341dbc175e14c341c2b8" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" dependencies = [ "cfg-if 1.0.0", ] [[package]] name = "memchr" -version = "2.4.1" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "mio" @@ -452,9 +452,9 @@ dependencies = [ [[package]] name = "notify" -version = "5.0.0-pre.14" +version = "5.0.0-pre.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d13c22db70a63592e098fb51735bab36646821e6389a0ba171f3549facdf0b74" +checksum = "553f9844ad0b0824605c20fb55a661679782680410abfb1a8144c2e7e437e7a7" dependencies = [ "bitflags", "crossbeam-channel", @@ -479,9 +479,9 @@ dependencies = [ [[package]] name = "num-integer" -version = "0.1.44" +version = "0.1.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" +checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" dependencies = [ "autocfg", "num-traits", @@ -489,9 +489,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" +checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" dependencies = [ "autocfg", ] @@ -504,9 +504,9 @@ checksum = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" [[package]] name = "open" -version = "2.1.1" +version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9213e7b66aa06a7722828ee2980c1adff22a3922b582baaa1e62e30ca2a6c018" +checksum = "e0524af9508f9b5c4eb41dce095860456727748f63b478d625f119a70e0d764a" dependencies = [ "pathdiff", "winapi", @@ -600,18 +600,18 @@ checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" [[package]] name = "proc-macro2" -version = "1.0.36" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029" +checksum = "ec757218438d5fda206afc041538b2f6d889286160d649a86a24d37e1235afd1" dependencies = [ "unicode-xid", ] [[package]] name = "quote" -version = "1.0.17" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "632d02bff7f874a36f33ea8bb416cd484b90cc66c1194b1a1110d067a7013f58" +checksum = "a1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1" dependencies = [ "proc-macro2", ] @@ -749,15 +749,15 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.136" +version = "1.0.137" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce31e24b01e1e524df96f1c2fdd054405f8d7376249a5110886fb4b658484789" +checksum = "61ea8d54c77f8315140a05f4c7237403bf38b72704d031543aa1d16abbf517d1" [[package]] name = "serde_derive" -version = "1.0.136" +version = "1.0.137" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08597e7152fcd306f41838ed3e37be9eaeed2b61c42e2117266a554fab4662f9" +checksum = "1f26faba0c3959972377d3b2d306ee9f71faee9714294e41bb777f83f88578be" dependencies = [ "proc-macro2", "quote", @@ -836,9 +836,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.90" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "704df27628939572cd88d33f171cd6f896f4eaca85252c6e0a72d8d8287ee86f" +checksum = "7ff7c592601f11445996a06f8ad0c27f094a58857c2f89e97974ab9235b92c52" dependencies = [ "proc-macro2", "quote", @@ -868,18 +868,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.30" +version = "1.0.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "854babe52e4df1653706b98fcfc05843010039b406875930a70e4d9644e5c417" +checksum = "bd829fe32373d27f76265620b5309d0340cb8550f523c1dda251d6298069069a" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.30" +version = "1.0.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b" +checksum = "0396bc89e626244658bef819e22d0cc459e795a5ebe878e6ec336d1674a8d79a" dependencies = [ "proc-macro2", "quote", @@ -898,9 +898,9 @@ dependencies = [ [[package]] name = "toml" -version = "0.5.8" +version = "0.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa" +checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7" dependencies = [ "serde", ] @@ -916,9 +916,9 @@ dependencies = [ [[package]] name = "tui" -version = "0.16.0" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39c8ce4e27049eed97cfa363a5048b09d995e209994634a0efc26a14ab6c0c23" +checksum = "23ed0a32c88b039b73f1b6c5acbd0554bfa5b6be94467375fd947c4de3a02271" dependencies = [ "bitflags", "cassowary", @@ -928,9 +928,9 @@ dependencies = [ [[package]] name = "tui" -version = "0.17.0" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23ed0a32c88b039b73f1b6c5acbd0554bfa5b6be94467375fd947c4de3a02271" +checksum = "96fe69244ec2af261bced1d9046a6fee6c8c2a6b0228e59e5ba39bc8ba4ed729" dependencies = [ "bitflags", "cassowary", @@ -953,9 +953,9 @@ checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" [[package]] name = "unicode-xid" -version = "0.2.2" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" +checksum = "957e51f3646910546462e67d5f7599b9e4fb8acdd304b087a6494730f9eebf04" [[package]] name = "users" @@ -14,6 +14,7 @@ - [rustc](https://www.rust-lang.org/) >= 1.55 - xsel/xclip/wl-clipboard (optional, for clipboard support) - fzf (optional) +- zoxide (optional) Also see [Cargo.toml](Cargo.toml) diff --git a/docs/configuration/keymap.toml.md b/docs/configuration/keymap.toml.md index bfd9854..9aeef6a 100644 --- a/docs/configuration/keymap.toml.md +++ b/docs/configuration/keymap.toml.md @@ -51,7 +51,8 @@ f12 - [Navigation](#navigation) - [Tabs](#tabs) - [Search](#search) -- [Misc](#misc) +- [Integration](#integration) + ## General - `quit`: quit joshuto @@ -141,8 +142,6 @@ function joshuto() { it will prompt `:open_with ` to open with a specific command - if `xdg_open` is `true` in [joshuto.toml](https://github.com/kamiyaa/joshuto), joshuto will try to open it via xdg settings - - `subdir_fzf`: go to a subdirectory via fzf - ## Tabs - `new_tab`: opens a new tab @@ -187,13 +186,12 @@ function joshuto() { ## Search - - `search`: search via string + - `search`: search the current directory via a string - case insensitive - - `search_glob`: search via shell globbing + - `search_glob`: search the current directory via shell globbing - `:search_glob *.png` - - `search_fzf`: search via fzf - - `search_next`: go to next search result - - `search_prev`: go to previous search result + - `search_next`: go to next search result in the current directory + - `search_prev`: go to previous search result in the current directory - `select`: select current file - `--toggle=true`: toggle the selected files - `--all=true`: selected all files @@ -201,8 +199,13 @@ function joshuto() { - `glob`: select files based on glob (just like `search_glob`) - `select *.png` -## Misc +## Integration - `bulk_rename`: rename all selected files - this will create a file inside `$TMP_DIR` (or `/tmp` if `$TMP_DIR` is not set) and open up your text editor of choice via `$EDITOR` environment variable - once you've made your changes to the file, saved and quit, it will use the `mv` command to rename everything + - `search_fzf`: search the current directory via `fzf` + - `subdir_fzf`: go to a subdirectory via `fzf` + + - `z`: cd via `zoxide` + - `zi`: cd via interactive `zoxide` diff --git a/src/commands/help.rs b/src/commands/help.rs index 4f63e4e..bd8507d 100644 --- a/src/commands/help.rs +++ b/src/commands/help.rs @@ -5,12 +5,12 @@ use termion::event::{Event, Key}; use crate::config::AppKeyMapping; use crate::context::AppContext; use crate::error::JoshutoResult; +use crate::event::process_event; use crate::event::AppEvent; use crate::key_command::{Command, CommandKeybind}; use crate::ui::widgets; use crate::ui::widgets::TuiHelp; use crate::ui::TuiBackend; -use crate::util::input; pub fn help_loop( context: &mut AppContext, @@ -76,7 +76,7 @@ pub fn help_loop( } context.flush_event(); } - _ => input::process_noninteractive(event, context), + _ => process_event::process_noninteractive(event, context), } } diff --git a/src/commands/mod.rs b/src/commands/mod.rs index d01c3e3..f585bbc 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -27,3 +27,4 @@ pub mod sub_process; pub mod subdir_fzf; pub mod tab_ops; pub mod touch_file; +pub mod zoxide; diff --git a/src/commands/numbered_command.rs b/src/commands/numbered_command.rs index 16e3991..06e97ac 100644 --- a/src/commands/numbered_command.rs +++ b/src/commands/numbered_command.rs @@ -4,11 +4,11 @@ use crate::commands::cursor_move; use crate::config::AppKeyMapping; use crate::context::AppContext; use crate::error::{JoshutoError, JoshutoErrorKind, JoshutoResult}; +use crate::event::process_event; use crate::event::AppEvent; use crate::key_command::{CommandKeybind, NumberedExecute}; use crate::ui::views::TuiView; use crate::ui::TuiBackend; -use crate::util::input; pub fn numbered_command( first_char: char, @@ -66,7 +66,7 @@ pub fn numbered_command( } context.flush_event(); } - event => input::process_noninteractive(event, context), + event => process_event::process_noninteractive(event, context), } } } diff --git a/src/commands/selection.rs b/src/commands/selection.rs index 99f2471..a4d26c4 100644 --- a/src/commands/selection.rs +++ b/src/commands/selection.rs @@ -57,10 +57,12 @@ fn select_with_pattern( let glob = Glob::new(pattern)?.compile_matcher(); if let Some(curr_list) = context.tab_context_mut().curr_tab_mut().curr_list_mut() { + let mut found = 0; curr_list .iter_mut() .filter(|e| glob.is_match(e.file_name())) .for_each(|e| { + found += 1; if options.reverse { e.set_selected(false); } else if options.toggle { @@ -69,6 +71,9 @@ fn select_with_pattern( e.set_selected(true); } }); + context + .message_queue_mut() + .push_info(format!("{} files selected", found)); } Ok(()) } diff --git a/src/commands/show_workers.rs b/src/commands/show_workers.rs index cc6c65c..e20530a 100644 --- a/src/commands/show_workers.rs +++ b/src/commands/show_workers.rs @@ -3,10 +3,10 @@ use termion::event::{Event, Key}; use crate::config::AppKeyMapping; use crate::context::AppContext; use crate::error::JoshutoResult; +use crate::event::process_event; use crate::event::AppEvent; use crate::ui::views::TuiWorkerView; use crate::ui::TuiBackend; -use crate::util::input; pub fn show_workers( context: &mut AppContext, @@ -20,15 +20,13 @@ pub fn show_workers( if let Ok(event) = context.poll_event() { match event { - AppEvent::Termion(event) => { - #[allow(clippy::single_match)] - match event { - Event::Key(Key::Esc) => break, - _ => {} - } + AppEvent::Termion(Event::Key(Key::Esc)) => { + break; + } + AppEvent::Termion(_) => { context.flush_event(); } - event => input::process_noninteractive(event, context), + event => process_event::process_noninteractive(event, context), }; } } diff --git a/src/commands/zoxide.rs b/src/commands/zoxide.rs new file mode 100644 index 0000000..1abe9f2 --- /dev/null +++ b/src/commands/zoxide.rs @@ -0,0 +1,83 @@ +use std::io; +use std::path::Path; +use std::process::{Command, Stdio}; + +use crate::commands::change_directory; +use crate::context::AppContext; +use crate::error::JoshutoResult; +use crate::ui::TuiBackend; + +pub fn zoxide_query(context: &mut AppContext, args: &str) -> JoshutoResult { + let cwd = std::env::current_dir()?; + + let zoxide_output = Command::new("zoxide") + .arg("query") + .arg("--exclude") + .arg(&cwd) + .arg("--") + .arg(args) + .output()?; + + if zoxide_output.status.success() { + if let Ok(zoxide_str) = std::str::from_utf8(&zoxide_output.stdout) { + let zoxide_path = &zoxide_str[..zoxide_str.len() - 1]; + zoxide_add(zoxide_path)?; + + let path = Path::new(zoxide_path); + context + .message_queue_mut() + .push_info(format!("z {:?}", zoxide_path)); + change_directory::change_directory(context, &path)?; + } + } else { + if let Ok(zoxide_str) = std::str::from_utf8(&zoxide_output.stderr) { + context + .message_queue_mut() + .push_error(zoxide_str.to_string()); + } + } + Ok(()) +} + +pub fn zoxide_query_interactive( + context: &mut AppContext, + backend: &mut TuiBackend, +) -> JoshutoResult { + backend.terminal_drop(); + + let zoxide_process = Command::new("zoxide") + .arg("query") + .arg("-i") + .arg("--") + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .spawn()?; + let zoxide_output = zoxide_process.wait_with_output()?; + + backend.terminal_restore()?; + + if zoxide_output.status.success() { + if let Ok(zoxide_str) = std::str::from_utf8(&zoxide_output.stdout) { + let zoxide_path = &zoxide_str[..zoxide_str.len() - 1]; + zoxide_add(zoxide_path)?; + + let path = Path::new(zoxide_path); + context + .message_queue_mut() + .push_info(format!("zi {:?}", zoxide_path)); + change_directory::change_directory(context, &path)?; + } + } else { + if let Ok(zoxide_str) = std::str::from_utf8(&zoxide_output.stderr) { + context + .message_queue_mut() + .push_error(zoxide_str.to_string()); + } + } + Ok(()) +} + +fn zoxide_add(s: &str) -> io::Result<()> { + Command::new("zoxide").arg("add").arg(s).output()?; + Ok(()) +} diff --git a/src/context/app_context.rs b/src/context/app_context.rs index b2b70e1..364b5b1 100644 --- a/src/context/app_context.rs +++ b/src/context/app_context.rs @@ -282,7 +282,6 @@ impl AppContext { pub fn commandline_context_ref(&self) -> &CommandLineContext { &self.commandline_context } - pub fn commandline_context_mut(&mut self) -> &mut CommandLineContext { &mut self.commandline_context } diff --git a/src/context/commandline_context.rs b/src/context/commandline_context.rs index 6a6142b..5169029 100644 --- a/src/context/commandline_context.rs +++ b/src/context/commandline_context.rs @@ -20,7 +20,6 @@ impl CommandLineContext { pub fn history_ref(&self) -> &history::History { &self.history } - pub fn history_mut(&mut self) -> &mut history::History { &mut self.history } diff --git a/src/context/message_queue.rs b/src/context/message_queue.rs index f90ad53..0208b96 100644 --- a/src/context/message_queue.rs +++ b/src/context/message_queue.rs @@ -23,30 +23,27 @@ impl MessageQueue { Self::default() } - pub fn push_success(&mut self, msg: String) { - let message = Message::new(msg, Style::default().fg(Color::Green)); - self.push_msg(message); - } - pub fn push_info(&mut self, msg: String) { let message = Message::new(msg, Style::default().fg(Color::Yellow)); self.push_msg(message); } - + pub fn push_success(&mut self, msg: String) { + let message = Message::new(msg, Style::default().fg(Color::Green)); + self.push_msg(message); + } pub fn push_error(&mut self, msg: String) { let message = Message::new(msg, Style::default().fg(Color::Red)); self.push_msg(message); } - fn push_msg(&mut self, msg: Message) { - self.contents.push_back(msg); - } - pub fn pop_front(&mut self) -> Option<Message> { self.contents.pop_front() } - pub fn current_message(&self) -> Option<&Message> { self.contents.front() } + + fn push_msg(&mut self, msg: Message) { + self.contents.push_back(msg); + } } diff --git a/src/context/preview_context.rs b/src/context/preview_context.rs index f952629..05adc5e 100644 --- a/src/context/preview_context.rs +++ b/src/context/preview_context.rs @@ -17,7 +17,6 @@ impl PreviewContext { pub fn get_preview_ref(&self, p: &path::Path) -> Option<&Option<FilePreview>> { self.previews.get(p) } - pub fn get_preview_mut(&mut self, p: &path::Path) -> Option<&mut Option<FilePreview>> { self.previews.get_mut(p) } diff --git a/src/event/mod.rs b/src/event/mod.rs index 79fb031..2d68d61 100644 --- a/src/event/mod.rs +++ b/src/event/mod.rs @@ -1,3 +1,5 @@ -mod app_event; +pub mod app_event; +pub mod process_event; pub use self::app_event::*; +pub use self::process_event::*; diff --git a/src/util/input.rs b/src/event/process_event.rs index 7e89225..7e89225 100644 --- a/src/util/input.rs +++ b/src/event/process_event.rs diff --git a/src/key_command/command.rs b/src/key_command/command.rs index 77f2316..6dae33b 100644 --- a/src/key_command/command.rs +++ b/src/key_command/command.rs @@ -57,12 +57,9 @@ pub enum Command { SearchGlob(String), SearchString(String), SearchIncremental(String), - SearchFzf, SearchNext, SearchPrev, - SubdirFzf, - SelectFiles(String, SelectOption), SetMode, SubProcess(Vec<String>, bool), @@ -80,4 +77,9 @@ pub enum Command { TabSwitch(i32), TabSwitchIndex(u32), Help, + + SearchFzf, + SubdirFzf, + Zoxide(String), + ZoxideInteractive, } diff --git a/src/key_command/constants.rs b/src/key_command/constants.rs index 558790c..d9a4202 100644 --- a/src/key_command/constants.rs +++ b/src/key_command/constants.rs @@ -56,10 +56,8 @@ cmd_constants![ (CMD_SEARCH_STRING, "search"), (CMD_SEARCH_INCREMENTAL, "search_inc"), (CMD_SEARCH_GLOB, "search_glob"), - (CMD_SEARCH_FZF, "search_fzf"), (CMD_SEARCH_NEXT, "search_next"), (CMD_SEARCH_PREV, "search_prev"), - (CMD_SUBDIR_FZF, "subdir_fzf"), (CMD_SELECT_FILES, "select"), (CMD_SET_MODE, "set_mode"), (CMD_SORT, "sort"), @@ -73,6 +71,10 @@ cmd_constants![ (CMD_SWITCH_LINE_NUMBERS, "line_nums"), (CMD_TOUCH_FILE, "touch"), (CMD_HELP, "help"), + (CMD_SEARCH_FZF, "search_fzf"), + (CMD_SUBDIR_FZF, "subdir_fzf"), + (CMD_ZOXIDE, "z"), + (CMD_ZOXIDE_INTERACTIVE, "zi"), ]; pub fn complete_command(partial_command: &str) -> Vec<Pair> { diff --git a/src/key_command/impl_appcommand.rs b/src/key_command/impl_appcommand.rs index 6229289..c8bf2eb 100644 --- a/src/key_command/impl_appcommand.rs +++ b/src/key_command/impl_appcommand.rs @@ -55,27 +55,30 @@ impl AppCommand for Command { Self::SearchString(_) => CMD_SEARCH_STRING, Self::SearchIncremental(_) => CMD_SEARCH_INCREMENTAL, Self::SearchGlob(_) => CMD_SEARCH_GLOB, - Self::SearchFzf => CMD_SEARCH_FZF, Self::SearchNext => CMD_SEARCH_NEXT, Self::SearchPrev => CMD_SEARCH_PREV, - Self::SubdirFzf => CMD_SUBDIR_FZF, - Self::SelectFiles(_, _) => CMD_SELECT_FILES, Self::SetMode => CMD_SET_MODE, + Self::ShowWorkers => CMD_SHOW_WORKERS, + Self::Sort(_) => CMD_SORT, Self::SortReverse => CMD_SORT_REVERSE, Self::SubProcess(_, false) => CMD_SUBPROCESS_FOREGROUND, Self::SubProcess(_, true) => CMD_SUBPROCESS_BACKGROUND, - Self::ShowWorkers => CMD_SHOW_WORKERS, + Self::SwitchLineNums(_) => CMD_SWITCH_LINE_NUMBERS, Self::TabSwitch(_) => CMD_TAB_SWITCH, Self::TabSwitchIndex(_) => CMD_TAB_SWITCH_INDEX, Self::ToggleHiddenFiles => CMD_TOGGLE_HIDDEN, - Self::SwitchLineNums(_) => CMD_SWITCH_LINE_NUMBERS, Self::TouchFile(_) => CMD_TOUCH_FILE, + + Self::SearchFzf => CMD_SEARCH_FZF, + Self::SubdirFzf => CMD_SUBDIR_FZF, + Self::Zoxide(_) => CMD_ZOXIDE, + Self::ZoxideInteractive => CMD_ZOXIDE_INTERACTIVE, } } } diff --git a/src/key_command/impl_appexecute.rs b/src/key_command/impl_appexecute.rs index 8996a7c..0a9725c 100644 --- a/src/key_command/impl_appexecute.rs +++ b/src/key_command/impl_appexecute.rs @@ -80,27 +80,22 @@ impl AppExecute for Command { // cursor will be one the selected word. And as `interactive_execute` for // `SearchIncremental` always starts from index 0, this operation will be a no-op Self::SearchIncremental(_) => Ok(()), - Self::SearchFzf => search_fzf::search_fzf(context, backend), Self::SearchNext => search::search_next(context), Self::SearchPrev => search::search_prev(context), - Self::SubdirFzf => subdir_fzf::subdir_fzf(context, backend), - Self::SelectFiles(pattern, options) => { selection::select_files(context, pattern.as_str(), options) } Self::SetMode => set_mode::set_mode(context, backend), + Self::ShowWorkers => show_workers::show_workers(context, backend, keymap_t), + Self::Sort(t) => sort::set_sort(context, *t), + Self::SortReverse => sort::toggle_reverse(context), Self::SubProcess(v, spawn) => { sub_process::sub_process(context, backend, v.as_slice(), *spawn) } - Self::ShowWorkers => show_workers::show_workers(context, backend, keymap_t), - - Self::ToggleHiddenFiles => show_hidden::toggle_hidden(context), - Self::SwitchLineNums(d) => line_nums::switch_line_numbering(context, *d), - Self::Sort(t) => sort::set_sort(context, *t), - Self::SortReverse => sort::toggle_reverse(context), + Self::ToggleHiddenFiles => show_hidden::toggle_hidden(context), Self::TabSwitch(i) => { tab_ops::tab_switch(*i, context)?; @@ -108,6 +103,11 @@ impl AppExecute for Command { } Self::TabSwitchIndex(i) => tab_ops::tab_switch_index(*i as usize, context), Self::Help => help::help_loop(context, backend, keymap_t), + + Self::SearchFzf => search_fzf::search_fzf(context, backend), + Self::SubdirFzf => subdir_fzf::subdir_fzf(context, backend), + Self::Zoxide(arg) => zoxide::zoxide_query(context, &arg), + Self::ZoxideInteractive => zoxide::zoxide_query_interactive(context, backend), } } } diff --git a/src/key_command/impl_comment.rs b/src/key_command/impl_comment.rs index b52e3a2..dbc639a 100644 --- a/src/key_command/impl_comment.rs +++ b/src/key_command/impl_comment.rs @@ -72,12 +72,9 @@ impl CommandComment for Command { Self::SearchString(_) => "Search", Self::SearchIncremental(_) => "Search as you type", Self::SearchGlob(_) => "Search with globbing", - Self::SearchFzf => "Search via fzf", Self::SearchNext => "Next search entry", Self::SearchPrev => "Previous search entry", - Self::SubdirFzf => "Switch to a child directory via fzf", - Self::SelectFiles(_, _) => "Select file", Self::SetMode => "Set file permissions", Self::SubProcess(_, false) => "Run a shell command", @@ -100,6 +97,11 @@ impl CommandComment for Command { Self::TabSwitch(_) => "Swith to the next tab", Self::TabSwitchIndex(_) => "Swith to a given tab", Self::Help => "Open this help page", + + Self::SearchFzf => "Search via fzf", + Self::SubdirFzf => "Switch to a child directory via fzf", + Self::Zoxide(_) => "Zoxide", + Self::ZoxideInteractive => "Zoxide interactive", } |