diff --git a/default-editor b/default-editor.txt similarity index 100% rename from default-editor rename to default-editor.txt diff --git a/edit-options.sh b/edit-options.sh index 05c5bb2..7316127 100755 --- a/edit-options.sh +++ b/edit-options.sh @@ -26,7 +26,8 @@ SCRIPT_NAME="edit-options.sh" SCRIPT_VERSION="20230120" OPTIONS_FILE="8821cu.conf" -DEFAULT_EDITOR=`cat default-editor` +DEFAULT_EDITOR="$(/dev/null 2>&1 +# Try to find the user's default text editor through the EDITORS_SEARCH array +for editor in ${EDITORS_SEARCH[@]} +do + if command -v "${editor}" >/dev/null 2>&1 + then + TEXT_EDITOR="${editor}" + break + fi +done + +# Fail if no editor was found +if ! command -v "${TEXT_EDITOR}" >/dev/null 2>&1 then - TEXT_EDITOR="${VISUAL}" -elif command -v "${EDITOR}" >/dev/null 2>&1 -then - TEXT_EDITOR="${EDITOR}" -elif command -v "${DEFAULT_EDITOR}" >/dev/null 2>&1 -then - TEXT_EDITOR="${DEFAULT_EDITOR}" -else echo "No text editor found (default: ${DEFAULT_EDITOR})." - echo "Please install ${DEFAULT_EDITOR} or edit the file 'default-editor' to specify your editor." + echo "Please install ${DEFAULT_EDITOR} or edit the file 'default-editor.txt' to specify your editor." echo "Once complete, please run \"sudo ./${SCRIPT_NAME}\"" exit 1 fi diff --git a/install-driver.sh b/install-driver.sh index ae7278a..be46e2e 100755 --- a/install-driver.sh +++ b/install-driver.sh @@ -38,7 +38,8 @@ OPTIONS_FILE="${MODULE_NAME}.conf" SMEM=$(LANG=C free | awk '/Mem:/ { print $2 }') sproc=$(nproc) -DEFAULT_EDITOR=`cat default-editor` +DEFAULT_EDITOR="$(/dev/null 2>&1 +# Try to find the user's default text editor through the EDITORS_SEARCH array +for editor in ${EDITORS_SEARCH[@]} +do + if command -v "${editor}" >/dev/null 2>&1 + then + TEXT_EDITOR="${editor}" + break + fi +done + +# Fail if no editor was found +if ! command -v "${TEXT_EDITOR}" >/dev/null 2>&1 then - TEXT_EDITOR="${VISUAL}" -elif command -v "${EDITOR}" >/dev/null 2>&1 -then - TEXT_EDITOR="${EDITOR}" -elif command -v "${DEFAULT_EDITOR}" >/dev/null 2>&1 -then - TEXT_EDITOR="${DEFAULT_EDITOR}" -else echo "No text editor found (default: ${DEFAULT_EDITOR})." - echo "Please install ${DEFAULT_EDITOR} or edit the file 'default-editor' to specify your editor." + echo "Please install ${DEFAULT_EDITOR} or edit the file 'default-editor.txt' to specify your editor." echo "Once complete, please run \"sudo ./${SCRIPT_NAME}\"" exit 1 fi