From 9816ddd5360334ec0345fed8eb13e968c94fd599 Mon Sep 17 00:00:00 2001 From: Alexander Gehrke Date: Tue, 16 Jul 2024 01:26:00 +0200 Subject: [PATCH] new script: qrread --- misc/qrread | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100755 misc/qrread diff --git a/misc/qrread b/misc/qrread new file mode 100755 index 0000000..cd34f7e --- /dev/null +++ b/misc/qrread @@ -0,0 +1,51 @@ +#!/bin/zsh + +#dep:flameshot zbarimg zenity + +code_content=$(flameshot gui --accept-on-select --raw | zbarimg -1 --raw /dev/stdin) + +zenity-ask-clip() { + local title="$1" + local text="$2" + shift 2 + zenity --question --title "$title" \ + --text="$text" \ + --switch \ + "$@" \ + --extra-button "Copy to clipboard" \ + --extra-button "Close" +} + +handle-link() { + case $(zenity-ask-clip "Link detected" "$1" --extra-button "Open in browser") in + "Open in browser") + xdg-open $1 + ;; + "Copy to clipboard") + xclip -selection clipboard -i <(echo $1) + ;; + *) + exit 0 + ;; + esac +} + +handle-other() { + case $(zenity-ask-clip "Code contents" "$1") in + "Copy to clipboard") + xclip -selection clipboard -i <(echo $1) + ;; + *) + exit 0 + ;; + esac +} + +case $code_content in + http*) + handle-link $code_content + ;; + *) + handle-other $code_content + ;; +esac