summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorqkzk <qu3nt1n@gmail.com>2024-03-03 21:29:21 +0100
committerqkzk <qu3nt1n@gmail.com>2024-03-03 21:29:21 +0100
commitecacf5ac90d0dfae6d93659fd079dba74a40494d (patch)
tree73aca8439815771089df17fae9d66db55284a56d
parenta81a293dbe942edc0cdd3a0258681922882a493d (diff)
zoxide integration
-rw-r--r--development.md3
-rw-r--r--src/common/constant_strings_paths.rs1
-rw-r--r--src/modes/edit/completion.rs18
3 files changed, 21 insertions, 1 deletions
diff --git a/development.md b/development.md
index 36dc272..c7ca769 100644
--- a/development.md
+++ b/development.md
@@ -876,6 +876,7 @@ New view: Tree ! Toggle with 't', fold with 'z'. Navigate normally.
- replace `tar tvf` by `bsdtar -v --list --file`. Which can preview .deb and .rpm files
- preview torrent files with `transmission-show`
- preview mark, shortcut & history content in second pane while navigating
+- zoxide integration. While typing a path in "Goto mode" (default keybind "alt+g"), the first proposition will come from your zoxide answers.
#### Changelog
@@ -948,6 +949,7 @@ New view: Tree ! Toggle with 't', fold with 'z'. Navigate normally.
- [x] replace `tar tvf` by `bsdtar -v --list --file`. Which can preview .deb and .rpm files
- [x] torrent with `transmission-show`
- [x] preview mark, shortcut & history content in second pane while navigating
+- [x] zoxide support for "alt+g" aka goto mode.
- [ ] FIX: `q` while second window should exit the menu
## TODO
@@ -972,7 +974,6 @@ New view: Tree ! Toggle with 't', fold with 'z'. Navigate normally.
- https://github.com/KillTheMule/nvim-rs/blob/master/examples/basic.rs
- https://neovim.io/doc/user/api.html
-- [ ] zoxide support
- [ ] temporary marks
- [ ] context switch
- [ ] read events from stdin ? can't be done from tuikit. Would require another thread ?
diff --git a/src/common/constant_strings_paths.rs b/src/common/constant_strings_paths.rs
index 5089884..d43966d 100644
--- a/src/common/constant_strings_paths.rs
+++ b/src/common/constant_strings_paths.rs
@@ -212,3 +212,4 @@ pub const LAZYGIT: &str = "lazygit";
pub const NCDU: &str = "ncdu";
/// transmission-show
pub const TRANSMISSION_SHOW: &str = "transmission-show";
+pub const ZOXIDE: &str = "zoxide";
diff --git a/src/modes/edit/completion.rs b/src/modes/edit/completion.rs
index bd4dd58..bcce187 100644
--- a/src/modes/edit/completion.rs
+++ b/src/modes/edit/completion.rs
@@ -4,7 +4,9 @@ use std::fs::{self, ReadDir};
use anyhow::Result;
use strum::IntoEnumIterator;
+use crate::common::{is_program_in_path, ZOXIDE};
use crate::event::ActionMap;
+use crate::io::execute_and_capture_output_with_path;
use crate::modes::Leave;
/// Different kind of completions
@@ -146,6 +148,7 @@ impl Completion {
fn cd_update_from_input(&mut self, input_string: &str, current_path: &str) {
self.proposals = vec![];
+ self.cd_update_from_zoxide(input_string, current_path);
if let Some(expanded_input) = self.expand_input(input_string) {
self.proposals.push(expanded_input);
}
@@ -154,6 +157,21 @@ impl Completion {
}
}
+ fn cd_update_from_zoxide(&mut self, input_string: &str, current_path: &str) {
+ if !is_program_in_path(ZOXIDE) {
+ return;
+ }
+ let mut args = vec!["query"];
+ args.extend(input_string.split(' '));
+ let Ok(zoxide_output) = execute_and_capture_output_with_path(ZOXIDE, current_path, &args)
+ else {
+ return;
+ };
+ if !zoxide_output.is_empty() {
+ self.proposals.push(zoxide_output.trim().to_string());
+ }
+ }
+
fn expand_input(&mut self, input_string: &str) -> Option<String> {
let expanded_input = shellexpand::tilde(input_string).into_owned();
if std::path::PathBuf::from(&expanded_input).exists() {