From 08c95b98a1bc65641e0d0776d24abd1da536da86 Mon Sep 17 00:00:00 2001 From: Jeremiah S Date: Wed, 21 Aug 2024 22:39:33 -0400 Subject: [PATCH] add fallback behavior to editor --- pkgs/agenix.sh | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pkgs/agenix.sh b/pkgs/agenix.sh index 3d0415e..7dbb9fb 100644 --- a/pkgs/agenix.sh +++ b/pkgs/agenix.sh @@ -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"