git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] git-sh-setup.sh: make GIT_EDITOR/core.editor/VISUAL/EDITOR accept commands

From
David Kastrup <dak@gnu.org>
Date
Aug 1, 2007, 21:47 UTC
Message-ID
<S1752294AbXHAWCj/20070801220239Z+281@vger.kernel.org>
In-Reply-To
<7v7iof3uc5.fsf@assigned-by-dhcp.cox.net>

The previous code only allowed specifying a single executable rather than a complete command like "emacsclient --alternate-editor vi" in those variables. Since VISUAL/EDITOR appear to be traditionally passed to a shell for interpretation (as corroborated with "less", "mail" and "mailx", while the really ancient "more" indeed allows only an executable name), the shell function git_editor has been amended appropriately.

"eval" is employed to have quotes and similar interpreted _after_ expansion, so that specifying EDITOR='"/home/dak/My Commands/notepad.exe"' can be used for actually using commands with blanks.

Instead of passing just the first argument of git_editor on, we pass all of them (so that +lineno might be employed at a later point of time, or so that multiple files may be edited when appropriate).

Strictly speaking, there is a change in behavior: when git config core.editor returns a valid but empty string, the fallbacks are still searched. This is more consistent, and the old code was problematic with regard to multiple blanks. Putting in additional quotes might have worked, but quotes inside of command substitution inside of quotes is nasty enough to not reliably work the same across "Bourne shells".

Signed-off-by: David Kastrup <dak@gnu.org>
---
 git-sh-setup.sh |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/git-sh-setup.sh b/git-sh-setup.sh
index 3c0367d..3c50bc1 100755
--- a/git-sh-setup.sh
+++ b/git-sh-setup.sh
@@ -29,7 +29,8 @@ set_reflog_action() {
 }
 
 git_editor() {
-	GIT_EDITOR=${GIT_EDITOR:-$(git config core.editor || echo ${VISUAL:-${EDITOR}})}
+	: "${GIT_EDITOR:=$(git config core.editor)}"
+	: "${GIT_EDITOR:=${VISUAL:-${EDITOR}}}"
 	case "$GIT_EDITOR,$TERM" in
 	,dumb)
 		echo >&2 "No editor specified in GIT_EDITOR, core.editor, VISUAL,"
@@ -40,7 +41,7 @@ git_editor() {
 		exit 1
 		;;
 	esac
-	${GIT_EDITOR:-vi} "$1"
+	eval "${GIT_EDITOR:=vi}" '"$@"'
 }
 
 is_bare_repository () {
-- 
1.5.3.rc2.86.gdc7ba
Previous: Junio C HamanoNext: David Kastrup
Message 7 of 16 in “Interpreting EDITOR/VISUAL environment variables.”
  1. David KastrupAug 1, 2007
  2. Junio C HamanoAug 1, 2007
  3. Yann DirsonAug 1, 2007
  4. David KastrupAug 1, 2007
  5. David KastrupAug 1, 2007
  6. Junio C HamanoAug 1, 2007
  7. git-sh-setup.sh: make GIT_EDITOR/core.editor/VISUAL/EDITOR accept commandsDavid Kastrup, Aug 1, 2007
  8. David KastrupAug 1, 2007
  9. git-sh-setup.sh: make GIT_EDITOR/core.editor/VISUAL/EDITOR accept commandsDavid Kastrup, Aug 1, 2007
  10. Junio C HamanoAug 1, 2007
  11. Junio C HamanoAug 1, 2007
  12. David KastrupAug 1, 2007
  13. Junio C HamanoAug 2, 2007
  14. David KastrupAug 1, 2007
  15. Matthias LederhoferAug 2, 2007
  16. David KastrupAug 2, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.