From 1b32e0e6b8dba3c239703af57a39ff0afc686e41 Mon Sep 17 00:00:00 2001 From: tavo-wasd Date: Fri, 3 May 2024 14:15:16 -0600 Subject: [PATCH] qr scan --- scripts/anypinentry | 3 +++ scripts/contact | 3 +++ scripts/qr-scan | 49 +++++++++++++++++++++++++++++++++++++++++++++ shell/aliasrc | 1 - 4 files changed, 55 insertions(+), 1 deletion(-) create mode 100755 scripts/qr-scan diff --git a/scripts/anypinentry b/scripts/anypinentry index 8442b0c..8b2a061 100755 --- a/scripts/anypinentry +++ b/scripts/anypinentry @@ -1,5 +1,8 @@ #!/bin/sh # Ref: http://info2html.sourceforge.net/cgi-bin/info2html-demo/info2html?%28pinentry%29Protocol +# +# $ printf 'pinentry-program /home/tavo/.config/scripts/anypinentry' > ~/.gnupg/gpg-agent.conf +# $ gpg-agent reload set -e diff --git a/scripts/contact b/scripts/contact index 5bf935c..e875cfb 100755 --- a/scripts/contact +++ b/scripts/contact @@ -1,6 +1,9 @@ #!/bin/sh VDIR="$HOME/.local/share/contacts" +STDIN="$(cat)" +[ -n "$STDIN" ] && printf '%s' "$STDIN" > "$VDIR/temp-contact.vcf" + QUERY="$(grep -r '^FN:' "$VDIR" | sed 's/.*://' | tr -d '\r' | menu "Contact:")" [ -z "$QUERY" ] && exit 0 FILE="$(grep -r "^FN:$QUERY" "$VDIR" | cut -d ':' -f 1)" diff --git a/scripts/qr-scan b/scripts/qr-scan new file mode 100755 index 0000000..d38a316 --- /dev/null +++ b/scripts/qr-scan @@ -0,0 +1,49 @@ +#!/bin/sh +FILE="$1" + +qr_code () { +[ -n "$1" ] && + ZBARCMD="zbarimg -q $1" || + ZBARCMD="zbarcam -q" + +$ZBARCMD | while read line ; do + printf '%s\n' "$line" + check="${line#*:}" ; check="${check%%:*}" + + case "$check" in + "BEGIN") multiline=1 ;; + "VCARD") multiline= ;; + esac + + [ "$multiline" != 1 ] && + pkill zbarcam && + return 0 + +done +} + +QRCODE="$(qr_code "$FILE" 2>/dev/null)" +QRCODE="${QRCODE#*:}" +QRTYPE="${QRCODE%%:*}" + +case "$QRTYPE" in + "http"|"https"|"gopher"|"gemini"|"ftp"|"ftps"|"sftp"|"ssh"|"git"|"www"|"magnet"|"xmpp"|"mailto"|"nc") + printf '%s\n' "$QRCODE" + printf '%s' "$QRCODE" | xsel -ib + break ;; + + "WIFI") + SSID="${QRCODE##*S:}" ; SSID="${SSID%%;[A-Za-z]:*}" + PASSW="${QRCODE##*P:}" ; PASSW="${PASSW%%;[A-Za-z]:*}" + wpa_passphrase "$SSID" "$PASSW" + break ;; + + "BEGIN") + printf '%s\n' "$QRCODE" + printf '%s' "$QRCODE" | contact + break ;; + + *) + printf '%s\n' "$QRCODE" + break ;; +esac diff --git a/shell/aliasrc b/shell/aliasrc index 40d901d..d505cb0 100644 --- a/shell/aliasrc +++ b/shell/aliasrc @@ -29,7 +29,6 @@ alias \ # Command shortcuts alias \ - claws-mail='HOME="$XDG_DATA_HOME"/claws-mail && mkdir -p "$HOME" && claws-mail' \ mgr-all="mgr pacman_upgrade apt_upgrade flatpak_update distrobox_update pip_update configs passmgr" \ df-short="df -h | grep -v '\s/dev.*$\|\s/run.*$\|\s/boot.*$'" \ wacom-setup-menu="wacom-setup menu" \