Skip to content

Commit e3a8414

Browse files
committed
enh: display directory base name as terminal title on Unix based systems (~/dir)
Signed-off-by: Saurabh Kumar <developer.saurabh@outlook.com>
1 parent 7a197ad commit e3a8414

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

crates/deno_task_shell/src/shell/types.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ pub struct ShellState {
5858
pub fn set_terminal_title(title: &str) {
5959
// Only set title if we're in an interactive terminal session
6060
if std::io::stdout().is_terminal() {
61+
let title = title.replace('\\', "/");
62+
let title = if cfg!(unix) {
63+
Path::new(&title).file_name().unwrap().to_str().unwrap()
64+
} else {
65+
&title
66+
};
6167
// OSC 0 ; title BEL - works in most terminals
6268
print!("\x1B]0;{}\x07", title);
6369
// Ensure it's displayed immediately

crates/shell/src/main.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,17 @@ async fn interactive(state: Option<ShellState>, norc: bool, args: &[String]) ->
157157
}
158158

159159
let mut display_cwd = if let Some(stripped) = cwd.strip_prefix(home_str) {
160-
format!("~{}", stripped.replace('\\', "/"))
160+
if cfg!(unix) {
161+
format!(
162+
"~/{}",
163+
PathBuf::from(stripped.replace('\\', "/"))
164+
.file_name()
165+
.unwrap_or_default()
166+
.to_string_lossy()
167+
)
168+
} else {
169+
format!("~{}", stripped.replace('\\', "/"))
170+
}
161171
} else {
162172
cwd.to_string()
163173
};

0 commit comments

Comments
 (0)