on master help sign in
enable starting hx with a working directory (#8223)
75c0a5cLloyd Bond
helix-term/src/application.rs+3
@@ -156,6 +156,9 @@ impl Application {
156 let editor_view = Box::new(ui::EditorView::new(Keymaps::new(keys)));
156 let editor_view = Box::new(ui::EditorView::new(Keymaps::new(keys)));
157 compositor.push(editor_view);
157 compositor.push(editor_view);
158
158
159+ if let Some(path) = args.working_directory {
160+ helix_loader::set_current_working_dir(path)?
161+ }
159 if args.load_tutor {
162 if args.load_tutor {
160 let path = helix_loader::runtime_file(Path::new("tutor"));
163 let path = helix_loader::runtime_file(Path::new("tutor"));
161 editor.open(&path, Action::VerticalSplit)?;
164 editor.open(&path, Action::VerticalSplit)?;
helix-term/src/args.rs+15
@@ -17,6 +17,7 @@ pub struct Args {
17 pub log_file: Option<PathBuf>,
17 pub log_file: Option<PathBuf>,
18 pub config_file: Option<PathBuf>,
18 pub config_file: Option<PathBuf>,
19 pub files: Vec<(PathBuf, Position)>,
19 pub files: Vec<(PathBuf, Position)>,
20+ pub working_directory: Option<PathBuf>,
20}
21}
21
22
22impl Args {
23impl Args {
@@ -59,6 +60,20 @@ impl Args {
59 Some(path) => args.log_file = Some(path.into()),
60 Some(path) => args.log_file = Some(path.into()),
60 None => anyhow::bail!("--log must specify a path to write"),
61 None => anyhow::bail!("--log must specify a path to write"),
61 },
62 },
63+ "-w" | "--working-dir" => match argv.next().as_deref() {
64+ Some(path) => {
65+ args.working_directory = if Path::new(path).is_dir() {
66+ Some(PathBuf::from(path))
67+ } else {
68+ anyhow::bail!(
69+ "--working-dir specified does not exist or is not a directory"
70+ )
71+ }
72+ }
73+ None => {
74+ anyhow::bail!("--working-dir must specify an initial working directory")
75+ }
76+ },
62 arg if arg.starts_with("--") => {
77 arg if arg.starts_with("--") => {
63 anyhow::bail!("unexpected double dash argument: {}", arg)
78 anyhow::bail!("unexpected double dash argument: {}", arg)
64 }
79 }
helix-term/src/main.rs+1
@@ -66,6 +66,7 @@ FLAGS:
66 -V, --version Prints version information
66 -V, --version Prints version information
67 --vsplit Splits all given files vertically into different windows
67 --vsplit Splits all given files vertically into different windows
68 --hsplit Splits all given files horizontally into different windows
68 --hsplit Splits all given files horizontally into different windows
69+ -w, --working-dir <path> Specify an initial working directory
69",
70",
70 env!("CARGO_PKG_NAME"),
71 env!("CARGO_PKG_NAME"),
71 VERSION_AND_GIT_HASH,
72 VERSION_AND_GIT_HASH,