diff --git a/pkgs/agenix.sh b/pkgs/agenix.sh index 3d0415e..6e95b04 100644 --- a/pkgs/agenix.sh +++ b/pkgs/agenix.sh @@ -152,11 +152,21 @@ function edit { CLEARTEXT_DIR=$(@mktempBin@ -d) CLEARTEXT_FILE="$CLEARTEXT_DIR/$(basename "$FILE")" DEFAULT_DECRYPT+=(-o "$CLEARTEXT_FILE") + COMMON_EDITORS=("${EDITOR}" "vim" "vi" "nvim" "nano") decrypt "$FILE" "$KEYS" || exit 1 [ ! -f "$CLEARTEXT_FILE" ] || cp "$CLEARTEXT_FILE" "$CLEARTEXT_FILE.before" + # Loop through common editors and check if they exist + # Even if their editor is incorrectly set we want to try to still work + for e in "${COMMON_EDITORS[@]}"; do + if command -v "$e" &> /dev/null; then + EDITOR="$e" + break + fi + done + [ -t 0 ] || EDITOR='cp /dev/stdin' $EDITOR "$CLEARTEXT_FILE"