initial commit
This commit is contained in:
commit
ed08b701c3
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2025 Adam Douglas
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
|
@ -0,0 +1,127 @@
|
|||
# QR Share
|
||||
|
||||
Share text data between devices using a computer with GNU/Linux operating system, a camera and a quick response (QR) code.
|
||||
|
||||
**Features**
|
||||
|
||||
- Supports QR code output to the console (tty), terminal (pts) or graphical user interface (GUI)
|
||||
- Auto detects graphical environment, X.Org or Wayland
|
||||
- Clipboard access uses xclip (X.Org) or wl-paste (Wayland)
|
||||
- Text data sourced from clipboard or as a command argument
|
||||
- Shares Wi-Fi network QR code (pregenerated image)
|
||||
- Customize image viewer command along with arguments
|
||||
- Customize Wi-Fi image viewer command along with arguments
|
||||
|
||||
## Install
|
||||
|
||||
1. Install application dependencies.
|
||||
|
||||
Choose one of the applicable example commands below by operating system and display server, X.Org or Wayland.
|
||||
|
||||
**Arch Linux - X.Org**
|
||||
|
||||
```console
|
||||
# pacman -Sy qrencode xclip
|
||||
```
|
||||
|
||||
**Arch Linux - Wayland**
|
||||
|
||||
```console
|
||||
# pacman -Sy qrencode wl-clipboard
|
||||
```
|
||||
|
||||
**Fedora - X.Org**
|
||||
|
||||
```console
|
||||
# dnf install qrencode xclip
|
||||
```
|
||||
|
||||
**Fedora - Wayland**
|
||||
|
||||
```console
|
||||
# dnf install qrencode wl-clipboard
|
||||
```
|
||||
|
||||
**Debian/Ubuntu - X.Org**
|
||||
|
||||
```console
|
||||
# apt install qrencode xclip
|
||||
```
|
||||
|
||||
**Debian/Ubuntu - Wayland**
|
||||
```console
|
||||
# apt install qrencode wl-clipboard
|
||||
```
|
||||
|
||||
1. Download [QR Share](src/qrshare).
|
||||
1. Install QR Share.
|
||||
|
||||
Move QR Share to one of the following directories. Which ever directory you choose make sure it is found within the PATH environment variable to ensure the command works in all contexts.
|
||||
|
||||
**Accessible to a Specific User**
|
||||
|
||||
```console
|
||||
$ mv qrshare ~/.local/bin/
|
||||
```
|
||||
|
||||
**Accessible to All System Users**
|
||||
|
||||
```console
|
||||
# mv qrshare /usr/local/bin/
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
The user settings are configured within the qrshare command and can be altered by using a text editor. Each user setting is optional, but be aware if a setting is omitted functionality maybe limited. User-friendly error messages will tell you if a setting is missing. Here is a break-down of the available settings.
|
||||
|
||||
- wifiQRCode (optional): An absolute path to a pregenerated Wi-Fi QR code. The value must be enclosed in quotes.
|
||||
- wifiViewer (optional): The command name of a desired Wi-Fi image viewer (e.g. feh, kitten). The value must be enclosed in quotes.
|
||||
- wifiViewerArgs (optional): The associated image viewer arguments. Each argument must be enclosed in quotes and all the arguments must be surrounded by parentheses.
|
||||
- viewer (optional): The command name of a desired image viewer (e.g. feh, kitten). The value must be enclosed in quotes.
|
||||
- viewerArgs (optional): The associated image viewer arguments. Each argument must be enclosed in quotes and all the arguments must be surrounded by parentheses.
|
||||
|
||||
View the qrshare command in a text editor to see examples.
|
||||
|
||||
## Usage
|
||||
|
||||
**Generate QR code from Clipboard**
|
||||
|
||||
First copy text data to the clipboard within X.Org or Wayland and then run the following command to generate a QR code.
|
||||
|
||||
```console
|
||||
$ qrshare
|
||||
```
|
||||
|
||||
**Generate QR code from Argument**
|
||||
|
||||
Generating a QR code from an argument is simply achieved by typing out a text string in quotes after the command.
|
||||
|
||||
```console
|
||||
$ qrshare "Hello World!"
|
||||
```
|
||||
|
||||
**Display Wi-Fi QR Code**
|
||||
|
||||
In order to display a pregenerated Wi-Fi QR code QR Share requires three configuration options to be previously set, wifiQRCode, wifiViewer and wifiViewerArgs. Once the configuration has been completed, run one of the following command examples.
|
||||
|
||||
```console
|
||||
$ qrshare -w
|
||||
```
|
||||
```console
|
||||
$ qrshare --wifi
|
||||
```
|
||||
|
||||
**Display Help**
|
||||
|
||||
A simple help message can be displayed using one of the following commands.
|
||||
|
||||
```console
|
||||
$ qrshare -h
|
||||
```
|
||||
```console
|
||||
$ qrshare --help
|
||||
```
|
||||
|
||||
## Copyright License
|
||||
|
||||
Refer to the [LICENSE](LICENSE) file for details.
|
|
@ -0,0 +1,207 @@
|
|||
#!/usr/bin/env bash
|
||||
###### HEADER ######
|
||||
# Script Name : qrshare
|
||||
# Description : Share text data between devices using a computer with GNU/Linux operating system, a camera and a quick response (QR) code.
|
||||
# Author : Adam Douglas
|
||||
# License : MIT License Copyright (c) 2025 Adam Douglas
|
||||
# Date : 2025-03-27
|
||||
# Version : 1.0.0
|
||||
# Usage : bash qrshare
|
||||
# Dependencies : qrencode, tty, xclip (optional), wl-clipboard (optional)
|
||||
# Environment : GNU bash, version 5.2.37(1)-release (x86_64-pc-linux-gnu)
|
||||
###### END OF HEADER ######
|
||||
###### USER SETTINGS ######
|
||||
declare -r wifiQRCode="/home/adam/Pictures/wifi-network-sign.svg"
|
||||
### feh wi-fi image viewer
|
||||
# declare -r wifiViewer="feh"
|
||||
# declare -r wifiViewerArgs=("--force-aliasing" "-ZF")
|
||||
### Kitty kitten icat wi-fi image viewer
|
||||
declare -r wifiViewer="kitten"
|
||||
declare -r wifiViewerArgs=("icat")
|
||||
### ImageMagick display wi-fi image viewer
|
||||
# declare -r wifiViewer="display"
|
||||
### nsxiv wi-fi image viewer
|
||||
# declare -r wifiViewer="nsxiv"
|
||||
### Kitty kitten icat image viewer
|
||||
# declare -r viewer="kitten"
|
||||
# declare -r viewerArgs=("icat")
|
||||
### FIM (Fbi IMproved) image viewer
|
||||
# declare -r viewer="fim"
|
||||
# declare -r viewerArgs=("-i")
|
||||
### feh image viewer
|
||||
# declare -r viewer="feh"
|
||||
# declare -r viewerArgs=("-")
|
||||
##### END OF USER SETTINGS ######
|
||||
declare -a dependencies=("qrencode" "tty")
|
||||
|
||||
prepare() {
|
||||
setTermType
|
||||
setClipboardDependency
|
||||
checkDependencies
|
||||
getShareText "$1"
|
||||
validateShareText
|
||||
}
|
||||
|
||||
setTermType() {
|
||||
termType=''
|
||||
if [[ "$(tty)" == *tty* ]]
|
||||
then
|
||||
termType="tty"
|
||||
fi
|
||||
}
|
||||
|
||||
setClipboardDependency() {
|
||||
if [[ $termType != "tty" ]]
|
||||
then
|
||||
if [ -n "$WAYLAND_DISPLAY" ]
|
||||
then
|
||||
dependencies+=("wl-paste")
|
||||
else
|
||||
dependencies+=("xclip")
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
checkDependencies() {
|
||||
for i in "${dependencies[@]}";
|
||||
do
|
||||
checkCmdExists "$i"
|
||||
done
|
||||
|
||||
if [ -n "$viewer" ]
|
||||
then
|
||||
checkCmdExists "$viewer"
|
||||
elif [ -n "$wifiViewer" ]
|
||||
then
|
||||
checkCmdExists "$wifiViewer"
|
||||
fi
|
||||
|
||||
if [ -n "$cmdNotFound" ]
|
||||
then
|
||||
quit "Error: The following command(s) where not found:${cmdNotFound::-1}."
|
||||
fi
|
||||
}
|
||||
|
||||
checkCmdExists() {
|
||||
if ! [ -x "$(command -v "$1")" ]
|
||||
then
|
||||
cmdNotFound="$cmdNotFound $1,"
|
||||
fi
|
||||
}
|
||||
|
||||
getClipboardContent() {
|
||||
if [ -n "$WAYLAND_DISPLAY" ]
|
||||
then
|
||||
shareText="$(wl-paste -p)"
|
||||
else
|
||||
shareText="$(xclip -o)"
|
||||
fi
|
||||
}
|
||||
|
||||
getShareText() {
|
||||
if [ -n "$1" ]
|
||||
then
|
||||
shareText="${1}"
|
||||
elif [[ $termType != "tty" ]]
|
||||
then
|
||||
getClipboardContent
|
||||
fi
|
||||
}
|
||||
|
||||
checkFileExists() {
|
||||
if [ ! -e "$wifiQRCode" ]
|
||||
then
|
||||
quit "Error: The Wi-Fi QR code pregenerated image path setting ($wifiQRCode) is not accessible or doesn't exist."
|
||||
fi
|
||||
}
|
||||
|
||||
validateShareText() {
|
||||
if [ -z "$shareText" ]
|
||||
then
|
||||
quit "Error: Text data not provided or the clipboard is empty."
|
||||
fi
|
||||
}
|
||||
|
||||
validateWifiQRCode() {
|
||||
if [ "$termType" == "tty" ]
|
||||
then
|
||||
quit "Error: Unable to display Wi-Fi QR code in the console."
|
||||
elif [ -z "$wifiQRCode" ]
|
||||
then
|
||||
quit "Error: Wi-Fi QR code pregenerated image path setting has not been set."
|
||||
elif [ -z "$wifiViewer" ]
|
||||
then
|
||||
quit "Error: Wi-Fi QR code image viewer has not been set."
|
||||
else
|
||||
checkFileExists
|
||||
fi
|
||||
}
|
||||
|
||||
displayWifiQRCode() {
|
||||
validateWifiQRCode
|
||||
"$wifiViewer" "${wifiViewerArgs[@]}" "$wifiQRCode" || quit "Error: failed to display Wi-Fi QR code."
|
||||
}
|
||||
|
||||
displayQRCode() {
|
||||
if [ -n "$viewer" ] && [ "$termType" != "tty" ]
|
||||
then
|
||||
qrencode -s 8 -o - "$shareText" | $viewer "${viewerArgs[@]}" || quit "Error: failed to generate or display QR code."
|
||||
else
|
||||
qrencode -t utf8 -o - "$shareText" || quit "Error: failed to generate or display QR code."
|
||||
fi
|
||||
}
|
||||
|
||||
displayHelp() {
|
||||
printf "%b\n" "USAGE
|
||||
qrshare
|
||||
or qrshare [TEXT]
|
||||
or qrshare [OPTION]
|
||||
|
||||
DESCRIPTION
|
||||
Dynamically generate and display a QR code to share text data to camera enabled
|
||||
devices. If no text data or option is provided then the clipboard will
|
||||
be used.
|
||||
|
||||
OPTIONS
|
||||
-w, --wifi
|
||||
display Wi-Fi network QR code (pregenerated image).
|
||||
-h, --help
|
||||
display this help message and exit.
|
||||
|
||||
EXAMPLES
|
||||
qrshare
|
||||
Generate a QR code using text data from the clipboard (X.Org or Wayland).
|
||||
qrshare \"Hello World!\"
|
||||
Generate a QR code using text data from the argument.
|
||||
qrshare -w
|
||||
Display pregenerated Wi-Fi QR code image.
|
||||
"
|
||||
}
|
||||
|
||||
run() {
|
||||
prepare "$1"
|
||||
case "$1" in
|
||||
-w|--wifi)
|
||||
displayWifiQRCode
|
||||
;;
|
||||
-h|--help)
|
||||
displayHelp
|
||||
;;
|
||||
*)
|
||||
displayQRCode
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
quit() {
|
||||
if [ "$1" = 0 ]
|
||||
then
|
||||
exit 0
|
||||
else
|
||||
printf "%b\n" "$1"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
run "$1"
|
||||
quit 0
|
Loading…
Reference in New Issue