add fallback behavior to editor

This commit is contained in:
Jeremiah S 2024-08-21 22:39:33 -04:00 committed by Jermeiah S
parent f6291c5935
commit 08c95b98a1
No known key found for this signature in database

View file

@ -157,7 +157,17 @@ function edit {
[ ! -f "$CLEARTEXT_FILE" ] || cp "$CLEARTEXT_FILE" "$CLEARTEXT_FILE.before" [ ! -f "$CLEARTEXT_FILE" ] || cp "$CLEARTEXT_FILE" "$CLEARTEXT_FILE.before"
[ -t 0 ] || EDITOR='cp /dev/stdin' if [ ! -t 0 ]; then
EDITOR='cp /dev/stdin'
else
COMMON_EDITORS=("${EDITOR}" "vim" "vi" "nvim" "nano")
for e in "${COMMON_EDITORS[@]}"; do
if command -v "$e" &> /dev/null; then
EDITOR="$e"
break
fi
done
fi
$EDITOR "$CLEARTEXT_FILE" $EDITOR "$CLEARTEXT_FILE"