diff --git a/src/editor/open_in_editor.rs b/src/editor/open_in_editor.rs index 5693f93..2dd6ca8 100644 --- a/src/editor/open_in_editor.rs +++ b/src/editor/open_in_editor.rs @@ -4,13 +4,11 @@ use std::io::{Read, Seek, SeekFrom, Write}; use std::process::Command; use tempfile::NamedTempFile; use thiserror::Error; -use tracing::{debug, instrument, trace}; +use tracing::{debug, instrument, trace, warn}; /// Error type returned by `spawn_editor` #[derive(Debug, Error)] pub enum EditorSpawnError { - #[error("$EDITOR environment variable isn't set")] - NoEditorEnv, #[error("failed to parse out absolute path of editor: {0}")] InvalidEditorPath(which::Error), #[error("failed to create temporary file for edit buffer: {0}")] @@ -34,7 +32,10 @@ pub enum EditorSpawnError { pub fn spawn_editor(buffer: impl AsRef + Display) -> Result { use EditorSpawnError::*; trace!("Input buffer: {buffer}"); - let editor = option_env!("EDITOR").ok_or(NoEditorEnv)?; + let editor = option_env!("EDITOR").unwrap_or_else(|| { + warn!("EDITOR environment variable isn't set, defaulting to vi"); + "vi" + }); debug!("$EDITOR is {editor}"); let editor = which::which(editor).map_err(InvalidEditorPath)?; debug!("$EDITOR's full path is {editor:?}");