Skip to content

Instantly share code, notes, and snippets.

@ezracelli
Created December 17, 2019 00:18
Show Gist options
  • Save ezracelli/56fb7cc24561dafae1e3de45a4edb79c to your computer and use it in GitHub Desktop.
Save ezracelli/56fb7cc24561dafae1e3de45a4edb79c to your computer and use it in GitHub Desktop.
Command-line client for https://file.io -- inspired by http://ix.io/client
#!/usr/bin/env bash
# Examples:
# fileio hello.txt # paste file (name/ext will be set).
# echo Hello world. | fileio # read from STDIN (won't set name/ext).
# fileio -n 1d self_destruct.txt # paste will be deleted after one day, downloaded or not.
# # can set \d(d|w|m|y) for weeks, months, years.
fileio() {
local query
local OPTIND
while getopts ":hd:i:n:" x; do
case $x in
h) echo "fileio [-n N] [opts]"; return;;
n) query="?expires=$OPTARG";;
esac
done
shift $(($OPTIND - 1))
[ -t 0 ] && {
local filename="$1"
shift
[ "$filename" ] && {
curl -w "\n" -F file=@"$filename" $* https://file.io$query
echo ''
return
}
echo "^C to cancel, ^D to send."
}
local text="$(cat)"
curl -w "\n" --data text="$text" $* https://file.io$query
}
fileio $*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment