-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqr
executable file
·40 lines (33 loc) · 969 Bytes
/
qr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env fish
# Generate a QR code from a file or input.
# With -w or --wifi flag, generate a qr code to connect to the current wifi network with the provided password.
argparse -n qr 't/text=' 'w/wifi=' -- $argv
if set -q _flag_w
# format should be:
# WIFI:T:WPA;S:ssid;P:password;;
echo "w/wifi flag is not yet implemented."
exit 1
end
set stdin (if not set -q _flag_t; and test "$argv[1]" = '-'; echo -n "yes"; end)
set head (if test "$stdin" = "yes"
c | head -1 -
else
if set -q _flag_t
echo $_flag_t[1]
else
head -1 $argv
end
end)
set append (string sub -l 16 $head | string replace --all --regex '[^a-zA-Z0-9]' '-')
set infile (mktemp --suffix=.$append.txt)
set outfile (mktemp --suffix=.$append.png)
if test "$stdin" = "yes"
cat >$infile
else if set -q _flag_t
echo "$_flag_t" >$infile
else
cat $argv >$infile
end
qrencode -r $infile -o $outfile -s 5
and open $outfile
rm $infile $outfile