Skip to content

Instantly share code, notes, and snippets.

@tygerbytes
Created Aug 17, 2021
Embed
What would you like to do?
Generate QR code
#!/usr/bin/env zsh
# Make sure we have all the utilities we need
requiredBins=('qrencode' 'feh')
if [[ `uname` == "Darwin" ]]; then
requiredBins+=("pbpaste")
else
requiredBins+=("xclip")
fi
missingBins=()
for cmd in $requiredBins
do
if ! which $cmd > /dev/null; then
missingBins+=($cmd)
fi
done
if [ ${#missingBins[@]} -gt 0 ]; then
IFS=","
echo "OOPS! Missing $missingBins"
exit 1
fi
# Clipboard paste function which works on Mac and Linux
paste() {
if which pbpaste > /dev/null; then
pbpaste
else
xclip -selection clipboard -o
fi
}
# Try using the command line argument as the QR source text
sourceText=$1
if (( # == 0 )); then
# No argument. Grab from clipboard instead
sourceText=$(paste)
fi
# Convert the text to a QR code and display it with feh
echo $sourceText | qrencode --size=15 -o - | feh -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment