feat(cli): zellij run improvements (#1804)

* feat(cli): move command to the end of the cli arguments

* feat(cli): allow naming panes from the command line

* fix(cli): adjust actions after pane rename

* feat(cli): zellij run completions for fish

* feat(cli): zellij run completions for bash and zsh

* style(fmt): rustfmt

* fix(e2e): fix run test and snapshot

* style(fmt): rustfmt
This commit is contained in:
Aram Drevekenin 2022-10-17 19:39:37 +02:00 committed by GitHub
parent 4562982409
commit 271abb3ea2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
30 changed files with 270 additions and 121 deletions

View File

@ -148,12 +148,12 @@ fn get_keys_and_hints(mi: &ModeInfo) -> Vec<(String, String, Vec<Key>)> {
(s("Move focus"), s("Move"),
action_key_group(&km, &[&[A::MoveFocus(Dir::Left)], &[A::MoveFocus(Dir::Down)],
&[A::MoveFocus(Dir::Up)], &[A::MoveFocus(Dir::Right)]])),
(s("New"), s("New"), action_key(&km, &[A::NewPane(None), TO_NORMAL])),
(s("New"), s("New"), action_key(&km, &[A::NewPane(None, None), TO_NORMAL])),
(s("Close"), s("Close"), action_key(&km, &[A::CloseFocus, TO_NORMAL])),
(s("Rename"), s("Rename"),
action_key(&km, &[A::SwitchToMode(IM::RenamePane), A::PaneNameInput(vec![0])])),
(s("Split down"), s("Down"), action_key(&km, &[A::NewPane(Some(Dir::Down)), TO_NORMAL])),
(s("Split right"), s("Right"), action_key(&km, &[A::NewPane(Some(Dir::Right)), TO_NORMAL])),
(s("Split down"), s("Down"), action_key(&km, &[A::NewPane(Some(Dir::Down), None), TO_NORMAL])),
(s("Split right"), s("Right"), action_key(&km, &[A::NewPane(Some(Dir::Right), None), TO_NORMAL])),
(s("Fullscreen"), s("Fullscreen"), action_key(&km, &[A::ToggleFocusFullscreen, TO_NORMAL])),
(s("Frames"), s("Frames"), action_key(&km, &[A::TogglePaneFrames, TO_NORMAL])),
(s("Floating toggle"), s("Floating"),
@ -239,8 +239,8 @@ fn get_keys_and_hints(mi: &ModeInfo) -> Vec<(String, String, Vec<Key>)> {
(s("Move focus"), s("Move"), action_key_group(&km, &[
&[A::MoveFocus(Dir::Left)], &[A::MoveFocus(Dir::Down)],
&[A::MoveFocus(Dir::Up)], &[A::MoveFocus(Dir::Right)]])),
(s("Split down"), s("Down"), action_key(&km, &[A::NewPane(Some(Dir::Down)), TO_NORMAL])),
(s("Split right"), s("Right"), action_key(&km, &[A::NewPane(Some(Dir::Right)), TO_NORMAL])),
(s("Split down"), s("Down"), action_key(&km, &[A::NewPane(Some(Dir::Down), None), TO_NORMAL])),
(s("Split right"), s("Right"), action_key(&km, &[A::NewPane(Some(Dir::Right), None), TO_NORMAL])),
(s("Fullscreen"), s("Fullscreen"), action_key(&km, &[A::ToggleFocusFullscreen, TO_NORMAL])),
(s("New tab"), s("New"), action_key(&km, &[A::NewTab(None, None), TO_NORMAL])),
(s("Rename tab"), s("Rename"),
@ -673,7 +673,7 @@ mod tests {
Key::Right,
vec![Action::MoveFocus(actions::Direction::Right)],
),
(Key::Char('n'), vec![Action::NewPane(None), TO_NORMAL]),
(Key::Char('n'), vec![Action::NewPane(None, None), TO_NORMAL]),
(Key::Char('x'), vec![Action::CloseFocus, TO_NORMAL]),
(
Key::Char('f'),
@ -708,7 +708,7 @@ mod tests {
Key::Right,
vec![Action::MoveFocus(actions::Direction::Right)],
),
(Key::Char('n'), vec![Action::NewPane(None), TO_NORMAL]),
(Key::Char('n'), vec![Action::NewPane(None, None), TO_NORMAL]),
(Key::Char('x'), vec![Action::CloseFocus, TO_NORMAL]),
(
Key::Char('f'),
@ -748,7 +748,7 @@ mod tests {
Key::Ctrl(' '),
vec![Action::MoveFocus(actions::Direction::Right)],
),
(Key::Backspace, vec![Action::NewPane(None), TO_NORMAL]),
(Key::Backspace, vec![Action::NewPane(None, None), TO_NORMAL]),
(Key::Esc, vec![Action::CloseFocus, TO_NORMAL]),
(Key::End, vec![Action::ToggleFocusFullscreen, TO_NORMAL]),
],

View File

@ -65,7 +65,7 @@ struct Keygroups<'a> {
fn add_keybinds(help: &ModeInfo) -> Keygroups {
let normal_keymap = help.get_mode_keybinds();
let new_pane_keys = action_key(&normal_keymap, &[Action::NewPane(None)]);
let new_pane_keys = action_key(&normal_keymap, &[Action::NewPane(None, None)]);
let new_pane = if new_pane_keys.is_empty() {
vec![Style::new().bold().paint("UNBOUND")]
} else {

View File

@ -24,6 +24,7 @@ fn main() {
direction,
cwd,
floating,
name,
})) = opts.command
{
let command_cli_action = CliAction::NewPane {
@ -31,6 +32,7 @@ fn main() {
direction,
cwd,
floating,
name,
};
commands::send_action_to_session(command_cli_action, opts.session);
std::process::exit(0);

View File

@ -345,7 +345,9 @@ impl RemoteTerminal {
pub fn send_command_through_the_cli(&mut self, command: &str) {
let mut channel = self.channel.lock().unwrap();
channel
.write_all(format!("{} run \"{}\"\n", ZELLIJ_EXECUTABLE_LOCATION, command).as_bytes())
.write_all(
format!("{} run -- \"{}\"\n", ZELLIJ_EXECUTABLE_LOCATION, command).as_bytes(),
)
.unwrap();
channel.flush().unwrap();
}

View File

@ -6,7 +6,7 @@ expression: last_snapshot
Zellij (e2e-test)  Tab #1 
┌ Pane #1 ─────────────────────────────────────────────────┐┌ /usr/src/zellij/fixtures/append-echo-script.sh ──────────┐
│$ /usr/src/zellij/x86_64-unknown-linux-musl/release/zellij││foo │
│ run "/usr/src/zellij/fixtures/append-echo-script.sh" ││foo │
│ run -- "/usr/src/zellij/fixtures/append-echo-script.sh" ││foo │
│$ ││█ │
│ ││ │
│ ││ │

View File

@ -267,7 +267,7 @@ impl InputHandler {
.send_to_server(ClientToServerMsg::Action(action, None));
},
Action::CloseFocus
| Action::NewPane(_)
| Action::NewPane(..)
| Action::Run(_)
| Action::ToggleFloatingPanes
| Action::TogglePaneEmbedOrFloating

View File

@ -343,9 +343,7 @@ impl Pane for TerminalPane {
input_mode: InputMode,
) -> Option<(Vec<CharacterChunk>, Option<String>)> {
// TODO: remove the cursor stuff from here
let pane_title = if let Some((_exit_status, run_command)) = &self.is_held {
format!("{}", run_command)
} else if self.pane_name.is_empty()
let pane_title = if self.pane_name.is_empty()
&& input_mode == InputMode::RenamePane
&& frame_params.is_main_client
{

View File

@ -31,11 +31,20 @@ pub enum ClientOrTabIndex {
/// Instructions related to PTYs (pseudoterminals).
#[derive(Clone, Debug)]
pub(crate) enum PtyInstruction {
SpawnTerminal(Option<TerminalAction>, Option<bool>, ClientOrTabIndex), // bool (if Some) is
// should_float
SpawnTerminal(
Option<TerminalAction>,
Option<bool>,
Option<String>,
ClientOrTabIndex,
), // bool (if Some) is
// should_float, String is an optional pane name
OpenInPlaceEditor(PathBuf, Option<usize>, ClientId), // Option<usize> is the optional line number
SpawnTerminalVertically(Option<TerminalAction>, ClientId),
SpawnTerminalHorizontally(Option<TerminalAction>, ClientId),
SpawnTerminalVertically(Option<TerminalAction>, Option<String>, ClientId), // String is an
// optional pane
// name
SpawnTerminalHorizontally(Option<TerminalAction>, Option<String>, ClientId), // String is an
// optional pane
// name
UpdateActivePane(Option<PaneId>, ClientId),
GoToTab(TabIndex, ClientId),
NewTab(
@ -82,14 +91,19 @@ pub(crate) fn pty_thread_main(mut pty: Pty, layout: Box<Layout>) {
let (event, mut err_ctx) = pty.bus.recv().expect("failed to receive event on channel");
err_ctx.add_call(ContextType::Pty((&event).into()));
match event {
PtyInstruction::SpawnTerminal(terminal_action, should_float, client_or_tab_index) => {
PtyInstruction::SpawnTerminal(
terminal_action,
should_float,
name,
client_or_tab_index,
) => {
let (hold_on_close, run_command, pane_title) = match &terminal_action {
Some(TerminalAction::RunCommand(run_command)) => (
run_command.hold_on_close,
Some(run_command.clone()),
Some(run_command.to_string()),
Some(name.unwrap_or_else(|| run_command.to_string())),
),
_ => (false, None, None),
_ => (false, None, name),
};
match pty.spawn_terminal(terminal_action, client_or_tab_index) {
Ok(pid) => {
@ -149,14 +163,14 @@ pub(crate) fn pty_thread_main(mut pty: Pty, layout: Box<Layout>) {
},
}
},
PtyInstruction::SpawnTerminalVertically(terminal_action, client_id) => {
PtyInstruction::SpawnTerminalVertically(terminal_action, name, client_id) => {
let (hold_on_close, run_command, pane_title) = match &terminal_action {
Some(TerminalAction::RunCommand(run_command)) => (
run_command.hold_on_close,
Some(run_command.clone()),
Some(run_command.to_string()),
Some(name.unwrap_or_else(|| run_command.to_string())),
),
_ => (false, None, None),
_ => (false, None, name),
};
match pty.spawn_terminal(terminal_action, ClientOrTabIndex::ClientId(client_id)) {
Ok(pid) => {
@ -209,14 +223,14 @@ pub(crate) fn pty_thread_main(mut pty: Pty, layout: Box<Layout>) {
},
}
},
PtyInstruction::SpawnTerminalHorizontally(terminal_action, client_id) => {
PtyInstruction::SpawnTerminalHorizontally(terminal_action, name, client_id) => {
let (hold_on_close, run_command, pane_title) = match &terminal_action {
Some(TerminalAction::RunCommand(run_command)) => (
run_command.hold_on_close,
Some(run_command.clone()),
Some(run_command.to_string()),
Some(name.unwrap_or_else(|| run_command.to_string())),
),
_ => (false, None, None),
_ => (false, None, name),
};
match pty.spawn_terminal(terminal_action, ClientOrTabIndex::ClientId(client_id)) {
Ok(pid) => {

View File

@ -235,43 +235,56 @@ pub(crate) fn route_action(
.send_to_screen(ScreenInstruction::TogglePaneFrames)
.unwrap();
},
Action::NewPane(direction) => {
Action::NewPane(direction, name) => {
let shell = session.default_shell.clone();
let pty_instr = match direction {
Some(Direction::Left) => PtyInstruction::SpawnTerminalVertically(shell, client_id),
Some(Direction::Right) => PtyInstruction::SpawnTerminalVertically(shell, client_id),
Some(Direction::Up) => PtyInstruction::SpawnTerminalHorizontally(shell, client_id),
Some(Direction::Left) => {
PtyInstruction::SpawnTerminalVertically(shell, name, client_id)
},
Some(Direction::Right) => {
PtyInstruction::SpawnTerminalVertically(shell, name, client_id)
},
Some(Direction::Up) => {
PtyInstruction::SpawnTerminalHorizontally(shell, name, client_id)
},
Some(Direction::Down) => {
PtyInstruction::SpawnTerminalHorizontally(shell, client_id)
PtyInstruction::SpawnTerminalHorizontally(shell, name, client_id)
},
// No direction specified - try to put it in the biggest available spot
None => PtyInstruction::SpawnTerminal(
shell,
None,
name,
ClientOrTabIndex::ClientId(client_id),
),
};
session.senders.send_to_pty(pty_instr).unwrap();
},
Action::EditFile(path_to_file, line_number, split_direction, should_float) => {
let title = format!("Editing: {}", path_to_file.display());
let open_file = TerminalAction::OpenFile(path_to_file, line_number);
let pty_instr = match (split_direction, should_float) {
(Some(Direction::Left), false) => {
PtyInstruction::SpawnTerminalVertically(Some(open_file), client_id)
PtyInstruction::SpawnTerminalVertically(Some(open_file), Some(title), client_id)
},
(Some(Direction::Right), false) => {
PtyInstruction::SpawnTerminalVertically(Some(open_file), client_id)
},
(Some(Direction::Up), false) => {
PtyInstruction::SpawnTerminalHorizontally(Some(open_file), client_id)
},
(Some(Direction::Down), false) => {
PtyInstruction::SpawnTerminalHorizontally(Some(open_file), client_id)
PtyInstruction::SpawnTerminalVertically(Some(open_file), Some(title), client_id)
},
(Some(Direction::Up), false) => PtyInstruction::SpawnTerminalHorizontally(
Some(open_file),
Some(title),
client_id,
),
(Some(Direction::Down), false) => PtyInstruction::SpawnTerminalHorizontally(
Some(open_file),
Some(title),
client_id,
),
// No direction specified or should float - defer placement to screen
(None, _) | (_, true) => PtyInstruction::SpawnTerminal(
Some(open_file),
Some(should_float),
Some(title),
ClientOrTabIndex::ClientId(client_id),
),
};
@ -296,7 +309,7 @@ pub(crate) fn route_action(
)))
.unwrap();
},
Action::NewFloatingPane(run_command) => {
Action::NewFloatingPane(run_command, name) => {
let should_float = true;
let run_cmd = run_command
.map(|cmd| TerminalAction::RunCommand(cmd.into()))
@ -306,32 +319,34 @@ pub(crate) fn route_action(
.send_to_pty(PtyInstruction::SpawnTerminal(
run_cmd,
Some(should_float),
name,
ClientOrTabIndex::ClientId(client_id),
))
.unwrap();
},
Action::NewTiledPane(direction, run_command) => {
Action::NewTiledPane(direction, run_command, name) => {
let should_float = false;
let run_cmd = run_command
.map(|cmd| TerminalAction::RunCommand(cmd.into()))
.or_else(|| session.default_shell.clone());
let pty_instr = match direction {
Some(Direction::Left) => {
PtyInstruction::SpawnTerminalVertically(run_cmd, client_id)
PtyInstruction::SpawnTerminalVertically(run_cmd, name, client_id)
},
Some(Direction::Right) => {
PtyInstruction::SpawnTerminalVertically(run_cmd, client_id)
PtyInstruction::SpawnTerminalVertically(run_cmd, name, client_id)
},
Some(Direction::Up) => {
PtyInstruction::SpawnTerminalHorizontally(run_cmd, client_id)
PtyInstruction::SpawnTerminalHorizontally(run_cmd, name, client_id)
},
Some(Direction::Down) => {
PtyInstruction::SpawnTerminalHorizontally(run_cmd, client_id)
PtyInstruction::SpawnTerminalHorizontally(run_cmd, name, client_id)
},
// No direction specified - try to put it in the biggest available spot
None => PtyInstruction::SpawnTerminal(
run_cmd,
Some(should_float),
name,
ClientOrTabIndex::ClientId(client_id),
),
};
@ -368,21 +383,22 @@ pub(crate) fn route_action(
let run_cmd = Some(TerminalAction::RunCommand(command.clone().into()));
let pty_instr = match command.direction {
Some(Direction::Left) => {
PtyInstruction::SpawnTerminalVertically(run_cmd, client_id)
PtyInstruction::SpawnTerminalVertically(run_cmd, None, client_id)
},
Some(Direction::Right) => {
PtyInstruction::SpawnTerminalVertically(run_cmd, client_id)
PtyInstruction::SpawnTerminalVertically(run_cmd, None, client_id)
},
Some(Direction::Up) => {
PtyInstruction::SpawnTerminalHorizontally(run_cmd, client_id)
PtyInstruction::SpawnTerminalHorizontally(run_cmd, None, client_id)
},
Some(Direction::Down) => {
PtyInstruction::SpawnTerminalHorizontally(run_cmd, client_id)
PtyInstruction::SpawnTerminalHorizontally(run_cmd, None, client_id)
},
// No direction specified - try to put it in the biggest available spot
None => PtyInstruction::SpawnTerminal(
run_cmd,
None,
None,
ClientOrTabIndex::ClientId(client_id),
),
};

View File

@ -780,10 +780,12 @@ impl Tab {
}
},
None => {
let name = None;
let should_float = true;
let instruction = PtyInstruction::SpawnTerminal(
default_shell,
Some(should_float),
name,
ClientOrTabIndex::ClientId(client_id),
);
self.senders.send_to_pty(instruction).with_context(|| {

View File

@ -1815,9 +1815,10 @@ pub fn send_cli_new_pane_action_with_default_parameters() {
);
let cli_new_pane_action = CliAction::NewPane {
direction: None,
command: None,
command: vec![],
cwd: None,
floating: false,
name: None,
};
send_cli_action_to_server(
&session_metadata,
@ -1852,9 +1853,10 @@ pub fn send_cli_new_pane_action_with_split_direction() {
);
let cli_new_pane_action = CliAction::NewPane {
direction: Some(Direction::Right),
command: None,
command: vec![],
cwd: None,
floating: false,
name: None,
};
send_cli_action_to_server(
&session_metadata,
@ -1889,9 +1891,10 @@ pub fn send_cli_new_pane_action_with_command_and_cwd() {
);
let cli_new_pane_action = CliAction::NewPane {
direction: Some(Direction::Right),
command: Some("htop".into()),
command: vec!["htop".into()],
cwd: Some("/some/folder".into()),
floating: false,
name: None,
};
send_cli_action_to_server(
&session_metadata,

View File

@ -1,6 +1,6 @@
---
source: zellij-server/src/./unit/screen_tests.rs
assertion_line: 1937
assertion_line: 1944
expression: "format!(\"{:?}\", * received_pty_instructions.lock().unwrap())"
---
[SpawnTerminal(Some(OpenFile("/file/to/edit", None)), Some(false), ClientId(10)), UpdateActivePane(Some(Terminal(0)), 1), UpdateActivePane(Some(Terminal(0)), 1), Exit]
[SpawnTerminal(Some(OpenFile("/file/to/edit", None)), Some(false), Some("Editing: /file/to/edit"), ClientId(10)), UpdateActivePane(Some(Terminal(0)), 1), UpdateActivePane(Some(Terminal(0)), 1), Exit]

View File

@ -1,6 +1,6 @@
---
source: zellij-server/src/./unit/screen_tests.rs
assertion_line: 1974
assertion_line: 1981
expression: "format!(\"{:?}\", * received_pty_instructions.lock().unwrap())"
---
[SpawnTerminal(Some(OpenFile("/file/to/edit", Some(100))), Some(false), ClientId(10)), UpdateActivePane(Some(Terminal(0)), 1), UpdateActivePane(Some(Terminal(0)), 1), Exit]
[SpawnTerminal(Some(OpenFile("/file/to/edit", Some(100))), Some(false), Some("Editing: /file/to/edit"), ClientId(10)), UpdateActivePane(Some(Terminal(0)), 1), UpdateActivePane(Some(Terminal(0)), 1), Exit]

View File

@ -1,6 +1,6 @@
---
source: zellij-server/src/./unit/screen_tests.rs
assertion_line: 2011
assertion_line: 2018
expression: "format!(\"{:?}\", * received_pty_instructions.lock().unwrap())"
---
[SpawnTerminalHorizontally(Some(OpenFile("/file/to/edit", None)), 10), UpdateActivePane(Some(Terminal(0)), 1), UpdateActivePane(Some(Terminal(0)), 1), Exit]
[SpawnTerminalHorizontally(Some(OpenFile("/file/to/edit", None)), Some("Editing: /file/to/edit"), 10), UpdateActivePane(Some(Terminal(0)), 1), UpdateActivePane(Some(Terminal(0)), 1), Exit]

View File

@ -1,6 +1,6 @@
---
source: zellij-server/src/./unit/screen_tests.rs
assertion_line: 1900
assertion_line: 1907
expression: "format!(\"{:?}\", * received_pty_instructions.lock().unwrap())"
---
[SpawnTerminalVertically(Some(RunCommand(RunCommand { command: "htop", args: [], cwd: Some("/some/folder"), hold_on_close: true })), 10), UpdateActivePane(Some(Terminal(0)), 1), UpdateActivePane(Some(Terminal(0)), 1), Exit]
[SpawnTerminalVertically(Some(RunCommand(RunCommand { command: "htop", args: [], cwd: Some("/some/folder"), hold_on_close: true })), None, 10), UpdateActivePane(Some(Terminal(0)), 1), UpdateActivePane(Some(Terminal(0)), 1), Exit]

View File

@ -1,6 +1,6 @@
---
source: zellij-server/src/./unit/screen_tests.rs
assertion_line: 1826
assertion_line: 1831
expression: "format!(\"{:?}\", * received_pty_instructions.lock().unwrap())"
---
[SpawnTerminal(None, Some(false), ClientId(10)), UpdateActivePane(Some(Terminal(0)), 1), UpdateActivePane(Some(Terminal(0)), 1), Exit]
[SpawnTerminal(None, Some(false), None, ClientId(10)), UpdateActivePane(Some(Terminal(0)), 1), UpdateActivePane(Some(Terminal(0)), 1), Exit]

View File

@ -1,6 +1,6 @@
---
source: zellij-server/src/./unit/screen_tests.rs
assertion_line: 1863
assertion_line: 1869
expression: "format!(\"{:?}\", * received_pty_instructions.lock().unwrap())"
---
[SpawnTerminalVertically(None, 10), UpdateActivePane(Some(Terminal(0)), 1), UpdateActivePane(Some(Terminal(0)), 1), Exit]
[SpawnTerminalVertically(None, None, 10), UpdateActivePane(Some(Terminal(0)), 1), UpdateActivePane(Some(Terminal(0)), 1), Exit]

View File

@ -395,6 +395,7 @@ fn host_open_file(plugin_env: &PluginEnv) {
.send_to_pty(PtyInstruction::SpawnTerminal(
Some(TerminalAction::OpenFile(path, None)),
None,
None,
ClientOrTabIndex::TabIndex(plugin_env.tab_index),
))
.unwrap();

View File

@ -0,0 +1,4 @@
function zp () { zellij run --name "$*" -- bash -c "$*";} # zellij pane
function zpf () { zellij run --name "$*" --floating -- bash -c "$*";} # zellij pane floating
function zo () { zellij edit "$*";} # zellij open
function zof () { zellij edit --floating "$*";} # zellij open floating

View File

@ -6,3 +6,19 @@ complete -c zellij -n "__fish_seen_subcommand_from a" -f -a "(__fish_complete_se
complete -c zellij -n "__fish_seen_subcommand_from kill-session" -f -a "(__fish_complete_sessions)" -d "Session"
complete -c zellij -n "__fish_seen_subcommand_from k" -f -a "(__fish_complete_sessions)" -d "Session"
complete -c zellij -n "__fish_seen_subcommand_from setup" -l "generate-completion" -x -a "bash elvish fish zsh powershell" -d "Shell"
function zp
# zellij pane
command zellij run --name "$argv" -- fish -c "$argv"
end
function zpf
# zellij pane floating
command zellij run --name "$argv" --floating -- fish -c "$argv"
end
function zo
# zellij open
command zellij edit $argv
end
function zof
# zellij open floating
command zellij edit --floating $argv
end

View File

@ -0,0 +1,4 @@
function zp () { zellij run --name "$*" -- zsh -c "$*";} # zellij pane
function zpf () { zellij run --name "$*" --floating -- zsh -c "$*";} # zellij pane floating
function zo () { zellij edit "$*";} # zellij open
function zof () { zellij edit --floating "$*";} # zellij open floating

View File

@ -127,13 +127,16 @@ pub enum Sessions {
/// Run a command in a new pane
#[clap(visible_alias = "r")]
Run {
command: Option<String>,
#[clap(last(true), required(true))]
command: Vec<String>,
#[clap(short, long, value_parser, conflicts_with("floating"))]
direction: Option<Direction>,
#[clap(long, value_parser)]
cwd: Option<PathBuf>,
#[clap(short, long, value_parser, default_value("false"), takes_value(false))]
floating: bool,
#[clap(short, long, value_parser)]
name: Option<String>,
},
/// Edit file with default $EDITOR / $VISUAL
#[clap(visible_alias = "e")]
@ -206,12 +209,14 @@ pub enum CliAction {
NewPane {
#[clap(short, long, value_parser, conflicts_with("floating"))]
direction: Option<Direction>,
#[clap(short, long, value_parser)]
command: Option<String>,
#[clap(last(true))]
command: Vec<String>,
#[clap(long, value_parser)]
cwd: Option<PathBuf>,
#[clap(short, long, value_parser, default_value("false"), takes_value(false))]
floating: bool,
#[clap(short, long, value_parser)]
name: Option<String>,
},
/// Open the specified file in a new zellij pane with your default EDITOR
Edit {

View File

@ -109,37 +109,6 @@ impl FromStr for SearchOption {
}
}
fn split_escaped_whitespace(s: &str) -> Vec<String> {
s.split_ascii_whitespace()
.map(|s| String::from(s))
.fold(vec![], |mut acc, part| {
if let Some(previous_part) = acc.last_mut() {
if previous_part.ends_with('\\') {
previous_part.push(' ');
previous_part.push_str(&part);
return acc;
}
}
acc.push(part);
acc
})
}
fn split_command_and_args(command: String) -> (PathBuf, Vec<String>) {
let mut full_command = split_escaped_whitespace(&command);
let mut command = None;
let mut command_args = vec![];
for part in full_command.drain(..) {
if command.is_none() {
command = Some(part);
} else {
command_args.push(part);
}
}
let command = PathBuf::from(command.unwrap());
(command, command_args)
}
// As these actions are bound to the default config, please
// do take care when refactoring - or renaming.
// They might need to be adjusted in the default config
@ -198,13 +167,15 @@ pub enum Action {
ToggleActiveSyncTab,
/// Open a new pane in the specified direction (relative to focus).
/// If no direction is specified, will try to use the biggest available space.
NewPane(Option<Direction>),
NewPane(Option<Direction>, Option<String>), // String is an optional pane name
/// Open the file in a new pane using the default editor
EditFile(PathBuf, Option<usize>, Option<Direction>, bool), // usize is an optional line number, bool is floating true/false
/// Open a new floating pane
NewFloatingPane(Option<RunCommandAction>),
NewFloatingPane(Option<RunCommandAction>, Option<String>), // String is an optional pane name
/// Open a new tiled (embedded, non-floating) pane
NewTiledPane(Option<Direction>, Option<RunCommandAction>),
NewTiledPane(Option<Direction>, Option<RunCommandAction>, Option<String>), // String is an
// optional pane
// name
/// Embed focused pane in tab if floating or float focused pane if embedded
TogglePaneEmbedOrFloating,
/// Toggle the visibility of all floating panes (if any) in the current Tab
@ -285,9 +256,11 @@ impl Action {
command,
cwd,
floating,
} => match command {
Some(command) => {
let (command, args) = split_command_and_args(command);
name,
} => {
if !command.is_empty() {
let mut command = command.clone();
let (command, args) = (PathBuf::from(command.remove(0)), command);
let cwd = cwd.or_else(|| std::env::current_dir().ok());
let run_command_action = RunCommandAction {
command,
@ -297,21 +270,24 @@ impl Action {
hold_on_close: true,
};
if floating {
Ok(vec![Action::NewFloatingPane(Some(run_command_action))])
Ok(vec![Action::NewFloatingPane(
Some(run_command_action),
name,
)])
} else {
Ok(vec![Action::NewTiledPane(
direction,
Some(run_command_action),
name,
)])
}
},
None => {
} else {
if floating {
Ok(vec![Action::NewFloatingPane(None)])
Ok(vec![Action::NewFloatingPane(None, name)])
} else {
Ok(vec![Action::NewTiledPane(direction, None)])
Ok(vec![Action::NewTiledPane(direction, None, name)])
}
},
}
},
CliAction::Edit {
direction,

View File

@ -430,7 +430,7 @@ impl Action {
"DumpScreen" => Ok(Action::DumpScreen(string)),
"NewPane" => {
if string.is_empty() {
return Ok(Action::NewPane(None));
return Ok(Action::NewPane(None, None));
} else {
let direction = Direction::from_str(string.as_str()).map_err(|_| {
ConfigError::new_kdl_error(
@ -439,7 +439,7 @@ impl Action {
action_node.span().len(),
)
})?;
Ok(Action::NewPane(Some(direction)))
Ok(Action::NewPane(Some(direction), None))
}
},
"SearchToggleOption" => {

View File

@ -125,6 +125,18 @@ pub const FISH_EXTRA_COMPLETION: &[u8] = include_bytes!(concat!(
"assets/completions/comp.fish"
));
pub const BASH_EXTRA_COMPLETION: &[u8] = include_bytes!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/",
"assets/completions/comp.bash"
));
pub const ZSH_EXTRA_COMPLETION: &[u8] = include_bytes!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/",
"assets/completions/comp.zsh"
));
pub const BASH_AUTO_START_SCRIPT: &[u8] = include_bytes!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/",
@ -412,13 +424,17 @@ impl Setup {
clap_complete::generate(shell, &mut CliArgs::command(), "zellij", &mut out);
// add shell dependent extra completion
match shell {
Shell::Bash => {},
Shell::Bash => {
let _ = out.write_all(BASH_EXTRA_COMPLETION);
},
Shell::Elvish => {},
Shell::Fish => {
let _ = out.write_all(FISH_EXTRA_COMPLETION);
},
Shell::PowerShell => {},
Shell::Zsh => {},
Shell::Zsh => {
let _ = out.write_all(ZSH_EXTRA_COMPLETION);
},
_ => {},
};
}

View File

@ -1,6 +1,6 @@
---
source: zellij-utils/src/setup.rs
assertion_line: 491
assertion_line: 503
expression: "format!(\"{:#?}\", config)"
---
Config {
@ -76,6 +76,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -339,6 +340,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -498,6 +500,7 @@ Config {
Some(
Down,
),
None,
),
SwitchToMode(
Normal,
@ -552,6 +555,7 @@ Config {
): [
NewPane(
None,
None,
),
SwitchToMode(
Normal,
@ -569,6 +573,7 @@ Config {
Some(
Right,
),
None,
),
SwitchToMode(
Normal,
@ -668,6 +673,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -1019,6 +1025,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -1280,6 +1287,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -1481,6 +1489,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -1761,6 +1770,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -1962,6 +1972,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -2160,6 +2171,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -2363,6 +2375,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -2624,6 +2637,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -2819,6 +2833,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -2978,6 +2993,7 @@ Config {
Some(
Down,
),
None,
),
SwitchToMode(
Normal,
@ -2990,6 +3006,7 @@ Config {
Some(
Right,
),
None,
),
SwitchToMode(
Normal,
@ -3164,6 +3181,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(

View File

@ -1,6 +1,6 @@
---
source: zellij-utils/src/setup.rs
assertion_line: 541
assertion_line: 561
expression: "format!(\"{:#?}\", config)"
---
Config {
@ -76,6 +76,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -339,6 +340,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -498,6 +500,7 @@ Config {
Some(
Down,
),
None,
),
SwitchToMode(
Normal,
@ -552,6 +555,7 @@ Config {
): [
NewPane(
None,
None,
),
SwitchToMode(
Normal,
@ -569,6 +573,7 @@ Config {
Some(
Right,
),
None,
),
SwitchToMode(
Normal,
@ -668,6 +673,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -1019,6 +1025,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -1280,6 +1287,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -1481,6 +1489,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -1761,6 +1770,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -1962,6 +1972,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -2160,6 +2171,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -2363,6 +2375,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -2624,6 +2637,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -2819,6 +2833,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -2978,6 +2993,7 @@ Config {
Some(
Down,
),
None,
),
SwitchToMode(
Normal,
@ -2990,6 +3006,7 @@ Config {
Some(
Right,
),
None,
),
SwitchToMode(
Normal,
@ -3164,6 +3181,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(

View File

@ -1,6 +1,6 @@
---
source: zellij-utils/src/setup.rs
assertion_line: 557
assertion_line: 589
expression: "format!(\"{:#?}\", config)"
---
Config {
@ -76,6 +76,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -339,6 +340,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -498,6 +500,7 @@ Config {
Some(
Down,
),
None,
),
SwitchToMode(
Normal,
@ -552,6 +555,7 @@ Config {
): [
NewPane(
None,
None,
),
SwitchToMode(
Normal,
@ -569,6 +573,7 @@ Config {
Some(
Right,
),
None,
),
SwitchToMode(
Normal,
@ -668,6 +673,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -1019,6 +1025,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -1280,6 +1287,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -1481,6 +1489,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -1761,6 +1770,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -1962,6 +1972,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -2160,6 +2171,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -2363,6 +2375,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -2624,6 +2637,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -2819,6 +2833,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -2978,6 +2993,7 @@ Config {
Some(
Down,
),
None,
),
SwitchToMode(
Normal,
@ -2990,6 +3006,7 @@ Config {
Some(
Right,
),
None,
),
SwitchToMode(
Normal,
@ -3164,6 +3181,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(

View File

@ -1,6 +1,6 @@
---
source: zellij-utils/src/setup.rs
assertion_line: 565
assertion_line: 603
expression: "format!(\"{:#?}\", config)"
---
Config {
@ -76,6 +76,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -339,6 +340,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -498,6 +500,7 @@ Config {
Some(
Down,
),
None,
),
SwitchToMode(
Normal,
@ -552,6 +555,7 @@ Config {
): [
NewPane(
None,
None,
),
SwitchToMode(
Normal,
@ -569,6 +573,7 @@ Config {
Some(
Right,
),
None,
),
SwitchToMode(
Normal,
@ -668,6 +673,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -1019,6 +1025,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -1280,6 +1287,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -1481,6 +1489,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -1761,6 +1770,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -1962,6 +1972,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -2160,6 +2171,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -2363,6 +2375,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -2624,6 +2637,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -2819,6 +2833,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -2978,6 +2993,7 @@ Config {
Some(
Down,
),
None,
),
SwitchToMode(
Normal,
@ -2990,6 +3006,7 @@ Config {
Some(
Right,
),
None,
),
SwitchToMode(
Normal,
@ -3164,6 +3181,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(

View File

@ -1,6 +1,6 @@
---
source: zellij-utils/src/setup.rs
assertion_line: 549
assertion_line: 575
expression: "format!(\"{:#?}\", config)"
---
Config {
@ -76,6 +76,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -339,6 +340,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -498,6 +500,7 @@ Config {
Some(
Down,
),
None,
),
SwitchToMode(
Normal,
@ -552,6 +555,7 @@ Config {
): [
NewPane(
None,
None,
),
SwitchToMode(
Normal,
@ -569,6 +573,7 @@ Config {
Some(
Right,
),
None,
),
SwitchToMode(
Normal,
@ -668,6 +673,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -1019,6 +1025,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -1280,6 +1287,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -1481,6 +1489,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -1761,6 +1770,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -1962,6 +1972,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -2160,6 +2171,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -2363,6 +2375,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -2624,6 +2637,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -2819,6 +2833,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(
@ -2978,6 +2993,7 @@ Config {
Some(
Down,
),
None,
),
SwitchToMode(
Normal,
@ -2990,6 +3006,7 @@ Config {
Some(
Right,
),
None,
),
SwitchToMode(
Normal,
@ -3164,6 +3181,7 @@ Config {
): [
NewPane(
None,
None,
),
],
Alt(