From 8f7b45ca8dd7f8ec188401bad99c529ea031c4eb Mon Sep 17 00:00:00 2001 From: fzdwx Date: Wed, 26 Jul 2023 09:16:22 +0800 Subject: [PATCH] feat: add `command` operation --- config/keymap.toml | 4 +++- src/core/manager/manager.rs | 30 ++++++++++++++++++++++++++++++ src/ui/dispatcher.rs | 1 + 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/config/keymap.toml b/config/keymap.toml index ee6d49c2..072ad44e 100644 --- a/config/keymap.toml +++ b/config/keymap.toml @@ -48,6 +48,8 @@ keymap = [ { on = [ "" ], exec = "search none" }, { on = [ "z" ], exec = "jump zoxide" }, { on = [ "Z" ], exec = "jump fzf" }, + { on = [ ";" ], exec = "command" }, + { on = [ ":" ], exec = "command" }, # Sorting { on = [ ",", "a" ], exec = "sort alphabetical" }, @@ -81,7 +83,7 @@ keymap = [ { on = [ "g", "h" ], exec = "cd ~" }, { on = [ "g", "c" ], exec = "cd ~/.config" }, { on = [ "g", "d" ], exec = "cd ~/Downloads" }, - { on = [ "g", "t" ], exec = "cd /tmp" }, + { on = [ "m", "g" ], exec = "cd /tmp" }, ] [tasks] diff --git a/src/core/manager/manager.rs b/src/core/manager/manager.rs index 5c36c183..95e128d1 100644 --- a/src/core/manager/manager.rs +++ b/src/core/manager/manager.rs @@ -1,6 +1,8 @@ use std::{collections::{BTreeMap, BTreeSet, HashMap, HashSet}, env, mem, path::PathBuf}; +use std::process::Stdio; use tokio::fs; +use tokio::process::Command; use super::{PreviewData, Tab, Tabs, Watcher}; use crate::{config::OPEN, core::{external, files::{File, FilesOp}, input::InputOpt, manager::Folder, select::SelectOpt, tasks::Tasks, Position}, emit}; @@ -216,6 +218,34 @@ impl Manager { false } + pub fn command(&self) -> bool { + let cwd = self.tabs.active().current.cwd.clone(); + + tokio::spawn(async move { + let result = emit!(Input(InputOpt { + title: "Command:".to_string(), + value: "".to_string(), + position: Position::Top, + })) + .await; + + if let Ok(command) = result { + Command::new("sh") + .current_dir(&cwd) + .arg("-c") + .arg(command) + .kill_on_drop(false) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .spawn() + .ok(); + + } + }); + + return false + } + fn bulk_rename(&self) -> bool { false } pub fn selected(&self) -> Vec<&File> { diff --git a/src/ui/dispatcher.rs b/src/ui/dispatcher.rs index 5be44529..7e4f21bf 100644 --- a/src/ui/dispatcher.rs +++ b/src/ui/dispatcher.rs @@ -114,6 +114,7 @@ impl Executor { "zoxide" => cx.manager.active_mut().jump(false), _ => false, }, + "command"=> cx.manager.command(), // Sorting "sort" => {