Skip to content

Commit

Permalink
Update +N argument feature according to feedback in original PR helix…
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorn-ove committed Oct 11, 2023
1 parent 66fbb60 commit 6410e65
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
13 changes: 5 additions & 8 deletions helix-term/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ pub struct Args {
pub config_file: Option<PathBuf>,
pub files: Vec<(PathBuf, Position)>,
pub working_directory: Option<PathBuf>,
pub line_number: usize,
}

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 @@ -90,14 +90,11 @@ impl Args {
}
}
arg if arg.starts_with('+') => {
let arg = arg.get(1..).unwrap();
args.line_number = match arg.parse() {
Ok(n) => n,
let arg = &arg[1..];
line_number = match arg.parse::<usize>() {
Ok(n) => n.saturating_sub(1),
_ => anyhow::bail!("bad line number after +"),
};
if args.line_number > 0 {
args.line_number -= 1;
}
}
arg => args.files.push(parse_file(arg)),
}
Expand All @@ -109,7 +106,7 @@ impl Args {
}

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

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

0 comments on commit 6410e65

Please sign in to comment.