blob: 184b57afa3cb1569935c9881ec80e28b2ac8df60 (
plain)
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
|
#!/bin/sh -eu
base="https://0x0.st"
field="file"
expires=
while getopts e:u:f:h opt; do
case "$opt" in
e)
if ! printf %d "$OPTARG" >/dev/null 2>&1; then
printf "%s: invalid number '%d'\n" "${0##*/}" "$OPTARG"
exit 1
fi
expires="$OPTARG"
;;
u)
base="$OPTARG"
;;
f)
field="$OPTARG"
;;
h)
cat <<-EOF
Usage: ${0##*/} [-e EXPIRES] [FILE]
Upload FILE (or stdin) to a pastebin and print the URL
-e EXPIRES Set the expiration time, either hours or epoch milliseconds
-u URL Provide a different pastebin (default: https://0x0.st)
-f FIELD Use a different field name for the file (default: file)
EOF
exit 0
;;
?)
printf 'Usage: %s [-e EXPIRES] [FILE]\n' "${0##*/}"
exit 1
;;
esac
done
shift $((OPTIND-1))
if [ $# -gt 1 ]; then
printf 'Usage: %s [-e EXPIRES] [FILE]\n' "${0##*/}"
exit 1
fi
file="${1:-/dev/stdin}"
[ "$file" = '-' ] && file="/dev/stdin"
url="$(curl -fsS -F "$field"=@"$file" ${expires:+-F expires="$expires"} "$base")"
printf '%s\n' "$url"
wl-copy "$url"
|