Skip to content

Commit

Permalink
Merge pull request #63 from ldesgoui/edit-force
Browse files Browse the repository at this point in the history
Add --force to the edit command
  • Loading branch information
oddlama authored Jan 9, 2025
2 parents 3e2b748 + 7099089 commit 8cd512c
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion apps/edit.nix
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ pkgs.writeShellScriptBin "agenix-edit" ''
echo '-h, --help Show help'
echo '-i, --input INFILE Instead of editing FILE with $EDITOR, directly use the'
echo ' content of INFILE and encrypt it to FILE.'
echo '-f, --force Always write out the file, regardless if the contents are unchanged.'
echo ' Can be useful if you'"'"'re adding masterIdentities.'
echo ""
echo 'FILE An age-encrypted file to edit or a new file to create.'
echo ' If not given, a fzf selector of used secrets will be shown.'
Expand All @@ -54,6 +56,7 @@ pkgs.writeShellScriptBin "agenix-edit" ''
fi
POSITIONAL_ARGS=()
force=0
while [[ $# -gt 0 ]]; do
case "$1" in
"help"|"--help"|"-help"|"-h")
Expand All @@ -65,6 +68,9 @@ pkgs.writeShellScriptBin "agenix-edit" ''
[[ -f "$INFILE" ]] || die "Input file not found: '$INFILE'"
shift
;;
"--force"|"-f")
force=1
;;
"--")
shift
POSITIONAL_ARGS+=("$@")
Expand Down Expand Up @@ -142,7 +148,7 @@ pkgs.writeShellScriptBin "agenix-edit" ''
fi
shasum_after="$(sha512sum "$CLEARTEXT_FILE")"
if [[ "$shasum_before" == "$shasum_after" ]]; then
if [[ "$force" == 0 && "$shasum_before" == "$shasum_after" ]]; then
echo "No content changes, original is left unchanged."
exit 0
fi
Expand Down

0 comments on commit 8cd512c

Please sign in to comment.