From 1bf40a8cc77d9082dfb76e028e0f66af88d79958 Mon Sep 17 00:00:00 2001 From: Rohan Poojary Date: Sun, 6 Sep 2020 21:08:49 +0530 Subject: [PATCH] Pass existing CLI parameters to SpawnNewInstance Co-authored-by: Christian Duerr --- CHANGELOG.md | 1 + alacritty/src/event.rs | 22 +++++++++++++++++++--- alacritty_terminal/src/term/mod.rs | 2 +- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e84ec91..b8e4b224 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Fallback to normal underline for unsupported underline types in `CSI 4 : ? m` escapes - The user's background color is now used as the foreground for the render timer - Use yellow/red from the config for error and warning messages instead of fixed colors +- Existing CLI parameters are now passed to instances spawned using `SpawnNewInstance` ### Fixed diff --git a/alacritty/src/event.rs b/alacritty/src/event.rs index c3e1b6c8..e81dc0f9 100644 --- a/alacritty/src/event.rs +++ b/alacritty/src/event.rs @@ -299,10 +299,11 @@ impl<'a, N: Notify + 'a, T: EventListener> input::ActionContext for ActionCon } fn spawn_new_instance(&mut self) { - let alacritty = env::args().next().unwrap(); + let mut env_args = env::args(); + let alacritty = env_args.next().unwrap(); #[cfg(unix)] - let args = { + let mut args = { // Use working directory of controlling process, or fallback to initial shell. let mut pid = unsafe { libc::tcgetpgrp(tty::master_fd()) }; if pid < 0 { @@ -314,12 +315,27 @@ impl<'a, N: Notify + 'a, T: EventListener> input::ActionContext for ActionCon #[cfg(target_os = "freebsd")] let link_path = format!("/compat/linux/proc/{}/cwd", pid); + // Add the current working directory as parameter. fs::read_link(link_path) .map(|path| vec!["--working-directory".into(), path]) .unwrap_or_default() }; + #[cfg(not(unix))] - let args: Vec = Vec::new(); + let mut args: Vec = Vec::new(); + + let working_directory_set = !args.is_empty(); + + // Reuse the arguments passed to Alacritty for the new instance. + while let Some(arg) = env_args.next() { + // Drop working directory from existing parameters. + if working_directory_set && arg == "--working-directory" { + let _ = env_args.next(); + continue; + } + + args.push(arg.into()); + } start_daemon(&alacritty, &args); } diff --git a/alacritty_terminal/src/term/mod.rs b/alacritty_terminal/src/term/mod.rs index 15499e07..d61cf7e3 100644 --- a/alacritty_terminal/src/term/mod.rs +++ b/alacritty_terminal/src/term/mod.rs @@ -2823,7 +2823,7 @@ mod benches { let config = MockConfig::default(); - let mut terminal = Term::new(&config, &size, Mock); + let mut terminal = Term::new(&config, size, Mock); mem::swap(&mut terminal.grid, &mut grid); b.iter(|| {