sprunge.plugin.zsh 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # Contributed and SLIGHTLY modded by Matt Parnell/ilikenwf <parwok -at- gmail>
  2. # Created by the blogger at the URL below...I don't know where to find his/her name
  3. # Original found at http://www.shellperson.net/sprunge-pastebin-script/
  4. usage() {
  5. description | fmt -s >&2
  6. }
  7. description() {
  8. cat << HERE
  9. DESCRIPTION
  10. Upload data and fetch URL from the pastebin http://sprunge.us
  11. USAGE
  12. $0 filename.txt
  13. $0 text string
  14. $0 < filename.txt
  15. piped_data | $0
  16. NOTES
  17. --------------------------------------------------------------------------
  18. * INPUT METHODS *
  19. $0 can accept piped data, STDIN redirection [<filename.txt], text strings following the command as arguments, or filenames as arguments. Only one of these methods can be used at a time, so please see the note on precedence. Also, note that using a pipe or STDIN redirection will treat tabs as spaces, or disregard them entirely (if they appear at the beginning of a line). So I suggest using a filename as an argument if tabs are important either to the function or readability of the code.
  20. * PRECEDENCE *
  21. STDIN redirection has precedence, then piped input, then a filename as an argument, and finally text strings as an arguments.
  22. EXAMPLE:
  23. echo piped | "$0" arguments.txt < stdin_redirection.txt
  24. In this example, the contents of file_as_stdin_redirection.txt would be uploaded. Both the piped_text and the file_as_argument.txt are ignored. If there is piped input and arguments, the arguments will be ignored, and the piped input uploaded.
  25. * FILENAMES *
  26. If a filename is misspelled or doesn't have the necessary path description, it will NOT generate an error, but will instead treat it as a text string and upload it.
  27. --------------------------------------------------------------------------
  28. HERE
  29. exit
  30. }
  31. sprunge() {
  32. if [ -t 0 ]; then
  33. echo Running interactively, checking for arguments... >&2
  34. if [ "$*" ]; then
  35. echo Arguments present... >&2
  36. if [ -f "$*" ]; then
  37. echo Uploading the contents of "$*"... >&2
  38. cat "$*"
  39. else
  40. echo Uploading the text: \""$*"\"... >&2
  41. echo "$*"
  42. fi | curl -F 'sprunge=<-' http://sprunge.us
  43. else
  44. echo No arguments found, printing USAGE and exiting. >&2
  45. usage
  46. fi
  47. else
  48. echo Using input from a pipe or STDIN redirection... >&2
  49. curl -F 'sprunge=<-' http://sprunge.us
  50. fi
  51. }