feat: add command operation

This commit is contained in:
fzdwx 2023-07-26 09:16:22 +08:00
parent e2a4894111
commit 8f7b45ca8d
3 changed files with 34 additions and 1 deletions

View file

@ -48,6 +48,8 @@ keymap = [
{ on = [ "<C-s>" ], 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]

View file

@ -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> {

View file

@ -114,6 +114,7 @@ impl Executor {
"zoxide" => cx.manager.active_mut().jump(false),
_ => false,
},
"command"=> cx.manager.command(),
// Sorting
"sort" => {