on master help sign in
Add +N CLI argument to jump to first file's line number (#8521)
07a006dBjorn Ove Hay Andersen
helix-term/src/args.rs+14
@@ -24,6 +24,7 @@ impl Args {
24 pub fn parse_args() -> Result<Args> {
24 pub fn parse_args() -> Result<Args> {
25 let mut args = Args::default();
25 let mut args = Args::default();
26 let mut argv = std::env::args().peekable();
26 let mut argv = std::env::args().peekable();
27+ let mut line_number = 0;
27
28
28 argv.next(); // skip the program, we don't care about that
29 argv.next(); // skip the program, we don't care about that
29
30
@@ -88,6 +89,13 @@ impl Args {
88 }
89 }
89 }
90 }
90 }
91 }
92+ arg if arg.starts_with('+') => {
93+ let arg = &arg[1..];
94+ line_number = match arg.parse::<usize>() {
95+ Ok(n) => n.saturating_sub(1),
96+ _ => anyhow::bail!("bad line number after +"),
97+ };
98+ }
91 arg => args.files.push(parse_file(arg)),
99 arg => args.files.push(parse_file(arg)),
92 }
100 }
93 }
101 }
@@ -97,6 +105,12 @@ impl Args {
97 args.files.push(parse_file(&arg));
105 args.files.push(parse_file(&arg));
98 }
106 }
99
107
108+ if let Some(file) = args.files.first_mut() {
109+ if line_number != 0 {
110+ file.1.row = line_number;
111+ }
112+ }
113+
100 Ok(args)
114 Ok(args)
101 }
115 }
102}
116}
helix-term/src/main.rs+1
@@ -67,6 +67,7 @@ FLAGS:
67 --vsplit Splits all given files vertically into different windows
67 --vsplit Splits all given files vertically into different windows
68 --hsplit Splits all given files horizontally into different windows
68 --hsplit Splits all given files horizontally into different windows
69 -w, --working-dir <path> Specify an initial working directory
69 -w, --working-dir <path> Specify an initial working directory
70+ +N Open the first given file at line number N
70",
71",
71 env!("CARGO_PKG_NAME"),
72 env!("CARGO_PKG_NAME"),
72 VERSION_AND_GIT_HASH,
73 VERSION_AND_GIT_HASH,