Skip to content

Commit

Permalink
Accept +num flag for opening at line number
Browse files Browse the repository at this point in the history
  • Loading branch information
nabaco committed Jan 23, 2023
1 parent 4535d0f commit eaea712
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
15 changes: 15 additions & 0 deletions helix-term/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct Args {
pub log_file: Option<PathBuf>,
pub config_file: Option<PathBuf>,
pub files: Vec<(PathBuf, Position)>,
pub line_number: usize,
}

impl Args {
Expand Down Expand Up @@ -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)),
}
}
Expand All @@ -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)
}
}
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 @@ -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,
Expand Down

0 comments on commit eaea712

Please sign in to comment.