From 98c6390ede6a191ef5cf4bd4da39b198cc99d78f Mon Sep 17 00:00:00 2001 From: erik Date: Sun, 12 Jul 2026 21:32:12 +0200 Subject: [PATCH] fix(edit_secrets): guarantee a working editor (bundle nano, --wait for GUI) --- edit_secrets | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/edit_secrets b/edit_secrets index ff4af0f..74bbf36 100755 --- a/edit_secrets +++ b/edit_secrets @@ -31,6 +31,20 @@ done if [ "$show" -eq 1 ]; then exec nix shell nixpkgs#sops -c sops --decrypt "$file" -else - exec nix shell nixpkgs#sops -c sops "$file" fi + +# sops opens $EDITOR on a temp file and re-encrypts only if it changed. +# Pitfalls that cause "File has not changed, exiting": +# - $EDITOR unset: no editor is on the `nix shell` PATH -> bundle one. +# - GUI editor (code/zed) forks and returns instantly -> force --wait. +editor="${VISUAL:-${EDITOR:-}}" +extra=() +case "$editor" in + "") editor="nano"; extra=(nixpkgs#nano) ;; # sane default, bundled + code|code\ *) editor="code --wait" ;; # VS Code must block + codium|codium\ *) editor="codium --wait" ;; + zed|zed\ *) editor="zed --wait" ;; +esac + +export EDITOR="$editor" +exec nix shell nixpkgs#sops "${extra[@]}" -c sops "$file"