Skip to content

Instantly share code, notes, and snippets.

@feklee
Last active April 15, 2021 04:47
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 feklee/5bf542ce5051da0ff79aaa9eeb18d400 to your computer and use it in GitHub Desktop.
Save feklee/5bf542ce5051da0ff79aaa9eeb18d400 to your computer and use it in GitHub Desktop.
Easily view encrypted files
#!/bin/bash
# Felix E. Klee <felix.klee@inka.de>
# 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