Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set the terminal title to gitui ({repo_path}) #2484

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* improve syntax highlighting file detection [[@acuteenvy](https://github.com/acuteenvy)] ([#2524](https://github.com/extrawurst/gitui/pull/2524))
* After commit: jump back to unstaged area [[@tommady](https://github.com/tommady)] ([#2476](https://github.com/extrawurst/gitui/issues/2476))
* use OSC52 copying in case other methods fail [[@naseschwarz](https://github.com/naseschwarz)] ([#2366](https://github.com/gitui-org/gitui/issues/2366))
* set the terminal title to `gitui ({repo_path})` [[@acuteenvy](https://github.com/acuteenvy)] ([#2462](https://github.com/gitui-org/gitui/issues/2462))

## [0.27.0] - 2024-01-14

Expand Down
31 changes: 26 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -359,8 +361,27 @@ fn select_event(
Ok(ev)
}

fn start_terminal(buf: Stdout) -> io::Result<Terminal> {
let backend = CrosstermBackend::new(buf);
fn start_terminal(
buf: Stdout,
repo_path: &RepoPath,
) -> Result<Terminal> {
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()?;
Expand Down