diff options
author | Ben Sima <ben@bsima.me> | 2019-03-08 10:43:38 -0800 |
---|---|---|
committer | Ben Sima <ben@bsima.me> | 2019-03-08 10:43:45 -0800 |
commit | 3f50d3add22b1e79bbf147e956595d2a8ef1d6c3 (patch) | |
tree | 0b078ab960090b705c764c4484b54730678a23c9 /ix | |
parent | 81a699fcd18da46af228f088b96d43cd738578b4 (diff) |
update scripts
Diffstat (limited to 'ix')
-rwxr-xr-x | ix | 35 |
1 files changed, 35 insertions, 0 deletions
@@ -0,0 +1,35 @@ +#!/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 $*
\ No newline at end of file |