ix 1018 B

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/env bash
  2. # Examples:
  3. # ix hello.txt # paste file (name/ext will be set).
  4. # echo Hello world. | ix # read from STDIN (won't set name/ext).
  5. # ix -n 1 self_destruct.txt # paste will be deleted after one read.
  6. # ix -i ID hello.txt # replace ID, if you have permission.
  7. # ix -d ID
  8. ix() {
  9. local opts
  10. local OPTIND
  11. [ -f "$HOME/.netrc" ] && opts='-n'
  12. while getopts ":hd:i:n:" x; do
  13. case $x in
  14. h) echo "ix [-d ID] [-i ID] [-n N] [opts]"; return;;
  15. d) $echo curl $opts -X DELETE ix.io/$OPTARG; return;;
  16. i) opts="$opts -X PUT"; local id="$OPTARG";;
  17. n) opts="$opts -F read:1=$OPTARG";;
  18. esac
  19. done
  20. shift $(($OPTIND - 1))
  21. [ -t 0 ] && {
  22. local filename="$1"
  23. shift
  24. [ "$filename" ] && {
  25. curl $opts -F f:1=@"$filename" $* ix.io/$id
  26. return
  27. }
  28. echo "^C to cancel, ^D to send."
  29. }
  30. curl $opts -F f:1='<-' $* ix.io/$id
  31. }
  32. ix $*