-
Notifications
You must be signed in to change notification settings - Fork 4
/
yourls
69 lines (61 loc) · 1.56 KB
/
yourls
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
67
68
#!/usr/bin/env bash
# Configure these 2 lines and leave the rest
YOURLS_HOST="https://sho.rt/"
YOURLS_KEY="eb9444558f" # see sho.rt/admin/tools.php
yourls_help() {
echo "Shorten URLs with YOURLS"
echo
echo "Usage:"
echo " ${0##*/} <url>"
echo " ${0##*/} <url> -k <KEYWORD> -t <TITLE> -f <FORMAT>"
echo " ${0##*/} <url> --help"
echo
echo "Options:"
echo " -h | --help Show this screen"
echo " -k | --keyword <KEYWORD> Custom keyword"
echo " -t | --title <TITLE> Custom title"
echo " -f | --format <FORMAT> Ouput format (json, xml, simple)"
exit 1
}
# If no param or param is -h|--help
if [ -z "$1" ] || [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
yourls_help
fi
# Assuming first parameter is the URL
URL=$1;
shift;
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-k|--keyword)
KEYWORD="$2"
shift # argument
shift # value
;;
-t|--title)
TITLE="$2"
shift # argument
shift # value
;;
-f|--format)
FORMAT="$2"
shift # argument
shift # value
;;
-h|--help)
yourls_help
exit 1
;;
*) # unknown option
echo "${0##*/}: unknown option $1"
echo "Try '${0##*/} --help' for more information."
exit 1
;;
esac
done
if [ -z "$FORMAT" ]; then
FORMAT="simple"
fi
curl -s "$YOURLS_HOST/yourls-api.php?signature=$YOURLS_KEY&action=shorturl&url=$URL&keyword=$KEYWORD&title=$TITLE&format=$FORMAT"