QR Codes on the Command-Line

September 20, 2019

Why QR codes?

hello world

QR codes aren’t magical, they boil down to:

but, for my own personal uses, it’s just one of the fastest way to securely transfer small amount of data, (e.g. URLs or passwords), from my computer to my phone.

To use QR codes, you don’t even need networking! It’s too bad that wifi network login was never widely adopted, it’s one of the most useful use cases for QR out there.

As of January 2018, iPhones have this feature (wifi network login) built into the camera app under iOS 11.x […]

Whoah… that wasn’t true when I started playing with this!
I just checked and it works 🤯

On the command-line

Get the qrencode package:

> brew install qrencode     # or use another package manager

To generate a QR code, dumping it to stdout as ASCII art:

> qrencode 'hello world' -t ANSIUTF8 -o -

qrencode example

but that’s a lot to type; put it in your dotfiles as a function:

> qr() { qrencode "$1" -t ANSIUTF8 -o -; }
# call as: qr 'hello world'

There’s a bunch of output formats: PNG, PNG32, EPS, SVG, XPM, ANSI, ANSI256, ASCII, ASCIIi, UTF8, ANSIUTF8. Feel free to experiment 😃

On the phone

I’m on iOS and I’ve been using Barcode. It gives you a contextual menu when it finds a QR code:

I hadn’t realized that QR codes can be read directly in the iOS camera app… thank you Apple! It’s a bit finicky (try it, you’ll see what I mean) but it works.

Discuss on Twitter