my xfce4 dotfiles
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
2.2 KiB

3 years ago
  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 https://www.shellperson.net/sprunge-pastebin-script/
  4. sprunge() {
  5. if [[ "$1" = --help ]]; then
  6. fmt -s >&2 << EOF
  7. DESCRIPTION
  8. Upload data and fetch URL from the pastebin http://sprunge.us
  9. USAGE
  10. $0 filename.txt
  11. $0 text string
  12. $0 < filename.txt
  13. piped_data | $0
  14. NOTES
  15. Input Methods:
  16. $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.
  17. Precedence:
  18. STDIN redirection has precedence, then piped input, then a filename as an argument, and finally text strings as arguments. For example:
  19. echo piped | $0 arguments.txt < stdin_redirection.txt
  20. 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.
  21. Filenames:
  22. 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.
  23. EOF
  24. return
  25. fi
  26. if [ -t 0 ]; then
  27. echo Running interactively, checking for arguments... >&2
  28. if [ "$*" ]; then
  29. echo Arguments present... >&2
  30. if [ -f "$*" ]; then
  31. echo Uploading the contents of "$*"... >&2
  32. cat "$*"
  33. else
  34. echo Uploading the text: \""$*"\"... >&2
  35. echo "$*"
  36. fi | curl -F 'sprunge=<-' http://sprunge.us
  37. else
  38. echo No arguments found, printing USAGE and exiting. >&2
  39. sprunge --help
  40. return 1
  41. fi
  42. else
  43. echo Using input from a pipe or STDIN redirection... >&2
  44. curl -F 'sprunge=<-' http://sprunge.us
  45. fi
  46. }