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

Add +N CLI argument to jump to first file's line number #8521

Merged
merged 3 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions helix-term/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ impl Args {
pub fn parse_args() -> Result<Args> {
let mut args = Args::default();
let mut argv = std::env::args().peekable();
let mut line_number = 0;

argv.next(); // skip the program, we don't care about that

Expand Down Expand Up @@ -88,6 +89,13 @@ impl Args {
}
}
}
arg if arg.starts_with('+') => {
let arg = &arg[1..];
line_number = match arg.parse::<usize>() {
Ok(n) => n.saturating_sub(1),
_ => anyhow::bail!("bad line number after +"),
};
}
arg => args.files.push(parse_file(arg)),
}
}
Expand All @@ -97,6 +105,12 @@ impl Args {
args.files.push(parse_file(&arg));
}

if let Some(file) = args.files.first_mut() {
if line_number != 0 {
file.1.row = line_number;
}
}

Ok(args)
}
}
Expand Down
1 change: 1 addition & 0 deletions helix-term/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ FLAGS:
--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
+N Open the first given file at line number N
",
env!("CARGO_PKG_NAME"),
VERSION_AND_GIT_HASH,
Expand Down
Loading