Skip to content

Instantly share code, notes, and snippets.

@iamFIREcracker
Forked from zacharyvoase/qr_codify.py
Last active December 15, 2015 21:29
Show Gist options
  • Save iamFIREcracker/5325912 to your computer and use it in GitHub Desktop.
Save iamFIREcracker/5325912 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Utility script which creates and display a QR code with the content of
# positional arguments or with everything stored within the WM clipboard.
#
# Depends on xclip, curl and xdg-open
set -e
TEMP=""
cleanup_exit() {
rm -rf "$TEMP"
}
# Remove temporary files even if we get interrupted
trap "cleanup_exit" 0
trap "exit 255" HUP INT QUIT ABRT TERM
TEMP=$(mktemp --suffix=.png)
[ x$TEMP != x ] || {
echo "Could not create temporary file! Exiting." 1>&2
exit 1
}
[ $# != 0 ] && DATA="$@" || DATA=$(xclip -o)
URL="http://chart.apis.google.com/chart?cht=qr&chs=400x400&chl=${DATA}&chld=H|0"
echo $URL
curl -L $URL > $TEMP
xdg-open $TEMP
# Wait for the sub-process to successfully open the image
sleep 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment