New tab opens on current directory

This patch add a new feature, now tab behavior now inherits the
active tab’s current directory on Linux controlled by a settings
toggle, and default is off
This commit is contained in:
Nicolas Danelon 2026-03-06 13:53:46 +01:00
parent 7ce2974273
commit 75714dedee
4 changed files with 81 additions and 15 deletions

View file

@ -28,7 +28,8 @@ use indexmap::IndexSet;
use std::{
borrow::Cow,
collections::HashMap,
io, mem,
fs, io, mem,
path::PathBuf,
sync::{
Arc, Mutex, Weak,
atomic::{AtomicU32, Ordering},
@ -257,6 +258,7 @@ pub struct Terminal {
notifier: Notifier,
search_regex_opt: Option<RegexSearch>,
search_value: String,
shell_pid: Option<u32>,
size: Size,
use_bright_bold: bool,
zoom_adj: i8,
@ -328,6 +330,10 @@ impl Terminal {
let window_id = 0;
let pty = tty::new(&options, size.into(), window_id)?;
#[cfg(not(windows))]
let shell_pid = Some(pty.child().id());
#[cfg(windows)]
let shell_pid = pty.child_watcher().pid().map(|pid| pid.get());
let pty_event_loop =
EventLoop::new(term.clone(), event_proxy, pty, options.drain_on_exit, false)?;
@ -352,6 +358,7 @@ impl Terminal {
profile_id_opt,
search_regex_opt: None,
search_value: String::new(),
shell_pid,
size,
tab_title_override,
term,
@ -407,6 +414,18 @@ impl Terminal {
self.notifier.notify(input);
}
pub fn working_directory(&self) -> Option<PathBuf> {
#[cfg(not(windows))]
{
let shell_pid = self.shell_pid?;
fs::read_link(format!("/proc/{shell_pid}/cwd")).ok()
}
#[cfg(windows)]
{
None
}
}
pub fn input_scroll<I: Into<Cow<'static, [u8]>>>(&self, input: I) {
self.input_no_scroll(input);
self.scroll(TerminalScroll::Bottom);