Skip to content

Commit

Permalink
add fallback behavior to editor
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremiahSecrist committed Aug 22, 2024
1 parent f6291c5 commit f02160f
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkgs/agenix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit f02160f

Please sign in to comment.