Created
July 29, 2015 20:44
-
-
Save CyrusOfEden/cdba87dc8ebc21d1bda6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
# Share a file on https://file.io | |
# Dependencies: jq | |
# Optional Dependencies: xclip | |
# Usage: | |
# fileio -t TTL [FILE] | |
# | |
# TTL is a positive integer representing the number of days the file lives on | |
# the server before being purged. | |
# TODO: | |
# * Add support for multiple files | |
# * Show help | |
TTL=3 # Files live for two days by default | |
BASE_URL="https://file.io" | |
while getopts ":t:" opt; do | |
case $opt in | |
t) | |
TTL=$OPTARG | |
;; | |
\?) | |
echo "Invalid option: -$OPTARG" >&2 | |
;; | |
:) | |
echo "Option -$OPTARG requires an argument" >&2 | |
;; | |
esac | |
done | |
echo "Uploading to file.io..." | |
response=$(curl -s -F "file=@${@: -1}" "$BASE_URL/?expires=${TTL}d") | |
key=$(echo $response | jq '.["key"]' | cut -d '"' -f2) | |
error=$(echo $response | jq '.["error"]') | |
if [[ "$key" == "null" ]]; then | |
echo $error | |
exit 1 | |
else | |
URL="$BASE_URL/$key" | |
echo $URL | pbcopy | |
echo "Done! The link has been copied to your clipboard." | |
echo $URL | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment