-
Notifications
You must be signed in to change notification settings - Fork 2
/
ix
executable file
·35 lines (32 loc) · 1.45 KB
/
ix
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
30
31
32
33
34
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 -e "ix\t\t\tVisit http://ix.io/ for more instructions\n\n[-d ID ]\t\tDelete paste through id\n[-i ID]\t\t\tReplace id if you have permission\n[-n N]\t\t\tPaste will be deleted after one read\n\nExamples:\n\nix hello.txt\t\t\t\t# paste file (name/ext will be set).\necho Hello world. | ix\t\t\t# read from STDIN (won't set name/ext).\nix -n 1 self_destruct.txt\t\t# paste will be deleted after one read.\nix -i ID hello.txt\t\t\t# replace ID, if you have permission.\nix -d ID\n"; 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 (CTRL+C) to cancel, ^D (CTRL+D) to send."
}
curl $opts -F f:1='<-' $* ix.io/$id
}
ix $*