aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2021-03-02 22:23:10 -0500
committerJesse Luehrs <doy@tozt.net>2021-03-02 22:23:10 -0500
commit7e529362470125102f60354d6938154363c4e21d (patch)
tree3bfa9ed1ba4a1b71abc41d16ae673caa3a975197
parent604e09e6ae098350bffe18bde26e1c62f7e88a00 (diff)
downloadrbw-7e529362470125102f60354d6938154363c4e21d.tar.gz
rbw-7e529362470125102f60354d6938154363c4e21d.zip
support VISUAL in preference to EDITOR
-rw-r--r--CHANGELOG.md2
-rw-r--r--src/bin/rbw/main.rs8
-rw-r--r--src/edit.rs8
-rw-r--r--src/error.rs11
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<String> {
- 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<String> {
},
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,