diff options
Diffstat (limited to 'helix-term')
-rw-r--r-- | helix-term/src/application.rs | 23 | ||||
-rw-r--r-- | helix-term/src/args.rs | 1 | ||||
-rw-r--r-- | helix-term/src/main.rs | 12 |
3 files changed, 22 insertions, 14 deletions
diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 43e1cdfc..ed085749 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -162,14 +162,19 @@ impl Application { // Unset path to prevent accidentally saving to the original tutor file. doc_mut!(editor).set_path(None); } else if !args.files.is_empty() { - if args.open_cwd { - // NOTE: The working directory is already set to args.files[0] in main() - editor.new_file(Action::VerticalSplit); - let picker = ui::file_picker(".".into(), &config.load().editor); + let mut files_it = args.files.into_iter().peekable(); + + // If the first file is a directory, skip it and open a picker + if let Some((first, _)) = files_it.next_if(|(p, _)| p.is_dir()) { + let picker = ui::file_picker(first, &config.load().editor); compositor.push(Box::new(overlaid(picker))); - } else { - let nr_of_files = args.files.len(); - for (i, (file, pos)) in args.files.into_iter().enumerate() { + } + + // If there are any more files specified, open them + if files_it.peek().is_some() { + let mut nr_of_files = 0; + for (file, pos) in files_it { + nr_of_files += 1; if file.is_dir() { return Err(anyhow::anyhow!( "expected a path to file, found a directory. (to open a directory pass it as first argument)" @@ -181,7 +186,7 @@ impl Application { // option. If neither of those two arguments are passed // in, just load the files normally. let action = match args.split { - _ if i == 0 => Action::VerticalSplit, + _ if nr_of_files == 1 => Action::VerticalSplit, Some(Layout::Vertical) => Action::VerticalSplit, Some(Layout::Horizontal) => Action::HorizontalSplit, None => Action::Load, @@ -208,6 +213,8 @@ impl Application { // does not affect views without pos since it is at the top let (view, doc) = current!(editor); align_view(doc, view, Align::Center); + } else { + editor.new_file(Action::VerticalSplit); } } else if stdin().is_tty() || cfg!(feature = "integration") { editor.new_file(Action::VerticalSplit); diff --git a/helix-term/src/args.rs b/helix-term/src/args.rs index 99ce3992..6a49889b 100644 --- a/helix-term/src/args.rs +++ b/helix-term/src/args.rs @@ -17,7 +17,6 @@ pub struct Args { pub log_file: Option<PathBuf>, pub config_file: Option<PathBuf>, pub files: Vec<(PathBuf, Position)>, - pub open_cwd: bool, pub working_directory: Option<PathBuf>, } diff --git a/helix-term/src/main.rs b/helix-term/src/main.rs index 6411a7c5..a62c54a4 100644 --- a/helix-term/src/main.rs +++ b/helix-term/src/main.rs @@ -116,16 +116,18 @@ FLAGS: setup_logging(args.verbosity).context("failed to initialize logging")?; + // Before setting the working directory, resolve all the paths in args.files + for (path, _) in args.files.iter_mut() { + *path = helix_core::path::get_canonicalized_path(path); + } + // NOTE: Set the working directory early so the correct configuration is loaded. Be aware that // Application::new() depends on this logic so it must be updated if this changes. if let Some(path) = &args.working_directory { helix_loader::set_current_working_dir(path)?; - } - - // If the first file is a directory, it will be the working directory and a file picker will be opened - if let Some((path, _)) = args.files.first().filter(|p| p.0.is_dir()) { + } else if let Some((path, _)) = args.files.first().filter(|p| p.0.is_dir()) { + // If the first file is a directory, it will be the working directory unless -w was specified helix_loader::set_current_working_dir(path)?; - args.open_cwd = true; // Signal Application that we want to open the picker on "." } let config = match Config::load_default() { |