1
1
mirror of https://github.com/wez/wezterm.git synced 2025-01-04 19:54:56 +03:00

Spawn new tabs using the current tab's current directory

(If known.)
This commit is contained in:
Jeremy Fitzhardinge 2020-01-10 23:18:59 -08:00 committed by Wez Furlong
parent 71eb27ccb5
commit 83641ed46c
8 changed files with 45 additions and 18 deletions

View File

@ -1028,24 +1028,37 @@ impl TermWindow {
let size = self.terminal_size;
let mux = Mux::get().unwrap();
let domain = match domain {
SpawnTabDomain::DefaultDomain => mux.default_domain().clone(),
let (domain, cwd) = match domain {
SpawnTabDomain::DefaultDomain => {
let cwd = mux
.get_active_tab_for_window(self.mux_window_id)
.and_then(|tab| tab.get_current_working_dir());
(mux.default_domain().clone(), cwd)
}
SpawnTabDomain::CurrentTabDomain => {
let tab = match mux.get_active_tab_for_window(self.mux_window_id) {
Some(tab) => tab,
None => bail!("window has no tabs?"),
};
mux.get_domain(tab.domain_id())
.ok_or_else(|| anyhow!("current tab has unresolvable domain id!?"))?
(
mux.get_domain(tab.domain_id())
.ok_or_else(|| anyhow!("current tab has unresolvable domain id!?"))?,
tab.get_current_working_dir(),
)
}
SpawnTabDomain::Domain(id) => mux
.get_domain(*id)
.ok_or_else(|| anyhow!("spawn_tab called with unresolvable domain id!?"))?,
SpawnTabDomain::DomainName(name) => mux.get_domain_by_name(&name).ok_or_else(|| {
anyhow!("spawn_tab called with unresolvable domain name {}", name)
})?,
SpawnTabDomain::Domain(id) => (
mux.get_domain(*id)
.ok_or_else(|| anyhow!("spawn_tab called with unresolvable domain id!?"))?,
None,
),
SpawnTabDomain::DomainName(name) => (
mux.get_domain_by_name(&name).ok_or_else(|| {
anyhow!("spawn_tab called with unresolvable domain name {}", name)
})?,
None,
),
};
let tab = domain.spawn(size, None, self.mux_window_id)?;
let tab = domain.spawn(size, None, cwd, self.mux_window_id)?;
let tab_id = tab.tab_id();
let clipboard: Arc<dyn term::Clipboard> = Arc::new(ClipboardHelper {
@ -1166,7 +1179,7 @@ impl TermWindow {
let window_id = mux.new_empty_window();
let tab = mux
.default_domain()
.spawn(PtySize::default(), None, window_id)?;
.spawn(PtySize::default(), None, None, window_id)?;
let front_end = front_end().expect("to be called on gui thread");
front_end.spawn_new_window(&fonts, &tab, window_id)?;
Ok(())

View File

@ -373,7 +373,7 @@ async fn async_run_ssh(opts: SshCommand, params: SshParameters) -> anyhow::Resul
domain.attach().await?;
let window_id = mux.new_empty_window();
let tab = domain.spawn(PtySize::default(), cmd, window_id)?;
let tab = domain.spawn(PtySize::default(), cmd, None, window_id)?;
let fontconfig = Rc::new(FontConfiguration::new());
gui.spawn_new_window(&fontconfig, &tab, window_id)?;
@ -429,7 +429,7 @@ fn run_serial(config: config::ConfigHandle, opts: &SerialCommand) -> anyhow::Res
domain.attach().wait()?;
let window_id = mux.new_empty_window();
let tab = domain.spawn(PtySize::default(), None, window_id)?;
let tab = domain.spawn(PtySize::default(), None, None, window_id)?;
gui.spawn_new_window(&fontconfig, &tab, window_id)?;
gui.run_forever()
@ -506,7 +506,7 @@ async fn spawn_tab_in_default_domain_if_mux_is_empty(
let tab = mux
.default_domain()
.spawn(PtySize::default(), cmd, window_id)?;
.spawn(PtySize::default(), cmd, None, window_id)?;
let fontconfig = Rc::new(FontConfiguration::new());
front_end()
.unwrap()

View File

@ -37,6 +37,7 @@ pub trait Domain: Downcast {
&self,
size: PtySize,
command: Option<CommandBuilder>,
command_dir: Option<String>,
window: WindowId,
) -> Result<Rc<dyn Tab>, Error>;
@ -85,13 +86,17 @@ impl Domain for LocalDomain {
&self,
size: PtySize,
command: Option<CommandBuilder>,
command_dir: Option<String>,
window: WindowId,
) -> Result<Rc<dyn Tab>, Error> {
let config = configuration();
let cmd = match command {
let mut cmd = match command {
Some(c) => c,
None => config.build_prog(None)?,
};
if let Some(dir) = command_dir {
cmd.cwd(dir);
}
let pair = self.pty_system.openpty(size)?;
let child = pair.slave.spawn_command(cmd)?;
info!("spawned: {:?}", child);

View File

@ -368,6 +368,7 @@ pub struct Spawn {
/// If None, create a new window for this new tab
pub window_id: Option<WindowId>,
pub command: Option<CommandBuilder>,
pub command_dir: Option<String>,
pub size: PtySize,
}

View File

@ -213,6 +213,7 @@ impl Domain for ClientDomain {
&self,
size: PtySize,
command: Option<CommandBuilder>,
command_dir: Option<String>,
window: WindowId,
) -> anyhow::Result<Rc<dyn Tab>> {
let inner = self
@ -226,6 +227,7 @@ impl Domain for ClientDomain {
window_id: inner.local_to_remote_window(window),
size,
command,
command_dir,
})
.wait()?;

View File

@ -750,7 +750,8 @@ impl<S: ReadAndWrite> ClientSession<S> {
mux.new_empty_window()
};
let tab = domain.spawn(spawn.size, spawn.command, window_id)?;
let tab =
domain.spawn(spawn.size, spawn.command, spawn.command_dir, window_id)?;
let clip: Arc<dyn Clipboard> = Arc::new(RemoteClipboard {
tab_id: tab.tab_id(),

View File

@ -338,12 +338,16 @@ impl Domain for RemoteSshDomain {
&self,
size: PtySize,
command: Option<CommandBuilder>,
command_dir: Option<String>,
window: WindowId,
) -> Result<Rc<dyn Tab>, Error> {
let cmd = match command {
let mut cmd = match command {
Some(c) => c,
None => CommandBuilder::new_default_prog(),
};
if let Some(dir) = command_dir {
cmd.cwd(dir);
}
let pair = self.pty_system.openpty(size)?;
let child = pair.slave.spawn_command(cmd)?;
log::info!("spawned: {:?}", child);

View File

@ -151,6 +151,7 @@ impl Domain for TermWizTerminalDomain {
&self,
_size: PtySize,
_command: Option<CommandBuilder>,
_command_dir: Option<String>,
_window: WindowId,
) -> anyhow::Result<Rc<dyn Tab>> {
bail!("cannot spawn tabs in a TermWizTerminalTab");