Skip to content

Instantly share code, notes, and snippets.

@cirrusUK
Created October 4, 2015 20:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cirrusUK/97e4719d61a7b82a27c9 to your computer and use it in GitHub Desktop.
Save cirrusUK/97e4719d61a7b82a27c9 to your computer and use it in GitHub Desktop.
shell script for the ix pastebin
#!/usr/bin/env bash
# Examples:
# ix hello.txt # paste file (name/ext will be set).
# echo Hello world. | ix # read from STDIN (won't set name/ext).
# ix -n 1 self_destruct.txt # paste will be deleted after one read.
# ix -i ID hello.txt # replace ID, if you have permission.
# ix -d ID
ix() {
local opts
local OPTIND
[ -f "$HOME/.netrc" ] && opts='-n'
while getopts ":hd:i:n:" x; do
case $x in
h) echo "ix [-d ID] [-i ID] [-n N] [opts]"; return;;
d) $echo curl $opts -X DELETE ix.io/$OPTARG; return;;
i) opts="$opts -X PUT"; local id="$OPTARG";;
n) opts="$opts -F read:1=$OPTARG";;
esac
done
shift $(($OPTIND - 1))
[ -t 0 ] && {
local filename="$1"
shift
[ "$filename" ] && {
curl $opts -F f:1=@"$filename" $* ix.io/$id
return
}
echo "^C to cancel, ^D to send."
}
curl $opts -F f:1='<-' $* ix.io/$id
}
ix $*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment