Skip to content

Instantly share code, notes, and snippets.

@kepocnhh
Last active May 1, 2023 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kepocnhh/49fb57c2e035d92e65f6ab5b39d96ac1 to your computer and use it in GitHub Desktop.
Save kepocnhh/49fb57c2e035d92e65f6ab5b39d96ac1 to your computer and use it in GitHub Desktop.
Copy to clipboard parsed decrypted.
#!/usr/local/bin/bash
if test $# -ne 2; then
echo "Script needs 2 arguments: ENCRYPTED, KEY. But actual is $#!"; exit 1; fi
ENCRYPTED="$1"
KEY="$2"
for it in ENCRYPTED KEY; do
if test -z "${!it}"; then echo "Argument \"$it\" is empty!"; exit 1; fi; done
if [[ ! -f "$ENCRYPTED" ]]; then echo "File \"$ENCRYPTED\" does not exist!"; exit 1
elif [[ ! -s "$ENCRYPTED" ]]; then echo "File \"$ENCRYPTED\" is empty!"; exit 1; fi
echo "Enter password:"
read -rs PASSWORD
DECRYPTED="$(gpg --batch -qd --passphrase "$PASSWORD" "$ENCRYPTED")"
if test $? -ne 0; then echo "Decrypt \"$ENCRYPTED\" error!"; exit 1
elif test -z "$DECRYPTED"; then echo "Decrypted is empty!"; exit 1; fi
RESULT="$(echo "$DECRYPTED" | yq -rMe -o=json "$KEY")"
if test $? -ne 0; then echo "Parse decrypted error!"; exit 1
elif test -z "$RESULT"; then echo "Result is empty!"; exit 1; fi
echo -n "$RESULT" | pbcopy
if test $? -ne 0; then
echo "Copy parsed error!"; exit 1; fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment