feat(panes): reuse CWD when dropping to shell in command panes (#2915)

This commit is contained in:
Diego Alonso 2023-11-09 10:45:48 +01:00 committed by GitHub
parent 83cf6d6e7c
commit 261c75ab92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 12 deletions

View File

@ -196,11 +196,13 @@ impl Pane for TerminalPane {
Some(AdjustedInput::ReRunCommandInThisPane(run_command))
},
ESC => {
// Drop to shell in the same working directory as the command was run
let working_dir = run_command.cwd.clone();
self.is_held = None;
self.grid.reset_terminal_state();
self.set_should_render(true);
self.remove_banner();
Some(AdjustedInput::DropToShellInThisPane)
Some(AdjustedInput::DropToShellInThisPane { working_dir })
},
CTRL_C => Some(AdjustedInput::CloseThisPane),
_ => None,

View File

@ -67,7 +67,11 @@ pub enum PtyInstruction {
ClosePane(PaneId),
CloseTab(Vec<PaneId>),
ReRunCommandInPane(PaneId, RunCommand),
DropToShellInPane(PaneId, Option<PathBuf>), // Option<PathBuf> - default shell
DropToShellInPane {
pane_id: PaneId,
shell: Option<PathBuf>,
working_dir: Option<PathBuf>,
},
SpawnInPlaceTerminal(
Option<TerminalAction>,
Option<String>,
@ -101,7 +105,7 @@ impl From<&PtyInstruction> for PtyContext {
PtyInstruction::CloseTab(_) => PtyContext::CloseTab,
PtyInstruction::NewTab(..) => PtyContext::NewTab,
PtyInstruction::ReRunCommandInPane(..) => PtyContext::ReRunCommandInPane,
PtyInstruction::DropToShellInPane(..) => PtyContext::DropToShellInPane,
PtyInstruction::DropToShellInPane { .. } => PtyContext::DropToShellInPane,
PtyInstruction::SpawnInPlaceTerminal(..) => PtyContext::SpawnInPlaceTerminal,
PtyInstruction::DumpLayout(..) => PtyContext::DumpLayout,
PtyInstruction::LogLayoutToHd(..) => PtyContext::LogLayoutToHd,
@ -546,17 +550,21 @@ pub(crate) fn pty_thread_main(mut pty: Pty, layout: Box<Layout>) -> Result<()> {
},
}
},
PtyInstruction::DropToShellInPane(pane_id, default_shell) => {
PtyInstruction::DropToShellInPane {
pane_id,
shell,
working_dir,
} => {
let err_context = || format!("failed to rerun command in pane {:?}", pane_id);
// TODO: get configured default_shell from screen/tab as an option and default to
// this otherwise (also look for a place that turns get_default_shell into a
// RunCommand, we might have done this before)
let run_command = RunCommand {
command: default_shell.unwrap_or_else(|| get_default_shell()),
command: shell.unwrap_or_else(|| get_default_shell()),
hold_on_close: false,
hold_on_start: false,
// TODO: cwd
cwd: working_dir,
..Default::default()
};
match pty

View File

@ -486,7 +486,7 @@ pub enum AdjustedInput {
ReRunCommandInThisPane(RunCommand),
PermissionRequestResult(Vec<PermissionType>, PermissionStatus),
CloseThisPane,
DropToShellInThisPane,
DropToShellInThisPane { working_dir: Option<PathBuf> },
}
pub fn get_next_terminal_position(
tiled_panes: &TiledPanes,
@ -1736,13 +1736,14 @@ impl Tab {
self.close_pane(PaneId::Terminal(active_terminal_id), false, None);
should_update_ui = true;
},
Some(AdjustedInput::DropToShellInThisPane) => {
Some(AdjustedInput::DropToShellInThisPane { working_dir }) => {
self.pids_waiting_resize.insert(active_terminal_id);
self.senders
.send_to_pty(PtyInstruction::DropToShellInPane(
PaneId::Terminal(active_terminal_id),
self.default_shell.clone(),
))
.send_to_pty(PtyInstruction::DropToShellInPane {
pane_id: PaneId::Terminal(active_terminal_id),
shell: self.default_shell.clone(),
working_dir,
})
.with_context(err_context)?;
should_update_ui = true;
},