paste.sh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/bin/sh
  2. usage="Usage: $0 [-s] [-l language] [-u user] [-c] [ -C copy_command ] [ -p pastebin_url ] file\n
  3. -s: toggles silent mode (do not print the final URL)\n
  4. -c: copies the final URL to clipboard"
  5. if [ "$#" -lt 1 ] ; then
  6. echo -e $usage;
  7. exit
  8. fi
  9. pastebin_url="https://paste.isomorphis.me"
  10. user=""
  11. copy=""
  12. lang=""
  13. print="yes"
  14. which xclip > /dev/null
  15. if [ "$?" -eq 0 ] ; then
  16. copy_cmd="$(which xclip) -i"
  17. else
  18. which xsel > /dev/null
  19. if [ "$?" -eq 0 ] ; then
  20. copy_cmd="$(which xsel)"
  21. fi
  22. fi
  23. while getopts :l:u:csC:p: option
  24. do
  25. case "$option" in
  26. l) language="$OPTARG";;
  27. u) user="$OPTARG";;
  28. c) copy="yes";;
  29. s) print="";;
  30. C) copy_command="$OPTARG";;
  31. p) pastebin_url="$OPTARG";;
  32. ?) echo -e $usage;
  33. exit;;
  34. esac
  35. done
  36. shift $(($OPTIND - 1))
  37. file=$1
  38. if [ ! "$language" ] ; then
  39. ext="$(echo \"$file\"|sed -e 's/.*\.//')"
  40. fi
  41. paste=$(curl -d "hl=${language}&ext=${ext}&user=${user}&escape=on&script" --data-urlencode "paste@${file}" "$pastebin_url" 2>/dev/null)
  42. final="$pastebin_url/$paste"
  43. if [ "$print" = "yes" ] ; then
  44. echo "$final"
  45. fi
  46. if [ "$copy" = "yes" -a -n "$copy_command" ] ; then
  47. echo "$final" | $copy_command
  48. fi