Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable starting hx with a working directory #8223

Merged
merged 15 commits into from
Oct 3, 2023
Merged
Changes from all 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
3 changes: 3 additions & 0 deletions helix-term/src/application.rs
Original file line number Diff line number Diff line change
@@ -156,6 +156,9 @@ 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)?;
15 changes: 15 additions & 0 deletions helix-term/src/args.rs
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@ pub struct Args {
pub log_file: Option<PathBuf>,
pub config_file: Option<PathBuf>,
pub files: Vec<(PathBuf, Position)>,
pub working_directory: Option<PathBuf>,
}

impl Args {
@@ -59,6 +60,20 @@ impl Args {
Some(path) => args.log_file = Some(path.into()),
None => anyhow::bail!("--log must specify a path to write"),
},
"-w" | "--working-dir" => match argv.next().as_deref() {
Some(path) => {
args.working_directory = if Path::new(path).is_dir() {
Some(PathBuf::from(path))
} else {
anyhow::bail!(
"--working-dir specified does not exist or is not a directory"
)
}
}
None => {
anyhow::bail!("--working-dir must specify an initial working directory")
}
},
arg if arg.starts_with("--") => {
anyhow::bail!("unexpected double dash argument: {}", arg)
}
1 change: 1 addition & 0 deletions helix-term/src/main.rs
Original file line number Diff line number Diff line change
@@ -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-dir <path> Specify an initial working directory
",
env!("CARGO_PKG_NAME"),
VERSION_AND_GIT_HASH,