From 29cc392dff3e93e48e0e2edd3ce11b405c66a95a Mon Sep 17 00:00:00 2001 From: 3wc <3wc.git@doesthisthing.work> Date: Thu, 31 Dec 2020 12:52:44 +0200 Subject: [PATCH] Prompt on `app .. config` if $EDITOR is un-set Closes #41 --- abra | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/abra b/abra index b0b9e67..248bfc6 100755 --- a/abra +++ b/abra @@ -684,6 +684,31 @@ sub_app_undeploy (){ sub_app_config (){ load_instance + if [ -z "$EDITOR" ]; then + warning "\$EDITOR not set; which text editor would you like to use?" + + EDITORS_ALL=(vi vim nano pico emacs) + declare -a EDITORS_AVAILABLE + + for EDITOR in "${EDITORS_ALL[@]}"; do + if type "$EDITOR" > /dev/null 2>&1; then + EDITORS_AVAILABLE+=("$EDITOR") + fi + done + + if [ ${#EDITORS_AVAILABLE[@]} = 0 ]; then + error "No text editors found! Are you using a magnetised needle? 🤪" + fi + + select EDITOR in "${EDITORS_AVAILABLE[@]}"; do + if [ 1 -le "$REPLY" ] && [ "$REPLY" -le ${#EDITORS_AVAILABLE[@]} ]; then + SERVER="$EDITOR" + success "Using '${EDITOR}'; Add 'export EDITOR=${EDITOR}' to your ~/.bashrc to set as default" + break + fi + done + fi + $EDITOR "$ENV_FILE" }