Skip to content

Commit

Permalink
locate editor executable using which crate
Browse files Browse the repository at this point in the history
  • Loading branch information
konradsz committed Aug 25, 2024
1 parent 3e13e07 commit f6a1fa4
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 7 deletions.
57 changes: 57 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ itertools = "0.13.0"
anyhow = "1.0.83"
strum = { version = "0.26.2", features = ["derive"] }
syntect = "5.2.0"
which = "6.0.3"

[dev-dependencies]
lazy_static = "1.4.0"
Expand Down
8 changes: 4 additions & 4 deletions src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use clap::ValueEnum;
use itertools::Itertools;
use std::{
fmt::{self, Debug, Display, Formatter},
io,
process::{Child, Command},
};
use strum::Display;
Expand Down Expand Up @@ -87,10 +86,11 @@ impl EditorCommand {
))
}

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

fn program(&self) -> &str {
Expand Down
5 changes: 2 additions & 3 deletions src/ig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ mod search_config;
mod searcher;
mod sink;

use std::io;
use std::process::ExitStatus;
use std::sync::mpsc;

Expand Down Expand Up @@ -43,9 +42,9 @@ impl Ig {
}
}

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

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

0 comments on commit f6a1fa4

Please sign in to comment.