From e3a84140af7420c184bf9a6d43ac5aedfac5c020 Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Date: Tue, 11 Nov 2025 20:12:10 +0530 Subject: [PATCH] enh: display directory base name as terminal title on Unix based systems (`~/dir`) Signed-off-by: Saurabh Kumar --- crates/deno_task_shell/src/shell/types.rs | 6 ++++++ crates/shell/src/main.rs | 12 +++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/crates/deno_task_shell/src/shell/types.rs b/crates/deno_task_shell/src/shell/types.rs index aa4eb95..28c674a 100644 --- a/crates/deno_task_shell/src/shell/types.rs +++ b/crates/deno_task_shell/src/shell/types.rs @@ -58,6 +58,12 @@ pub struct ShellState { pub fn set_terminal_title(title: &str) { // Only set title if we're in an interactive terminal session if std::io::stdout().is_terminal() { + let title = title.replace('\\', "/"); + let title = if cfg!(unix) { + Path::new(&title).file_name().unwrap().to_str().unwrap() + } else { + &title + }; // OSC 0 ; title BEL - works in most terminals print!("\x1B]0;{}\x07", title); // Ensure it's displayed immediately diff --git a/crates/shell/src/main.rs b/crates/shell/src/main.rs index 336fa86..d2fad7a 100644 --- a/crates/shell/src/main.rs +++ b/crates/shell/src/main.rs @@ -157,7 +157,17 @@ async fn interactive(state: Option, norc: bool, args: &[String]) -> } let mut display_cwd = if let Some(stripped) = cwd.strip_prefix(home_str) { - format!("~{}", stripped.replace('\\', "/")) + if cfg!(unix) { + format!( + "~/{}", + PathBuf::from(stripped.replace('\\', "/")) + .file_name() + .unwrap_or_default() + .to_string_lossy() + ) + } else { + format!("~{}", stripped.replace('\\', "/")) + } } else { cwd.to_string() };