Skip to content

Commit b4b67cc

Browse files
committed
enh: display home-relative directory paths on Unix based systems (~/dir)
Signed-off-by: Saurabh Kumar <[email protected]>
1 parent 1458b68 commit b4b67cc

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

crates/deno_task_shell/src/shell/types.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use std::collections::HashMap;
66
use std::fmt;
77
use std::fmt::Display;
88
use std::fs;
9-
use std::io::IsTerminal as _;
109
use std::io::Read;
1110
use std::io::Write;
1211
use std::path::Path;
@@ -54,16 +53,6 @@ pub struct ShellState {
5453
shell_options: HashMap<ShellOptions, bool>,
5554
}
5655

57-
#[allow(clippy::print_stdout)]
58-
pub fn set_terminal_title(title: &str) {
59-
// Only set title if we're in an interactive terminal session
60-
if std::io::stdout().is_terminal() {
61-
// OSC 0 ; title BEL - works in most terminals
62-
print!("\x1B]0;{}\x07", title);
63-
// Ensure it's displayed immediately
64-
let _ = std::io::stdout().flush();
65-
}
66-
}
6756

6857
impl ShellState {
6958
pub fn new(
@@ -186,7 +175,6 @@ impl ShellState {
186175
self.previous_cwd = Some(self.cwd.clone());
187176
self.cwd = cwd.to_path_buf();
188177

189-
set_terminal_title(&format!("{} - shell", self.cwd.to_string_lossy(),));
190178
// $PWD holds the current working directory, so we keep cwd and $PWD in sync
191179
self.env_vars
192180
.insert("PWD".to_string(), self.cwd.display().to_string());

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)