diff --git a/CHANGELOG.md b/CHANGELOG.md index 4aba19c7e0..4602119f80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Added +* `--no-terminal-title/-n` CLI argument to disable automatic terminal title + ## [0.28.0] - 2025-12-14 **discard changes on checkout** diff --git a/src/args.rs b/src/args.rs index 22c6cc8d92..f9cb1e24d0 100644 --- a/src/args.rs +++ b/src/args.rs @@ -22,6 +22,7 @@ const GIT_DIR_FLAG_ID: &str = "directory"; const WATCHER_FLAG_ID: &str = "watcher"; const KEY_BINDINGS_FLAG_ID: &str = "key_bindings"; const KEY_SYMBOLS_FLAG_ID: &str = "key_symbols"; +const NO_TERMINAL_TITLE_FLAG_ID: &str = "no-terminal-title"; const DEFAULT_THEME: &str = "theme.ron"; const DEFAULT_GIT_DIR: &str = "."; @@ -33,6 +34,7 @@ pub struct CliArgs { pub notify_watcher: bool, pub key_bindings_path: Option, pub key_symbols_path: Option, + pub no_terminal_title: bool, } pub fn process_cmdline() -> Result { @@ -92,6 +94,9 @@ pub fn process_cmdline() -> Result { .get_one::(KEY_SYMBOLS_FLAG_ID) .map(PathBuf::from); + let no_terminal_title: bool = + *arg_matches.get_one(NO_TERMINAL_TITLE_FLAG_ID).unwrap_or(&false); + Ok(CliArgs { theme, select_file, @@ -99,6 +104,7 @@ pub fn process_cmdline() -> Result { notify_watcher, key_bindings_path, key_symbols_path, + no_terminal_title, }) } @@ -190,6 +196,13 @@ fn app() -> ClapApp { .env("GIT_WORK_TREE") .num_args(1), ) + .arg( + Arg::new(NO_TERMINAL_TITLE_FLAG_ID) + .help("Disable setting the terminal title") + .short('n') + .long("no-terminal-title") + .action(clap::ArgAction::SetTrue), + ) } fn setup_logging(path_override: Option) -> Result<()> { diff --git a/src/main.rs b/src/main.rs index 12fbb71ddd..1ff57f33fc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -186,7 +186,7 @@ fn main() -> Result<()> { set_panic_handler()?; let mut terminal = - start_terminal(io::stdout(), &cliargs.repo_path)?; + start_terminal(io::stdout(), &cliargs.repo_path, cliargs.no_terminal_title)?; let input = Input::new(); let updater = if cliargs.notify_watcher { @@ -217,6 +217,7 @@ fn main() -> Result<()> { notify_watcher: args.notify_watcher, key_bindings_path: args.key_bindings_path, key_symbols_path: args.key_symbols_path, + no_terminal_title: args.no_terminal_title, } } _ => break, @@ -417,6 +418,7 @@ fn select_event( fn start_terminal( buf: Stdout, repo_path: &RepoPath, + no_terminal_title: bool, ) -> Result { let mut path = repo_path.gitpath().canonicalize()?; let home = dirs::home_dir().ok_or_else(|| { @@ -430,10 +432,14 @@ fn start_terminal( } let mut backend = CrosstermBackend::new(buf); - backend.execute(crossterm::terminal::SetTitle(format!( - "gitui ({})", - path.display() - )))?; + + // Conditionally set terminal title + if !no_terminal_title { + backend.execute(crossterm::terminal::SetTitle(format!( + "gitui ({})", + path.display() + )))?; + } let mut terminal = Terminal::new(backend)?; terminal.hide_cursor()?;