editor now uses EDITOR env var

This commit is contained in:
Abraham Toriz 2021-08-03 20:57:22 -05:00
parent 3ebe2ca035
commit 6414930dfb
No known key found for this signature in database
GPG Key ID: D5B4A746DB5DD42A
2 changed files with 5 additions and 2 deletions

View File

@ -54,7 +54,7 @@ impl<'a> Command<'a> for InCommand {
} else if !config.require_note {
None
} else {
Some(editor::get_string(config.note_editor.as_ref())?)
Some(editor::get_string(config.note_editor.clone())?)
};
let (start, needs_warning) = time_or_warning(start, db)?;

View File

@ -5,12 +5,15 @@ use tempfile::NamedTempFile;
use crate::error::{Error::*, Result};
pub fn get_string(note_editor: Option<&String>) -> Result<String> {
pub fn get_string(note_editor: Option<String>) -> Result<String> {
let note_editor = if let Some(note_editor) = note_editor {
note_editor
} else if let Ok(editor_env) = std::env::var("EDITOR") {
editor_env
} else {
return Err(EditorIsEmpty);
};
let parts: Vec<_> = note_editor.split(' ').filter(|p| !p.is_empty()).collect();
let editor = if let Some(name) = parts.get(0) {
name.to_owned()