From eaea71237665f8ccc44a94ccbb564ff8255d485d Mon Sep 17 00:00:00 2001 From: Nachum Barcohen <38861757+nabaco@users.noreply.github.com> Date: Fri, 20 Jan 2023 04:30:05 +0200 Subject: [PATCH] Accept +num flag for opening at line number --- helix-term/src/args.rs | 15 +++++++++++++++ helix-term/src/main.rs | 1 + 2 files changed, 16 insertions(+) diff --git a/helix-term/src/args.rs b/helix-term/src/args.rs index dd787f1fd18c..083aa322da87 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 line_number: usize, } impl Args { @@ -73,6 +74,16 @@ impl Args { } } } + arg if arg.starts_with('+') => { + let arg = arg.get(1..).unwrap(); + args.line_number = match arg.parse() { + Ok(n) => n, + _ => anyhow::bail!("bad line number after +"), + }; + if args.line_number > 0 { + args.line_number -= 1; + } + } arg => args.files.push(parse_file(arg)), } } @@ -82,6 +93,10 @@ impl Args { args.files.push(parse_file(&arg)); } + if let Some(file) = args.files.first_mut() { + file.1.row = args.line_number; + } + Ok(args) } } diff --git a/helix-term/src/main.rs b/helix-term/src/main.rs index aac5c5379f37..22e1e8ce5256 100644 --- a/helix-term/src/main.rs +++ b/helix-term/src/main.rs @@ -73,6 +73,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 + +N Goto line number N ", env!("CARGO_PKG_NAME"), VERSION_AND_GIT_HASH,