Skip to content

Commit a0b9f0d

Browse files
bjorn-ovenabaco
authored andcommitted
Add +N CLI argument to jump to first file's line number (helix-editor#8521)
* Accept +num flag for opening at line number * Update +N argument feature according to feedback in original PR helix-editor#5603 * Only override the line number of the first file if +N is specified --------- Co-authored-by: Nachum Barcohen <[email protected]>
1 parent 73afee1 commit a0b9f0d

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

helix-term/src/args.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ impl Args {
2424
pub fn parse_args() -> Result<Args> {
2525
let mut args = Args::default();
2626
let mut argv = std::env::args().peekable();
27+
let mut line_number = 0;
2728

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

@@ -88,6 +89,13 @@ impl Args {
8889
}
8990
}
9091
}
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+
}
9199
arg => args.files.push(parse_file(arg)),
92100
}
93101
}
@@ -97,6 +105,12 @@ impl Args {
97105
args.files.push(parse_file(&arg));
98106
}
99107

108+
if let Some(file) = args.files.first_mut() {
109+
if line_number != 0 {
110+
file.1.row = line_number;
111+
}
112+
}
113+
100114
Ok(args)
101115
}
102116
}

helix-term/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ FLAGS:
6767
--vsplit Splits all given files vertically into different windows
6868
--hsplit Splits all given files horizontally into different windows
6969
-w, --working-dir <path> Specify an initial working directory
70+
+N Open the first given file at line number N
7071
",
7172
env!("CARGO_PKG_NAME"),
7273
VERSION_AND_GIT_HASH,

0 commit comments

Comments
 (0)