Created
August 17, 2021 17:17
-
-
Save tygerbytes/8f3bec947522e62737529a197b569b45 to your computer and use it in GitHub Desktop.
Generate QR code
This file contains 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
#!/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