diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 0d40fa66f025..789d10503392 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -169,6 +169,10 @@ impl Application { let picker = ui::file_picker(".".into(), &config.load().editor); compositor.push(Box::new(overlaid(picker))); } else { + match args.working_path { + Some(path) => helix_loader::set_current_working_dir(path.clone())?, + None => log::warn!("invalid working path given"), + } let nr_of_files = args.files.len(); for (i, (file, pos)) in args.files.into_iter().enumerate() { if file.is_dir() { diff --git a/helix-term/src/args.rs b/helix-term/src/args.rs index dd787f1fd18c..21347e7eb872 100644 --- a/helix-term/src/args.rs +++ b/helix-term/src/args.rs @@ -17,6 +17,7 @@ pub struct Args { pub log_file: Option, pub config_file: Option, pub files: Vec<(PathBuf, Position)>, + pub working_path: Option, } impl Args { @@ -59,6 +60,10 @@ impl Args { Some(path) => args.log_file = Some(path.into()), None => anyhow::bail!("--log must specify a path to write"), }, + "-w" | "--working-path" => match argv.next().as_deref() { + Some(path) => args.working_path = if Path::new(path).exists() {Some(PathBuf::from(path))} else {None}, + None => anyhow::bail!("--working-path must specify an initial working directory"), + }, arg if arg.starts_with("--") => { anyhow::bail!("unexpected double dash argument: {}", arg) } diff --git a/helix-term/src/main.rs b/helix-term/src/main.rs index 542d18e6aa4d..667faa16f151 100644 --- a/helix-term/src/main.rs +++ b/helix-term/src/main.rs @@ -66,6 +66,7 @@ FLAGS: -V, --version Prints version information --vsplit Splits all given files vertically into different windows --hsplit Splits all given files horizontally into different windows + -w, --working-path Specify an initial working directory ", env!("CARGO_PKG_NAME"), VERSION_AND_GIT_HASH,