Assimilate QR Code in your Linux workflow

1. Script to generate qrcode for easy sharing of data

How much have integrated QRCodes into your lives?

For the lazy slobs like me, sharing data as trivial as a string of text ( passwords, email ids,contents of a short file, extract of logs or any sorts of strings) from you the system to your smartphone can be a tiring task. The prevalent solution is of course setting up a LAN or via internet ( sync devices, cloud storage etc).

If your needs are only limited to sharing text from your PC to your smartphone, you don't need no internt or LAN to share those data. Just convert them to QRCodes and scan them.

This function does all that for me.

Dependencies:

  • qrencode ( to actually generate the qrcode)
  • imagemagick ( to display the qrcode )
  • xclip

qrcode() {
    [[ $1 =~ ^f$ ]] && qrencode -l H --size 10  -r $2 -o - | display -geometry +200+200 -title "from $2" - 2>/dev/null  && return
    [[ $1 =~ ^(p|c|s)$ ]] || { echo -e "${1}" | qrencode -l H --size 10 -o - | display -geometry +200+200 -title "$1" - 2>/dev/null && return }
    xclip -o -sel $1 | qrencode -l H --size 10 -o - | display -geometry +200+200 -title "from clipboard" - 2>/dev/null  ;
}

examples:

  • To generate a qrcode for the string "mY-AlpHa9uM3riCPaSsW0r4":
    • qrcode "mY-AlpHa9uM3riCPaSsW0r4"
  • It even generates qrcode from the content of the clipboard:

    • qrcode c # from the clip
    • qrcode p # from the primary
    • qrcode s # from the secondary

2. Script to generate qrcode of email

Dependencies:

  • abook
  • qrencode
  • imagemagick
email=$(abook --mutt-query $1 | cut -f1)
h="$HOME/.abook"

#generate an image of the text
convert -size 276x40 -pointsize 18  -gravity center "label:$email" ~/.abook/t.svg

#generate the qrcode
qrencode "$email" -l H --size 10 -o $h/q.png

#append the image to the qrcode
convert -append $h/t.svg $h/q.png $h/f.png

#display the image
display -geometry +200+200 $h/f.png 2>/dev/null

you can make changes to it depending on your taste and needs.