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 08c95b9
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pkgs/agenix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,17 @@ function edit {

[ ! -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"

Expand Down

0 comments on commit 08c95b9

Please sign in to comment.