Skip to content

Commit 3ede6b5

Browse files
authored
Set the terminal title to gitui ({repo_path}) (#2484)
1 parent 5755c09 commit 3ede6b5

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818
* The default key to close the commit error message popup is now the Escape key [[@wessamfathi](https://github.com/wessamfathi)] ([#2552](https://github.com/extrawurst/gitui/issues/2552))
1919
* use OSC52 copying in case other methods fail [[@naseschwarz](https://github.com/naseschwarz)] ([#2366](https://github.com/gitui-org/gitui/issues/2366))
2020
* push: respect `branch.*.merge` when push default is upstream [[@vlad-anger](https://github.com/vlad-anger)] ([#2542](https://github.com/gitui-org/gitui/pull/2542))
21+
* set the terminal title to `gitui ({repo_path})` [[@acuteenvy](https://github.com/acuteenvy)] ([#2462](https://github.com/gitui-org/gitui/issues/2462))
2122

2223
## [0.27.0] - 2024-01-14
2324

src/main.rs

+26-5
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ mod ui;
4747
mod watcher;
4848

4949
use crate::{app::App, args::process_cmdline};
50-
use anyhow::{bail, Result};
50+
use anyhow::{anyhow, bail, Result};
5151
use app::QuitState;
5252
use asyncgit::{
5353
sync::{utils::repo_work_dir, RepoPath},
@@ -71,7 +71,9 @@ use spinner::Spinner;
7171
use std::{
7272
cell::RefCell,
7373
io::{self, Stdout},
74-
panic, process,
74+
panic,
75+
path::Path,
76+
process,
7577
time::{Duration, Instant},
7678
};
7779
use ui::style::Theme;
@@ -142,8 +144,8 @@ fn main() -> Result<()> {
142144

143145
set_panic_handlers()?;
144146

145-
let mut terminal = start_terminal(io::stdout())?;
146147
let mut repo_path = cliargs.repo_path;
148+
let mut terminal = start_terminal(io::stdout(), &repo_path)?;
147149
let input = Input::new();
148150

149151
let updater = if cliargs.notify_watcher {
@@ -359,8 +361,27 @@ fn select_event(
359361
Ok(ev)
360362
}
361363

362-
fn start_terminal(buf: Stdout) -> io::Result<Terminal> {
363-
let backend = CrosstermBackend::new(buf);
364+
fn start_terminal(
365+
buf: Stdout,
366+
repo_path: &RepoPath,
367+
) -> Result<Terminal> {
368+
let mut path = repo_path.gitpath().canonicalize()?;
369+
let home = dirs::home_dir().ok_or_else(|| {
370+
anyhow!("failed to find the home directory")
371+
})?;
372+
if path.starts_with(&home) {
373+
let relative_part = path
374+
.strip_prefix(&home)
375+
.expect("can't fail because of the if statement");
376+
path = Path::new("~").join(relative_part);
377+
}
378+
379+
let mut backend = CrosstermBackend::new(buf);
380+
backend.execute(crossterm::terminal::SetTitle(format!(
381+
"gitui ({})",
382+
path.display()
383+
)))?;
384+
364385
let mut terminal = Terminal::new(backend)?;
365386
terminal.hide_cursor()?;
366387
terminal.clear()?;

0 commit comments

Comments
 (0)