aboutsummaryrefslogtreecommitdiff
path: root/helix-term
diff options
context:
space:
mode:
authorBjorn Ove Hay Andersen2023-10-09 16:38:09 +0000
committerGitHub2023-10-09 16:38:09 +0000
commita8574805617d86304232b47d84fd7c7f4f773520 (patch)
tree9769a097d881c4330a71e79bdcee0bb279b0fb9f /helix-term
parent5cb76e74f9bd226f1b4757f478bf49873d9ecfe6 (diff)
Set the working directory before loading the config (#8498)
Diffstat (limited to 'helix-term')
-rw-r--r--helix-term/src/application.rs5
-rw-r--r--helix-term/src/main.rs8
2 files changed, 9 insertions, 4 deletions
diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs
index 7c23ddfe..fabd0fa4 100644
--- a/helix-term/src/application.rs
+++ b/helix-term/src/application.rs
@@ -156,9 +156,6 @@ impl Application {
let editor_view = Box::new(ui::EditorView::new(Keymaps::new(keys)));
compositor.push(editor_view);
- if let Some(path) = args.working_directory {
- helix_loader::set_current_working_dir(path)?
- }
if args.load_tutor {
let path = helix_loader::runtime_file(Path::new("tutor"));
editor.open(&path, Action::VerticalSplit)?;
@@ -167,7 +164,7 @@ impl Application {
} else if !args.files.is_empty() {
let first = &args.files[0].0; // we know it's not empty
if first.is_dir() {
- helix_loader::set_current_working_dir(first.clone())?;
+ // 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);
compositor.push(Box::new(overlaid(picker)));
diff --git a/helix-term/src/main.rs b/helix-term/src/main.rs
index 009cbf7f..ed3478ac 100644
--- a/helix-term/src/main.rs
+++ b/helix-term/src/main.rs
@@ -115,6 +115,14 @@ FLAGS:
setup_logging(args.verbosity).context("failed to initialize logging")?;
+ // 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, true)) = args.files.first().map(|(path, _)| (path, path.is_dir())) {
+ helix_loader::set_current_working_dir(path)?;
+ } else if let Some(path) = &args.working_directory {
+ helix_loader::set_current_working_dir(path)?;
+ }
+
let config = match Config::load_default() {
Ok(config) => config,
Err(ConfigLoadError::Error(err)) if err.kind() == std::io::ErrorKind::NotFound => {