From 580c5b5e1d1146b65347f71de038f7d9bf3563c4 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Mon, 19 Feb 2018 12:20:45 -0800 Subject: [PATCH] Beef up install.sh editor detection --- installer/install.sh | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/installer/install.sh b/installer/install.sh index 178731c..5ac04cc 100755 --- a/installer/install.sh +++ b/installer/install.sh @@ -386,9 +386,37 @@ else ## Verify that the specified editor program exists ##------------------------------------------------------- -DEFAULTEDITOR=${EDITOR:-‘/bin/vi’} -TWEDITOR=${TWEDITOR:-$DEFAULTEDITOR} -TWEDITOR_PATH=`command -v $TWEDITOR` +# If user specified an editor in $path_to_vi or $TWEDITOR, try that first. +# $path_to_vi defaults to /usr/bin/vi, so we usually succeed here. +# +if [ -n ${TWEDITOR} ]; then + TWEDITOR_PATH=`command -v $TWEDITOR` +fi + +# If user's environment includes $EDITOR, try that next +if [ -n ${EDITOR} ] && [ -z ${TWEDITOR_PATH} ]; then + TWEDITOR_PATH=`command -v $EDITOR` +fi + +# Ok, now search path for vi +if [ -z ${TWEDITOR_PATH} ]; then + TWEDITOR_PATH=`command -v vi` +fi + +# Try vim in case there isn't a link named vi +if [ -z ${TWEDITOR_PATH} ]; then + TWEDITOR_PATH=`command -v vim` +fi + +# No vi/vim? See if nano is present +if [ -z ${TWEDITOR_PATH} ]; then + TWEDITOR_PATH=`command -v nano` +fi + +# No vi or nano? See if emacs is available +if [ -z ${TWEDITOR_PATH} ]; then + TWEDITOR_PATH=`command -v emacs` +fi if [ -n ${TWEDITOR_PATH} ]; then TWEDITOR=$TWEDITOR_PATH