[PATCH] Honour the $VISUAL environment variable

pudinha rogi at skylittlesystem.org
Sat Jul 18 04:11:04 CEST 2020


---
Hello password storers! Hope you are well.

I made this patch to make *pass* honour the $VISUAL environment
variable, as in my system $EDITOR is not a visual editor.

What do you think?

Best regards,
Pudinha <3

 man/pass.1                         |  8 ++++----
 src/completion/pass.zsh-completion |  2 +-
 src/password-store.sh              |  8 +++++---
 tests/setup.sh                     |  1 +
 tests/t0200-edit-tests.sh          | 15 +++++++++++++--
 5 files changed, 24 insertions(+), 10 deletions(-)

diff --git a/man/pass.1 b/man/pass.1
index a555dcb..bca5d9c 100644
--- a/man/pass.1
+++ b/man/pass.1
@@ -116,8 +116,8 @@ before overwriting an existing password, unless \fI--force\fP or \fI-f\fP is spe
 command is alternatively named \fBadd\fP.
 .TP
 \fBedit\fP \fIpass-name\fP
-Insert a new password or edit an existing password using the default text editor specified
-by the environment variable \fIEDITOR\fP or using
+Insert a new password or edit an existing password using the default text editor specified,
+in order of precedence, by the environment variables \fIVISUAL\fP and \fIEDITOR\fP or using
 .BR vi (1)
 as a fallback. This mode makes use of temporary files for editing, but care is taken to
 ensure that temporary files are created in \fI/dev/shm\fP in order to avoid writing to
@@ -463,8 +463,8 @@ upper-case fingerprint in this variable. If multiple fingerprints are specified,
 separated by a whitespace character, then signatures must match at least one.
 The \fBinit\fP command will keep signatures of \fB.gpg-id\fP files up to date.
 .TP
-.I EDITOR
-The location of the text editor used by \fBedit\fP.
+.I VISUAL, EDITOR
+In order of precedence, the location of the text editor used by \fBedit\fP.
 .SH SEE ALSO
 .BR gpg2 (1),
 .BR tr (1),
diff --git a/src/completion/pass.zsh-completion b/src/completion/pass.zsh-completion
index 27ce15a..ceb2855 100644
--- a/src/completion/pass.zsh-completion
+++ b/src/completion/pass.zsh-completion
@@ -98,7 +98,7 @@ _pass () {
 			"show:Decrypt and print a password"
 			"insert:Insert a new password"
 			"generate:Generate a new password using pwgen"
-			"edit:Edit a password with \$EDITOR"
+			"edit:Edit a password with the default editor"
 			"mv:Rename the password"
 			"cp:Copy the password"
 			"rm:Remove the password"
diff --git a/src/password-store.sh b/src/password-store.sh
index 77f3eda..8ff2b24 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -6,6 +6,8 @@
 umask "${PASSWORD_STORE_UMASK:-077}"
 set -o pipefail
 
+EDITOR=${VISUAL:-${EDITOR:-vi}}
+
 GPG_OPTS=( $PASSWORD_STORE_GPG_OPTS "--quiet" "--yes" "--compress-algo=none" "--no-encrypt-to" )
 GPG="gpg"
 export GPG_TTY="${GPG_TTY:-$(tty 2>/dev/null)}"
@@ -292,7 +294,7 @@ cmd_usage() {
 	        during entry. Or, optionally, the entry may be multiline. Prompt before
 	        overwriting existing password unless forced.
 	    $PROGRAM edit pass-name
-	        Insert a new password or edit an existing password using ${EDITOR:-vi}.
+	        Insert a new password or edit an existing password using $EDITOR.
 	    $PROGRAM generate [--no-symbols,-n] [--clip,-c] [--in-place,-i | --force,-f] pass-name [pass-length]
 	        Generate a new password of pass-length (or $GENERATED_LENGTH if unspecified) with optionally no symbols.
 	        Optionally put it on the clipboard and clear board after $CLIP_TIME seconds.
@@ -498,13 +500,13 @@ cmd_edit() {
 		$GPG -d -o "$tmp_file" "${GPG_OPTS[@]}" "$passfile" || exit 1
 		action="Edit"
 	fi
-	${EDITOR:-vi} "$tmp_file"
+	$EDITOR "$tmp_file"
 	[[ -f $tmp_file ]] || die "New password not saved."
 	$GPG -d -o - "${GPG_OPTS[@]}" "$passfile" 2>/dev/null | diff - "$tmp_file" &>/dev/null && die "Password unchanged."
 	while ! $GPG -e "${GPG_RECIPIENT_ARGS[@]}" -o "$passfile" "${GPG_OPTS[@]}" "$tmp_file"; do
 		yesno "GPG encryption failed. Would you like to try again?"
 	done
-	git_add_file "$passfile" "$action password for $path using ${EDITOR:-vi}."
+	git_add_file "$passfile" "$action password for $path using $EDITOR."
 }
 
 cmd_generate() {
diff --git a/tests/setup.sh b/tests/setup.sh
index 5d1e794..296f97b 100644
--- a/tests/setup.sh
+++ b/tests/setup.sh
@@ -22,6 +22,7 @@ unset PASSWORD_STORE_ENABLE_EXTENSIONS
 unset PASSWORD_STORE_EXTENSIONS_DIR
 unset PASSWORD_STORE_SIGNING_KEY
 unset EDITOR
+unset VISUAL
 
 # We must be called from tests/
 TEST_HOME="$(pwd)"
diff --git a/tests/t0200-edit-tests.sh b/tests/t0200-edit-tests.sh
index d8d7b64..23af0ab 100755
--- a/tests/t0200-edit-tests.sh
+++ b/tests/t0200-edit-tests.sh
@@ -4,14 +4,25 @@ test_description='Test edit'
 cd "$(dirname "$0")"
 . ./setup.sh
 
-test_expect_success 'Test "edit" command' '
+test_expect_success 'Test "edit" command with EDITOR' '
 	"$PASS" init $KEY1 &&
 	"$PASS" generate cred1 90 &&
 	export FAKE_EDITOR_PASSWORD="big fat fake password" &&
-	export PATH="$TEST_HOME:$PATH"
+	export PATH="$TEST_HOME:$PATH" &&
 	export EDITOR="fake-editor-change-password.sh" &&
 	"$PASS" edit cred1 &&
 	[[ $("$PASS" show cred1) == "$FAKE_EDITOR_PASSWORD" ]]
 '
 
+test_expect_success 'Test "edit" command with VISUAL' '
+	"$PASS" init $KEY1 &&
+	"$PASS" generate cred1 90 &&
+	export FAKE_EDITOR_PASSWORD="big fat fake password" &&
+	export PATH="$TEST_HOME:$PATH" &&
+	export EDITOR="exit -1" &&
+	export VISUAL="fake-editor-change-password.sh" &&
+	"$PASS" edit cred1 &&
+	[[ $("$PASS" show cred1) == "$FAKE_EDITOR_PASSWORD" ]]
+'
+
 test_done
-- 
2.27.0



More information about the Password-Store mailing list