-
Notifications
You must be signed in to change notification settings - Fork 0
/
yourl.sh
executable file
·66 lines (55 loc) · 2.05 KB
/
yourl.sh
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env bash
#----------------------------------------------------|
# Matheus Martins [email protected]
# https://github.com/mateuscomh/yoURL
# 30/03/2023 GPL3
# URL shortner and upload files from bash to 0x0.st.
# Deps: qrencode/zbar, curl, xclip, pbcopy (MacOS)
#----------------------------------------------------|
version='2.2.3'
logo="
██╗ ██╗ ██████╗ ██╗ ██╗██████╗ ██╗
╚██╗ ██╔╝██╔═══██╗██║ ██║██╔══██╗██║
╚████╔╝ ██║ ██║██║ ██║██████╔╝██║
╚██╔╝ ██║ ██║██║ ██║██╔══██╗██║
██║ ╚██████╔╝╚██████╔╝██║ ██║███████╗
╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝
"
usage="yourl.sh - URL shortner and upload files from bash to 0x0.st
Usage:
To short links:
yourl.sh 'URL' URL shortner by http://tinyurl.com
To sent files:
yourl.sh 'FILE' File sent to https://0x0.st
Options:
-h|--help Shows help and exit.
-v|--version Show running version and exit.
"
case "$1" in
'' | -h | --help)
echo "$logo $usage"
exit
;;
-v | --version)
echo "$version"
exit
;;
esac
if [[ -f "$1" ]]; then
# If $1 is file
read -r <<<"$(curl -sF "file=@$1" https://0x0.st | sed -e "s/<.*//")"
else
# If $1 is a url
read -r <<<"$(curl -s http://tinyurl.com/api-create.php?url="$1")"
fi
# Validate read input and exit if error
[[ -z "$REPLY" || "$REPLY" = 'Error' ]] && exit 1
# Print url shorted on bash
echo "$logo URL created:"
command -v qrencode &>/dev/null && qrencode -m 2 -t ANSIUTF8 "$REPLY"
echo "$REPLY"
# Send a shorted url to clippboard Linux/MacOS
case $(command -v xclip &>/dev/null && echo "xclip" || echo "pbcopy") in
xclip) echo -n "$REPLY" | xclip -sel copy ;;
pbcopy) echo -n "$REPLY" | pbcopy 2>/dev/null ;;
esac