1
0
mirror of https://github.com/morrownr/8821cu-20210916.git synced 2024-12-21 22:06:32 +00:00

Converted to non-Bash editor searching

This commit is contained in:
Miles Goodhew 2023-01-25 21:45:40 +11:00
parent 8c202dd766
commit 08c72e9cb4
2 changed files with 6 additions and 16 deletions

View File

@ -26,8 +26,7 @@
SCRIPT_NAME="edit-options.sh" SCRIPT_NAME="edit-options.sh"
SCRIPT_VERSION="20230120" SCRIPT_VERSION="20230120"
OPTIONS_FILE="8821cu.conf" OPTIONS_FILE="8821cu.conf"
DEFAULT_EDITOR="$(<default-editor.txt)" DEFAULT_EDITOR="$(cat default-editor.txt)"
EDITORS_SEARCH=("${VISUAL}" "${EDITOR}" "${DEFAULT_EDITOR}" "vi")
if [[ $EUID -ne 0 ]] if [[ $EUID -ne 0 ]]
then then
@ -37,13 +36,9 @@ then
fi fi
# Try to find the user's default text editor through the EDITORS_SEARCH array # Try to find the user's default text editor through the EDITORS_SEARCH array
for editor in ${EDITORS_SEARCH[@]} for TEXT_EDITOR in "${VISUAL}" "${EDITOR}" "${DEFAULT_EDITOR}" vi;
do do
if command -v "${editor}" >/dev/null 2>&1 command -v "${TEXT_EDITOR}" >/dev/null 2>&1 && break
then
TEXT_EDITOR="${editor}"
break
fi
done done
# Fail if no editor was found # Fail if no editor was found

View File

@ -38,8 +38,7 @@ OPTIONS_FILE="${MODULE_NAME}.conf"
SMEM=$(LANG=C free | awk '/Mem:/ { print $2 }') SMEM=$(LANG=C free | awk '/Mem:/ { print $2 }')
sproc=$(nproc) sproc=$(nproc)
DEFAULT_EDITOR="$(<default-editor.txt)" DEFAULT_EDITOR="$(cat default-editor.txt)"
EDITORS_SEARCH=("${VISUAL}" "${EDITOR}" "${DEFAULT_EDITOR}" "vi")
# check to ensure sudo was used # check to ensure sudo was used
if [[ $EUID -ne 0 ]] if [[ $EUID -ne 0 ]]
@ -99,13 +98,9 @@ then
fi fi
# Try to find the user's default text editor through the EDITORS_SEARCH array # Try to find the user's default text editor through the EDITORS_SEARCH array
for editor in ${EDITORS_SEARCH[@]} for TEXT_EDITOR in "${VISUAL}" "${EDITOR}" "${DEFAULT_EDITOR}" vi;
do do
if command -v "${editor}" >/dev/null 2>&1 command -v "${TEXT_EDITOR}" >/dev/null 2>&1 && break
then
TEXT_EDITOR="${editor}"
break
fi
done done
# Fail if no editor was found # Fail if no editor was found