Skip to content

Commit

Permalink
home-manager: Check VISUAL before EDITOR for editor
Browse files Browse the repository at this point in the history
Check VISUAL for a visual editor before EDITOR, as per Unix convention
and as followed by Git, crontab, mutt, and other tools.
  • Loading branch information
srstevenson authored Feb 5, 2024
1 parent 3c6f2dd commit b319781
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/home-manager.1
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 9 additions & 5 deletions home-manager/home-manager
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."
Expand Down

0 comments on commit b319781

Please sign in to comment.