-
Notifications
You must be signed in to change notification settings - Fork 2
/
deldog
29 lines (29 loc) · 918 Bytes
/
deldog
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
#!/usr/bin/env bash
# Function to upload to del.dog
#
# This can be downloaded and sourced without any of the other scripts in this repo.
#
# $ curl -LSsO https://github.com/nathanchance/scripts/raw/master/env/stubs/deldog
#
# Open the deldog file to make sure it matches this one.
#
# $ source deldog
#
# Usage:
# $ deldog <file>
# $ command |& deldog
function deldog() { (
for BINARY in curl jq; do
command -v ${BINARY} &>/dev/null || {
echo "ERROR: ${BINARY} is not installed" >&2
exit 1
}
done
[[ -z ${HASTE_URL} ]] && HASTE_URL=https://del.dog
[[ -n ${DEL_DOG_API_KEY} && ${HASTE_URL} =~ del ]] && CURL_ARGS=(--header "X-api-key: ${DEL_DOG_API_KEY}")
RESULT=$(curl -sf --data-binary @"${1:--}" "${CURL_ARGS[@]}" "${HASTE_URL}"/documents) || {
echo "ERROR: failed to post document, ca-certificates might need to be installed" >&2
exit 1
}
echo "${HASTE_URL}/$(jq -r .key <<<"${RESULT}")"
); }