Add running commands to an action
Add the ability to bind running commands to
an action.
Eg:
```
- action: [Run: {command: "htop",},]
key: [F: 6,]
``
Optionally the direction and arguments can be
specified:
```
- action: [Run: {command: "htop", args: ["-C",]},]
key: [F: 7,]
```
The directional splits are analogous to the `[NewPane]` splits.
```
- action: [Run: {command: "htop", args: ["-C",], direction: "Up"},]
key: [F: 8,]
```
This commit is contained in:
parent
71f980a01d
commit
0bf78100dd
3 changed files with 37 additions and 1 deletions
|
|
@ -10,6 +10,7 @@ use zellij_utils::{
|
||||||
channels::SenderWithContext,
|
channels::SenderWithContext,
|
||||||
input::{
|
input::{
|
||||||
actions::{Action, Direction},
|
actions::{Action, Direction},
|
||||||
|
command::TerminalAction,
|
||||||
get_mode_info,
|
get_mode_info,
|
||||||
},
|
},
|
||||||
ipc::{ClientToServerMsg, ExitReason, ServerToClientMsg},
|
ipc::{ClientToServerMsg, ExitReason, ServerToClientMsg},
|
||||||
|
|
@ -143,6 +144,18 @@ fn route_action(
|
||||||
};
|
};
|
||||||
session.senders.send_to_pty(pty_instr).unwrap();
|
session.senders.send_to_pty(pty_instr).unwrap();
|
||||||
}
|
}
|
||||||
|
Action::Run(command) => {
|
||||||
|
let run_cmd = Some(TerminalAction::RunCommand(command.clone().into()));
|
||||||
|
let pty_instr = match command.direction {
|
||||||
|
Some(Direction::Left) => PtyInstruction::SpawnTerminalVertically(run_cmd),
|
||||||
|
Some(Direction::Right) => PtyInstruction::SpawnTerminalVertically(run_cmd),
|
||||||
|
Some(Direction::Up) => PtyInstruction::SpawnTerminalHorizontally(run_cmd),
|
||||||
|
Some(Direction::Down) => PtyInstruction::SpawnTerminalHorizontally(run_cmd),
|
||||||
|
// No direction specified - try to put it in the biggest available spot
|
||||||
|
None => PtyInstruction::SpawnTerminal(run_cmd),
|
||||||
|
};
|
||||||
|
session.senders.send_to_pty(pty_instr).unwrap();
|
||||||
|
}
|
||||||
Action::CloseFocus => {
|
Action::CloseFocus => {
|
||||||
session
|
session
|
||||||
.senders
|
.senders
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
//! Definition of the actions that can be bound to keys.
|
//! Definition of the actions that can be bound to keys.
|
||||||
|
|
||||||
|
use super::command::RunCommandAction;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use zellij_tile::data::InputMode;
|
use zellij_tile::data::InputMode;
|
||||||
|
|
||||||
|
|
@ -65,6 +66,8 @@ pub enum Action {
|
||||||
CloseTab,
|
CloseTab,
|
||||||
GoToTab(u32),
|
GoToTab(u32),
|
||||||
TabNameInput(Vec<u8>),
|
TabNameInput(Vec<u8>),
|
||||||
|
/// Run speficied command in new pane.
|
||||||
|
Run(RunCommandAction),
|
||||||
/// Detach session and exit
|
/// Detach session and exit
|
||||||
Detach,
|
Detach,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
//! Trigger a command
|
//! Trigger a command
|
||||||
|
use super::actions::Direction;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
|
@ -8,9 +9,28 @@ pub enum TerminalAction {
|
||||||
RunCommand(RunCommand),
|
RunCommand(RunCommand),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Default, Serialize, PartialEq)]
|
#[derive(Clone, Debug, Deserialize, Default, Serialize, PartialEq, Eq)]
|
||||||
pub struct RunCommand {
|
pub struct RunCommand {
|
||||||
pub command: PathBuf,
|
pub command: PathBuf,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub args: Vec<String>,
|
pub args: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Intermediate representation
|
||||||
|
#[derive(Clone, Debug, Deserialize, Default, Serialize, PartialEq, Eq)]
|
||||||
|
pub struct RunCommandAction {
|
||||||
|
pub command: PathBuf,
|
||||||
|
#[serde(default)]
|
||||||
|
pub args: Vec<String>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub direction: Option<Direction>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<RunCommandAction> for RunCommand {
|
||||||
|
fn from(action: RunCommandAction) -> Self {
|
||||||
|
RunCommand {
|
||||||
|
command: action.command,
|
||||||
|
args: action.args,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue