Skip to content

Commit 0e82862

Browse files
authored
locate editor executable using which crate (#70)
1 parent 3e13e07 commit 0e82862

File tree

4 files changed

+64
-7
lines changed

4 files changed

+64
-7
lines changed

Cargo.lock

+57
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ itertools = "0.13.0"
2828
anyhow = "1.0.83"
2929
strum = { version = "0.26.2", features = ["derive"] }
3030
syntect = "5.2.0"
31+
which = "6.0.3"
3132

3233
[dev-dependencies]
3334
lazy_static = "1.4.0"

src/editor.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use clap::ValueEnum;
44
use itertools::Itertools;
55
use std::{
66
fmt::{self, Debug, Display, Formatter},
7-
io,
87
process::{Child, Command},
98
};
109
use strum::Display;
@@ -87,10 +86,11 @@ impl EditorCommand {
8786
))
8887
}
8988

90-
pub fn spawn(&self, file_name: &str, line_number: u64) -> io::Result<Child> {
91-
let mut command = Command::new(self.program());
89+
pub fn spawn(&self, file_name: &str, line_number: u64) -> Result<Child> {
90+
let path = which::which(self.program())?;
91+
let mut command = Command::new(path);
9292
command.args(self.args(file_name, line_number));
93-
command.spawn()
93+
command.spawn().map_err(anyhow::Error::from)
9494
}
9595

9696
fn program(&self) -> &str {

src/ig.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ mod search_config;
44
mod searcher;
55
mod sink;
66

7-
use std::io;
87
use std::process::ExitStatus;
98
use std::sync::mpsc;
109

@@ -43,9 +42,9 @@ impl Ig {
4342
}
4443
}
4544

46-
fn try_spawn_editor(&self, file_name: &str, line_number: u64) -> io::Result<ExitStatus> {
45+
fn try_spawn_editor(&self, file_name: &str, line_number: u64) -> anyhow::Result<ExitStatus> {
4746
let mut editor_process = self.editor_command.spawn(file_name, line_number)?;
48-
editor_process.wait()
47+
editor_process.wait().map_err(anyhow::Error::from)
4948
}
5049

5150
pub fn open_file_if_requested(&mut self, selected_entry: Option<(String, u64)>) {

0 commit comments

Comments
 (0)