fix(cwd): open pane in cwd even if default shell is explicit (#834)
* fix(cwd): open pane in cwd even if default shell is explicit * style(fmt): make rustfmt happy
This commit is contained in:
parent
a83a8b9a96
commit
daa70022c9
1 changed files with 33 additions and 18 deletions
|
|
@ -267,36 +267,51 @@ impl Pty {
|
||||||
task_handles: HashMap::new(),
|
task_handles: HashMap::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn get_default_terminal(&self, client_id: Option<ClientId>) -> TerminalAction {
|
pub fn get_default_terminal(&self) -> TerminalAction {
|
||||||
TerminalAction::RunCommand(RunCommand {
|
TerminalAction::RunCommand(RunCommand {
|
||||||
args: vec![],
|
args: vec![],
|
||||||
command: PathBuf::from(env::var("SHELL").expect("Could not find the SHELL variable")),
|
command: PathBuf::from(env::var("SHELL").expect("Could not find the SHELL variable")),
|
||||||
cwd: client_id
|
cwd: None, // this should be filled by the calling function, eg. spawn_terminal
|
||||||
.and_then(|client_id| self.active_panes.get(&client_id))
|
|
||||||
.and_then(|pane| match pane {
|
|
||||||
PaneId::Plugin(..) => None,
|
|
||||||
PaneId::Terminal(id) => self.id_to_child_pid.get(id),
|
|
||||||
})
|
|
||||||
.and_then(|id| {
|
|
||||||
self.bus
|
|
||||||
.os_input
|
|
||||||
.as_ref()
|
|
||||||
.map(|input| input.get_cwd(Pid::from_raw(*id)))
|
|
||||||
})
|
|
||||||
.flatten(),
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
fn fill_cwd(&self, terminal_action: &mut TerminalAction, client_id: ClientId) {
|
||||||
|
if let TerminalAction::RunCommand(run_command) = terminal_action {
|
||||||
|
if run_command.cwd.is_none() {
|
||||||
|
run_command.cwd = self
|
||||||
|
.active_panes
|
||||||
|
.get(&client_id)
|
||||||
|
.and_then(|pane| match pane {
|
||||||
|
PaneId::Plugin(..) => None,
|
||||||
|
PaneId::Terminal(id) => self.id_to_child_pid.get(id),
|
||||||
|
})
|
||||||
|
.and_then(|id| {
|
||||||
|
self.bus
|
||||||
|
.os_input
|
||||||
|
.as_ref()
|
||||||
|
.map(|input| input.get_cwd(Pid::from_raw(*id)))
|
||||||
|
})
|
||||||
|
.flatten();
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
pub fn spawn_terminal(
|
pub fn spawn_terminal(
|
||||||
&mut self,
|
&mut self,
|
||||||
terminal_action: Option<TerminalAction>,
|
terminal_action: Option<TerminalAction>,
|
||||||
client_or_tab_index: ClientOrTabIndex,
|
client_or_tab_index: ClientOrTabIndex,
|
||||||
) -> RawFd {
|
) -> RawFd {
|
||||||
|
log::info!(
|
||||||
|
"spawn_terminal, client_or_tab_index: {:?}",
|
||||||
|
client_or_tab_index
|
||||||
|
);
|
||||||
let terminal_action = match client_or_tab_index {
|
let terminal_action = match client_or_tab_index {
|
||||||
ClientOrTabIndex::ClientId(client_id) => {
|
ClientOrTabIndex::ClientId(client_id) => {
|
||||||
terminal_action.unwrap_or_else(|| self.get_default_terminal(Some(client_id)))
|
let mut terminal_action =
|
||||||
|
terminal_action.unwrap_or_else(|| self.get_default_terminal());
|
||||||
|
self.fill_cwd(&mut terminal_action, client_id);
|
||||||
|
terminal_action
|
||||||
}
|
}
|
||||||
ClientOrTabIndex::TabIndex(_) => {
|
ClientOrTabIndex::TabIndex(_) => {
|
||||||
terminal_action.unwrap_or_else(|| self.get_default_terminal(None))
|
terminal_action.unwrap_or_else(|| self.get_default_terminal())
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let quit_cb = Box::new({
|
let quit_cb = Box::new({
|
||||||
|
|
@ -327,8 +342,8 @@ impl Pty {
|
||||||
default_shell: Option<TerminalAction>,
|
default_shell: Option<TerminalAction>,
|
||||||
client_id: ClientId,
|
client_id: ClientId,
|
||||||
) {
|
) {
|
||||||
let default_shell =
|
let mut default_shell = default_shell.unwrap_or_else(|| self.get_default_terminal());
|
||||||
default_shell.unwrap_or_else(|| self.get_default_terminal(Some(client_id)));
|
self.fill_cwd(&mut default_shell, client_id);
|
||||||
let extracted_run_instructions = layout.extract_run_instructions();
|
let extracted_run_instructions = layout.extract_run_instructions();
|
||||||
let mut new_pane_pids = vec![];
|
let mut new_pane_pids = vec![];
|
||||||
for run_instruction in extracted_run_instructions {
|
for run_instruction in extracted_run_instructions {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue