Skip to content

Instantly share code, notes, and snippets.

@tygerbytes
Created August 17, 2021 17:17
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 tygerbytes/8f3bec947522e62737529a197b569b45 to your computer and use it in GitHub Desktop.
Save tygerbytes/8f3bec947522e62737529a197b569b45 to your computer and use it in GitHub Desktop.
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