Last active
April 15, 2021 04:47
-
-
Save feklee/5bf542ce5051da0ff79aaa9eeb18d400 to your computer and use it in GitHub Desktop.
Easily view encrypted files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Felix E. Klee <[email protected]> | |
# Usage info | |
show_help() { | |
cat << EOF | |
Usage: ${0##*/} ENCRYPTED.gpg | |
Decrypts ENCRYPTED.gpg and displays its contents. | |
EOF | |
} | |
if [ "$#" -ne 1 ] | |
then | |
show_help >&2 | |
exit 1 | |
fi | |
show_unknown_format_error() { | |
echo "Don't what to do with $FILENAME" | |
} | |
FILENAME="$1" | |
if [[ "$FILENAME" != *.gpg ]] | |
then | |
show_unknown_format_error >&2 | |
exit 1 | |
fi | |
BASENAME=$(basename "$FILENAME" .gpg) | |
EXTENSION=${BASENAME##*.} | |
case $EXTENSION in | |
pdf|PDF) | |
echo "The file will be decrypted temporarily to /tmp" | |
read -p "Continue? " -n 1 -r | |
echo # (optional) move to a new line | |
if [[ $REPLY =~ ^[Yy]$ ]] | |
then | |
gpg -d "$FILENAME" | zathura - | |
fi | |
;; | |
jpg|JPG|jpeg|JPEG) | |
gpg -d "$FILENAME" | \ | |
display -auto-orient -resize 1024x768 -immutable \ | |
-geometry 1024x768-0+0 | |
;; | |
*) | |
show_unknown_format_error >&2 | |
exit 1 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment