From 7e529362470125102f60354d6938154363c4e21d Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Tue, 2 Mar 2021 22:23:10 -0500 Subject: support VISUAL in preference to EDITOR --- CHANGELOG.md | 2 ++ src/bin/rbw/main.rs | 8 ++++---- src/edit.rs | 8 ++++++-- src/error.rs | 11 +++++++++-- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 08b6bed..f43dbc4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ and no longer produces core dumps (#42, oranenj) * Suggest rotating the user's encryption key if we see an old cipherstring type (#40, rjc) +* Prefer the value of `$VISUAL` when trying to find an editor to run, before + falling back to `$EDITOR` (#43, rjc) ## [1.0.0] - 2021-02-21 diff --git a/src/bin/rbw/main.rs b/src/bin/rbw/main.rs index badff67..4380372 100644 --- a/src/bin/rbw/main.rs +++ b/src/bin/rbw/main.rs @@ -74,8 +74,8 @@ enum Opt { long_about = "Add a new password to the database\n\n\ This command will open a text editor to enter \ the password and notes. The editor to use is determined \ - by the value of the $EDITOR environment variable. The \ - first line will be saved as the password and the \ + by the value of the $VISUAL or $EDITOR environment variables. + The first line will be saved as the password and the \ remainder will be saved as a note." )] Add { @@ -156,8 +156,8 @@ enum Opt { This command will open a text editor with the existing \ password and notes of the given entry for editing. \ The editor to use is determined by the value of the \ - $EDITOR environment variable. The first line will be \ - saved as the password and the remainder will be saved \ + $VISUAL or $EDITOR environment variables. The first line \ + will be saved as the password and the remainder will be saved \ as a note." )] Edit { diff --git a/src/edit.rs b/src/edit.rs index 8325072..cac8794 100644 --- a/src/edit.rs +++ b/src/edit.rs @@ -3,8 +3,11 @@ use crate::prelude::*; use std::io::{Read as _, Write as _}; pub fn edit(contents: &str, help: &str) -> Result { - let editor = - std::env::var_os("EDITOR").unwrap_or_else(|| "/usr/bin/vim".into()); + let mut var = "VISUAL"; + let editor = std::env::var_os(var).unwrap_or_else(|| { + var = "EDITOR"; + std::env::var_os(var).unwrap_or_else(|| "/usr/bin/vim".into()) + }); let editor = std::path::Path::new(&editor); let mut args = vec![]; @@ -21,6 +24,7 @@ pub fn edit(contents: &str, help: &str) -> Result { }, None => { return Err(Error::InvalidEditor { + var: var.to_string(), editor: editor.as_os_str().to_os_string(), }) } diff --git a/src/error.rs b/src/error.rs index e43084c..cd85c02 100644 --- a/src/error.rs +++ b/src/error.rs @@ -43,8 +43,15 @@ pub enum Error { #[snafu(display("invalid cipherstring: {}", reason))] InvalidCipherString { reason: String }, - #[snafu(display("invalid value for $EDITOR: {}", editor.to_string_lossy()))] - InvalidEditor { editor: std::ffi::OsString }, + #[snafu(display( + "invalid value for ${}: {}", + var, + editor.to_string_lossy() + ))] + InvalidEditor { + var: String, + editor: std::ffi::OsString, + }, #[snafu(display("invalid mac"))] InvalidMac, -- cgit v1.2.3