diff options
author | Aram Drevekenin <aram@poor.dev> | 2022-10-17 19:39:37 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-17 19:39:37 +0200 |
commit | 271abb3ea2842cadc131ae91a3cd899e320e958e (patch) | |
tree | b20d4231f6d5b46737efe6b60b4e4e0170a87640 | |
parent | 4562982409cfcdfc151c5a4c2878d358dac9e76c (diff) |
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
30 files changed, 270 insertions, 121 deletions
diff --git a/default-plugins/status-bar/src/second_line.rs b/default-plugins/status-bar/src/second_line.rs index 8f0ff42a3..ccab42dff 100644 --- a/default-plugins/status-bar/src/second_line.rs +++ b/default-plugins/status-bar/src/second_line.rs @@ -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]), ], diff --git a/default-plugins/status-bar/src/tip/data/quicknav.rs b/default-plugins/status-bar/src/tip/data/quicknav.rs index 57d60a2d9..2e7cbec32 100644 --- a/default-plugins/status-bar/src/tip/data/quicknav.rs +++ b/default-plugins/status-bar/src/tip/data/quicknav.rs @@ -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 { diff --git a/src/main.rs b/src/main.rs index fa18f0900..3df61c42e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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); diff --git a/src/tests/e2e/remote_runner.rs b/src/tests/e2e/remote_runner.rs index b500149f5..dd2c800da 100644 --- a/src/tests/e2e/remote_runner.rs +++ b/src/tests/e2e/remote_runner.rs @@ -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(); } diff --git a/src/tests/e2e/snapshots/zellij__tests__e2e__cases__send_command_through_the_cli.snap b/src/tests/e2e/snapshots/zellij__tests__e2e__cases__send_command_through_the_cli.snap index 8f1e58ccc..84d33a037 100644 --- a/src/tests/e2e/snapshots/zellij__tests__e2e__cases__send_command_through_the_cli.snap +++ b/src/tests/e2e/snapshots/zellij__tests__e2e__cases__send_command_through_the_cli.snap @@ -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 │ │$ ││█ │ │ ││ │ │ ││ │ diff --git a/zellij-client/src/input_handler.rs b/zellij-client/src/input_handler.rs index 076ab35d6..a4c4988c9 100644 --- a/zellij-client/src/input_handler.rs +++ b/zellij-client/src/input_handler.rs @@ -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 diff --git a/zellij-server/src/panes/terminal_pane.rs b/zellij-server/src/panes/terminal_pane.rs index 95ddf9828..15e546f26 100644 --- a/zellij-server/src/panes/terminal_pane.rs +++ b/zellij-server/src/panes/terminal_pane.rs @@ -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 { diff --git a/zellij-server/src/pty.rs b/zellij-server/src/pty.rs index 9151c1a15..9fa8e1966 100644 --- a/zellij-server/src/pty.rs +++ b/zellij-server/src/pty.rs @@ -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) => { diff --git a/zellij-server/src/route.rs b/zellij-server/src/route.rs index fc8722b44..1fae23186 100644 --- a/zellij-server/src/route.rs +++ b/zellij-server/src/route.rs @@ -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), + |