From b319781e304c668da0ef144b1b4ee48977d4877d Mon Sep 17 00:00:00 2001 From: Scott Stevenson Date: Mon, 5 Feb 2024 22:22:43 +0000 Subject: [PATCH] home-manager: Check VISUAL before EDITOR for editor Check VISUAL for a visual editor before EDITOR, as per Unix convention and as followed by Git, crontab, mutt, and other tools. --- docs/home-manager.1 | 2 +- home-manager/home-manager | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/docs/home-manager.1 b/docs/home-manager.1 index 1747735e1..41406aca0 100644 --- a/docs/home-manager.1 +++ b/docs/home-manager.1 @@ -97,7 +97,7 @@ Instantiate the configuration and print the resulting derivation\&. .It Cm edit .RS 16 -Open the home configuration using the editor indicated by \fBEDITOR\fR\&. +Open the home configuration using the editor indicated by \fBVISUAL\fR or \fBEDITOR\fR\&. .RE .Pp diff --git a/home-manager/home-manager b/home-manager/home-manager index eb69530a8..ba3b8d98e 100644 --- a/home-manager/home-manager +++ b/home-manager/home-manager @@ -565,10 +565,14 @@ function presentNews() { } function doEdit() { - if [[ ! -v EDITOR || -z $EDITOR ]]; then - # shellcheck disable=2016 - _i 'Please set the $EDITOR environment variable' >&2 - return 1 + if [[ ! -v VISUAL || -z $VISUAL ]]; then + if [[ ! -v EDITOR || -z $EDITOR ]]; then + # shellcheck disable=2016 + _i 'Please set the $EDITOR or $VISUAL environment variable' >&2 + return 1 + fi + else + EDITOR=$VISUAL fi setConfigFile @@ -881,7 +885,7 @@ function doHelp() { echo echo " help Print this help" echo - echo " edit Open the home configuration in \$EDITOR" + echo " edit Open the home configuration in \$VISUAL or \$EDITOR" echo echo " option OPTION.NAME" echo " Inspect configuration option named OPTION.NAME."