From 8dda1258c15a989bb7861938babf82dcd1671298 Mon Sep 17 00:00:00 2001 From: Lena <126529524+acuteenvy@users.noreply.github.com> Date: Wed, 15 Jan 2025 22:31:11 +0100 Subject: [PATCH 1/2] Set the terminal title to `gitui ({repo_path})` --- src/main.rs | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index e85dca8530..3149bd8d9c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -47,7 +47,7 @@ mod ui; mod watcher; use crate::{app::App, args::process_cmdline}; -use anyhow::{bail, Result}; +use anyhow::{anyhow, bail, Result}; use app::QuitState; use asyncgit::{ sync::{utils::repo_work_dir, RepoPath}, @@ -71,7 +71,9 @@ use spinner::Spinner; use std::{ cell::RefCell, io::{self, Stdout}, - panic, process, + panic, + path::Path, + process, time::{Duration, Instant}, }; use ui::style::Theme; @@ -142,8 +144,8 @@ fn main() -> Result<()> { set_panic_handlers()?; - let mut terminal = start_terminal(io::stdout())?; let mut repo_path = cliargs.repo_path; + let mut terminal = start_terminal(io::stdout(), &repo_path)?; let input = Input::new(); let updater = if cliargs.notify_watcher { @@ -359,8 +361,27 @@ fn select_event( Ok(ev) } -fn start_terminal(buf: Stdout) -> io::Result { - let backend = CrosstermBackend::new(buf); +fn start_terminal( + buf: Stdout, + repo_path: &RepoPath, +) -> Result { + let mut path = repo_path.gitpath().canonicalize()?; + let home = dirs::home_dir().ok_or_else(|| { + anyhow!("failed to find the home directory") + })?; + if path.starts_with(&home) { + let relative_part = path + .strip_prefix(&home) + .expect("can't fail because of the if statement"); + path = Path::new("~").join(relative_part); + } + + let mut backend = CrosstermBackend::new(buf); + backend.execute(crossterm::terminal::SetTitle(format!( + "gitui ({})", + path.display() + )))?; + let mut terminal = Terminal::new(backend)?; terminal.hide_cursor()?; terminal.clear()?; From d7594d5ce95f61d1fde101da0660495fbcbdd6d5 Mon Sep 17 00:00:00 2001 From: Lena <126529524+acuteenvy@users.noreply.github.com> Date: Wed, 15 Jan 2025 22:45:12 +0100 Subject: [PATCH 2/2] Update the changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 05823362cf..c3b24b3e52 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 +* set the terminal title to `gitui ({repo_path})` [[@acuteenvy](https://github.com/acuteenvy)] ([#2462](https://github.com/extrawurst/gitui/issues/2462)) + ## [0.27.0] - 2024-01-14 **new: manage remotes**