Identify text editor by inspecting VISUAL, EDITOR, and git config
@@ -3,17 +3,25 @@ pub mod git;
use crate::prelude::*;
use crev_common;
use crev_data::proof;
+use git2;
use std::fmt::Write as FmtWrite;
use std::{self, env, ffi, fs, io::Write, path::Path, process};
use tempdir;
pub use crev_common::{read_file_to_string, store_str_to_file, store_to_file_with};
+fn get_git_default_editor() -> Result<String> {
+ let cfg = git2::Config::open_default()?;
+ Ok(cfg.get_string("core.editor")?)
+}
+
fn get_editor_to_use() -> Result<ffi::OsString> {
Ok(if let Some(v) = env::var_os("VISUAL") {
v
} else if let Some(v) = env::var_os("EDITOR") {
v
+ } else if let Ok(v) = get_git_default_editor() {
+ v.into()
} else {
"vi".into()
})
