Skip to content

Commit 3533ac2

Browse files
chriszaratesxyazi
andauthored
feat: add title_format manager config option (#1281)
Co-authored-by: sxyazi <sxyazi@gmail.com>
1 parent 9b7821a commit 3533ac2

4 files changed

Lines changed: 18 additions & 6 deletions

File tree

yazi-config/preset/yazi.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ show_hidden = false
1414
show_symlink = true
1515
scrolloff = 5
1616
mouse_events = [ "click", "scroll" ]
17+
title_format = "Yazi: {cwd}"
1718

1819
[preview]
1920
tab_size = 2

yazi-config/src/manager/manager.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub struct Manager {
2323
pub show_symlink: bool,
2424
pub scrolloff: u8,
2525
pub mouse_events: MouseEvents,
26+
pub title_format: String,
2627
}
2728

2829
impl FromStr for Manager {

yazi-core/src/manager/commands/refresh.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
11
use std::{env, path::MAIN_SEPARATOR};
22

33
use crossterm::{execute, terminal::SetTitle};
4+
use yazi_config::MANAGER;
45
use yazi_shared::event::Cmd;
56

67
use crate::{manager::Manager, tasks::Tasks};
78

89
impl Manager {
910
fn title(&self) -> String {
1011
let home = dirs::home_dir().unwrap_or_default();
11-
if let Some(p) = self.cwd().strip_prefix(home) {
12-
format!("Yazi: ~{}{}", MAIN_SEPARATOR, p.display())
12+
let cwd = if let Some(p) = self.cwd().strip_prefix(home) {
13+
format!("~{}{}", MAIN_SEPARATOR, p.display())
1314
} else {
14-
format!("Yazi: {}", self.cwd().display())
15-
}
15+
format!("{}", self.cwd().display())
16+
};
17+
18+
MANAGER.title_format.replace("{cwd}", &cwd)
1619
}
1720

1821
pub fn refresh(&mut self, _: Cmd, tasks: &Tasks) {
1922
env::set_current_dir(self.cwd()).ok();
2023
env::set_var("PWD", self.cwd());
21-
execute!(std::io::stderr(), SetTitle(self.title())).ok();
24+
25+
if !MANAGER.title_format.is_empty() {
26+
execute!(std::io::stderr(), SetTitle(self.title())).ok();
27+
}
2228

2329
self.active_mut().apply_files_attrs();
2430

yazi-fm/src/term.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crossterm::{event::{DisableBracketedPaste, EnableBracketedPaste, KeyboardEnh
55
use cursor::RestoreCursor;
66
use ratatui::{backend::CrosstermBackend, buffer::Buffer, layout::Rect, CompletedFrame, Frame, Terminal};
77
use yazi_adapter::Emulator;
8-
use yazi_config::INPUT;
8+
use yazi_config::{INPUT, MANAGER};
99

1010
static CSI_U: AtomicBool = AtomicBool::new(false);
1111
static BLINK: AtomicBool = AtomicBool::new(false);
@@ -85,6 +85,10 @@ impl Term {
8585
execute!(stderr(), PopKeyboardEnhancementFlags).ok();
8686
}
8787

88+
if !MANAGER.title_format.is_empty() {
89+
execute!(stderr(), SetTitle("")).ok();
90+
}
91+
8892
execute!(
8993
stderr(),
9094
mouse::SetMouse(false),

0 commit comments

Comments
 (0)