Created
August 29, 2017 06:33
-
-
Save lpsmith/231f219fa21e756ea686283043ac3d10 to your computer and use it in GitHub Desktop.
Bash scripts for working with qr codes
This file contains hidden or 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 | |
| DECODEQR_TMPDIR=$(mktemp --tmpdir=$TMPDIR -d) | |
| if [ $? -eq 0 -a ! -z "$DECODEQR_TMPDIR" ]; then | |
| #mkfifo $DECODEQR_TMPDIR/tmp.png | |
| gnome-screenshot -f $DECODEQR_TMPDIR/tmp.png | |
| zbarimg --quiet $DECODEQR_TMPDIR/tmp.png | |
| rm -rf $DECODEQR_TMPDIR | |
| fi |
This file contains hidden or 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 | |
| ENCODEQR_TEMPDIR=$(mktemp --tmpdir=$TMPDIR -d) | |
| if [ $? -eq 0 -a ! -z $ENCODEQR_TEMPDIR ]; then | |
| if [ $# -eq 0 ]; then | |
| qrencode -o $ENCODEQR_TEMPDIR/tmpqrcode.png < /dev/stdin | |
| else | |
| qrencode -o $ENCODEQR_TEMPDIR/tmpqrcode.png "$*" < /dev/stdin | |
| fi | |
| eog -n $ENCODEQR_TEMPDIR/tmpqrcode.png | |
| rm -rf $ENCODEQR_TEMPDIR | |
| fi |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
decodeqrdecodes any qr codes currently displayed on the screen, writing the result(s) to stdout. If nothing is found, then nothing is written to stdout. This depends ongnome-screenshotand thezbar-toolspackages on Ubuntu.encodeqrgenerates a qr code and displays it, temporarily. The content of the qr code can be specified either via command line arguments or via stdin; see the documentation forqrencodefor more info. This depends on theqrencodeandeogpackages on Ubuntu.For security reasons, ideally
TMPDIRwould be on a memory-only filesystem such as tmpfs. Note that at least on linux, if theTMPDIRenvironment variable is empty thenmktempwill default to creating a temporary directory inside/tmp.One could avoid writing the screen captures or temporary images to a file by using a fifo, not sure why uncommenting the
mkfifoline (and startinggnome-screenshotin the background using&) doesn't work. Assuming you could find a way to get gnome-screenshot and zbarimg to agree on the file type, one could avoid named fifo's altogether viapipe(2)and/dev/fd, but I'm not sure how to accomplish that with my limited bash scripting skills.