Advertisement
Guest User

Untitled

a guest
Apr 16th, 2024
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.03 KB | Source Code | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. # Examples:
  4. #     ix hello.txt              # paste file (name/ext will be set).
  5. #     echo Hello world. | ix    # read from STDIN (won't set name/ext).
  6. #     ix -n 1 self_destruct.txt # paste will be deleted after one read.
  7. #     ix -i ID hello.txt        # replace ID, if you have permission.
  8. #     ix -d ID
  9.  
  10. ix() {
  11.     local opts
  12.     local OPTIND
  13.     [ -f "$HOME/.netrc" ] && opts='-n'
  14.     while getopts ":hd:i:n:" x; do
  15.         case $x in
  16.             h) echo "ix [-d ID] [-i ID] [-n N] [opts]"; return;;
  17.             d) $echo curl $opts -X DELETE ix.io/$OPTARG; return;;
  18.             i) opts="$opts -X PUT"; local id="$OPTARG";;
  19.             n) opts="$opts -F read:1=$OPTARG";;
  20.         esac
  21.     done
  22.     shift $(($OPTIND - 1))
  23.     [ -t 0 ] && {
  24.         local filename="$1"
  25.         shift
  26.         [ "$filename" ] && {
  27.             curl $opts -F f:1=@"$filename" $* ix.io/$id
  28.             return
  29.         }
  30.         echo "^C to cancel, ^D to send."
  31.     }
  32.     curl $opts -F f:1='<-' $* ix.io/$id
  33. }
  34.  
  35. ix $*
Tags: ix
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement