-
Notifications
You must be signed in to change notification settings - Fork 0
/
fileio
executable file
·54 lines (45 loc) · 979 Bytes
/
fileio
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
#!/bin/bash
set -eu
expiry=""
result=""
usage_info () {
echo "file.io utility"
echo " "
echo "file.io [options] path"
echo " "
echo "Options:"
echo "-h, --help these instructions"
echo "-e, --expiry=AMOUNT specify when it will expire - e.g. 1w, 1m, 3d..."
exit 0
}
request () {
echo "Uploading to file.io..."
result=$(curl -sF $file $endpoint)
}
fail () {
exit_code=$?
echo "Failed to upload the file -> cURL exit code: $exit_code"
exit $exit_code
}
if [[ $# -eq 0 ]]; then
usage_info
else
case "$1" in
-h|--help)
usage_info
;;
-e|--expiry*)
shift
expiry=$1
shift
;;
esac
fi
endpoint="https://file.io/?expires=$expiry"
file="file=@$1"
request || fail
link=$(echo $result | awk -F'"' '{ print $10 }')
valid_until=$(echo $result | awk -F'"' '{ print $14 }')
echo $link | pbcopy
echo "Link: $link -> already available in your clipboard!"
echo "It will expire in $valid_until"