Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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 @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* new command-line option to override the default log file path (`--logfile`) [[@acuteenvy](https://github.com/acuteenvy)] ([#2539](https://github.com/gitui-org/gitui/pull/2539))
* dx: `make check` checks Cargo.toml dependency ordering using `cargo sort` [[@naseschwarz](https://github.com/naseschwarz)]
* add `use_selection_fg` to theme file to allow customizing selection foreground color [[@Upsylonbare](https://github.com/Upsylonbare)] ([#2515](https://github.com/gitui-org/gitui/pull/2515))
* add `--file` cli flag to open the files tab with the given file already selected [[@laktak](https://github.com/laktak)] ([#2510](https://github.com/gitui-org/gitui/issues/2510))

### Changed
* improve error messages [[@acuteenvy](https://github.com/acuteenvy)] ([#2617](https://github.com/gitui-org/gitui/pull/2617))
Expand Down
23 changes: 21 additions & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::{
accessors,
args::CliArgs,
cmdbar::CommandBar,
components::{
command_pump, event_pump, CommandInfo, Component,
Expand Down Expand Up @@ -150,13 +151,14 @@ impl App {
///
#[allow(clippy::too_many_lines)]
pub fn new(
repo: RepoPathRef,
cliargs: CliArgs,
sender_git: Sender<AsyncGitNotification>,
sender_app: Sender<AsyncAppNotification>,
input: Input,
theme: Theme,
key_config: KeyConfig,
) -> Result<Self> {
let repo = RefCell::new(cliargs.repo_path.clone());
log::trace!("open repo at: {:?}", &repo);

let repo_path_text =
Expand Down Expand Up @@ -230,7 +232,21 @@ impl App {
popup_stack: PopupStack::default(),
};

app.set_tab(tab)?;
if let Some(file) = cliargs.select_file {
app.set_tab(2)?;
// convert to relative git path
if let Ok(abs) = file.canonicalize() {
let repo =
app.repo.borrow().gitpath().canonicalize()?;
if let Ok(path) = abs.strip_prefix(repo) {
app.queue.push(InternalEvent::SelectFile {
path: Path::new(".").join(path),
});
}
}
} else {
app.set_tab(tab)?;
}

Ok(app)
}
Expand Down Expand Up @@ -771,6 +787,9 @@ impl App {
InternalEvent::SelectBranch => {
self.select_branch_popup.open()?;
}
InternalEvent::SelectFile { path } => {
self.files_tab.find_file(&path);
}
InternalEvent::ViewSubmodules => {
self.submodule_popup.open()?;
}
Expand Down
15 changes: 15 additions & 0 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ const LOG_FILE_FLAG_ID: &str = "logfile";
const LOGGING_FLAG_ID: &str = "logging";
const THEME_FLAG_ID: &str = "theme";
const WORKDIR_FLAG_ID: &str = "workdir";
const FILE_FLAG_ID: &str = "file";
const GIT_DIR_FLAG_ID: &str = "directory";
const WATCHER_FLAG_ID: &str = "watcher";
const DEFAULT_THEME: &str = "theme.ron";
const DEFAULT_GIT_DIR: &str = ".";

#[derive(Clone)]
pub struct CliArgs {
pub theme: PathBuf,
pub select_file: Option<PathBuf>,
pub repo_path: RepoPath,
pub notify_watcher: bool,
}
Expand Down Expand Up @@ -51,6 +54,10 @@ pub fn process_cmdline() -> Result<CliArgs> {
PathBuf::from,
);

let select_file = arg_matches
.get_one::<String>(FILE_FLAG_ID)
.map(PathBuf::from);

let repo_path = if let Some(w) = workdir {
RepoPath::Workdir { gitdir, workdir: w }
} else {
Expand All @@ -75,6 +82,7 @@ pub fn process_cmdline() -> Result<CliArgs> {

Ok(CliArgs {
theme,
select_file,
repo_path,
notify_watcher,
})
Expand Down Expand Up @@ -129,6 +137,13 @@ fn app() -> ClapApp {
.long("bugreport")
.action(clap::ArgAction::SetTrue),
)
.arg(
Arg::new(FILE_FLAG_ID)
.help("Select the file in the file tab")
.short('f')
.long("file")
.num_args(1),
)
.arg(
Arg::new(GIT_DIR_FLAG_ID)
.help("Set the git directory")
Expand Down
30 changes: 19 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ mod tabs;
mod ui;
mod watcher;

use crate::{app::App, args::process_cmdline};
use crate::{
app::App,
args::{process_cmdline, CliArgs},
};
use anyhow::{anyhow, bail, Result};
use app::QuitState;
use asyncgit::{
Expand All @@ -102,7 +105,6 @@ use scopeguard::defer;
use scopetime::scope_time;
use spinner::Spinner;
use std::{
cell::RefCell,
io::{self, Stdout},
panic,
path::Path,
Expand Down Expand Up @@ -163,7 +165,7 @@ macro_rules! log_eprintln {
fn main() -> Result<()> {
let app_start = Instant::now();

let cliargs = process_cmdline()?;
let mut cliargs = process_cmdline()?;

asyncgit::register_tracing_logging();
ensure_valid_path(&cliargs.repo_path)?;
Expand All @@ -180,8 +182,8 @@ fn main() -> Result<()> {

set_panic_handler()?;

let mut repo_path = cliargs.repo_path;
let mut terminal = start_terminal(io::stdout(), &repo_path)?;
let mut terminal =
start_terminal(io::stdout(), &cliargs.repo_path)?;
let input = Input::new();

let updater = if cliargs.notify_watcher {
Expand All @@ -193,7 +195,7 @@ fn main() -> Result<()> {
loop {
let quit_state = run_app(
app_start,
repo_path.clone(),
cliargs.clone(),
theme.clone(),
key_config.clone(),
&input,
Expand All @@ -203,7 +205,12 @@ fn main() -> Result<()> {

match quit_state {
QuitState::OpenSubmodule(p) => {
repo_path = p;
cliargs = CliArgs {
repo_path: p,
select_file: None,
theme: cliargs.theme,
notify_watcher: cliargs.notify_watcher,
}
}
_ => break,
}
Expand All @@ -214,7 +221,7 @@ fn main() -> Result<()> {

fn run_app(
app_start: Instant,
repo: RepoPath,
cliargs: CliArgs,
theme: Theme,
key_config: KeyConfig,
input: &Input,
Expand All @@ -228,8 +235,9 @@ fn run_app(

let (rx_ticker, rx_watcher) = match updater {
Updater::NotifyWatcher => {
let repo_watcher =
RepoWatcher::new(repo_work_dir(&repo)?.as_str());
let repo_watcher = RepoWatcher::new(
repo_work_dir(&cliargs.repo_path)?.as_str(),
);

(never(), repo_watcher.receiver())
}
Expand All @@ -239,7 +247,7 @@ fn run_app(
let spinner_ticker = tick(SPINNER_INTERVAL);

let mut app = App::new(
RefCell::new(repo),
cliargs,
tx_git,
tx_app,
input.clone(),
Expand Down
2 changes: 2 additions & 0 deletions src/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ pub enum InternalEvent {
///
SelectBranch,
///
SelectFile { path: PathBuf },
///
OpenExternalEditor(Option<String>),
///
Push(String, PushType, bool, bool),
Expand Down
4 changes: 4 additions & 0 deletions src/tabs/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ impl FilesTab {
pub fn file_finder_update(&mut self, file: &Path) {
self.files.find_file(file);
}

pub fn find_file(&mut self, file: &Path) {
self.files.find_file(file);
}
}

impl DrawableComponent for FilesTab {
Expand Down
Loading