Add sprunge.us uploader - uses files, pipes, etc and posts to a minimalistic pastebin
Robby Russell authored on 26/12/2011 at 18:06:551 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,64 @@ |
0 |
+# Contributed and SLIGHTLY modded by Matt Parnell/ilikenwf <parwok -at- gmail> |
|
1 |
+# Created by the blogger at the URL below...I don't know where to find his/her name |
|
2 |
+# Original found at http://www.shellperson.net/sprunge-pastebin-script/ |
|
3 |
+ |
|
4 |
+usage() { |
|
5 |
+description | fmt -s >&2 |
|
6 |
+} |
|
7 |
+ |
|
8 |
+description() { |
|
9 |
+cat << HERE |
|
10 |
+ |
|
11 |
+DESCRIPTION |
|
12 |
+ Upload data and fetch URL from the pastebin http://sprunge.us |
|
13 |
+ |
|
14 |
+USAGE |
|
15 |
+ $0 filename.txt |
|
16 |
+ $0 text string |
|
17 |
+ $0 < filename.txt |
|
18 |
+ piped_data | $0 |
|
19 |
+ |
|
20 |
+NOTES |
|
21 |
+-------------------------------------------------------------------------- |
|
22 |
+* INPUT METHODS * |
|
23 |
+$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. |
|
24 |
+ |
|
25 |
+* PRECEDENCE * |
|
26 |
+STDIN redirection has precedence, then piped input, then a filename as an argument, and finally text strings as an arguments. |
|
27 |
+ |
|
28 |
+ EXAMPLE: |
|
29 |
+ echo piped | "$0" arguments.txt < stdin_redirection.txt |
|
30 |
+ |
|
31 |
+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. |
|
32 |
+ |
|
33 |
+* FILENAMES * |
|
34 |
+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. |
|
35 |
+-------------------------------------------------------------------------- |
|
36 |
+ |
|
37 |
+HERE |
|
38 |
+exit |
|
39 |
+} |
|
40 |
+ |
|
41 |
+sprunge() { |
|
42 |
+ if [ -t 0 ]; then |
|
43 |
+ echo Running interactively, checking for arguments... >&2 |
|
44 |
+ if [ "$*" ]; then |
|
45 |
+ echo Arguments present... >&2 |
|
46 |
+ if [ -f "$*" ]; then |
|
47 |
+ echo Uploading the contents of "$*"... >&2 |
|
48 |
+ cat "$*" |
|
49 |
+ else |
|
50 |
+ echo Uploading the text: \""$*"\"... >&2 |
|
51 |
+ echo "$*" |
|
52 |
+ fi | curl -F 'sprunge=<-' http://sprunge.us |
|
53 |
+ else |
|
54 |
+ echo No arguments found, printing USAGE and exiting. >&2 |
|
55 |
+ usage |
|
56 |
+ fi |
|
57 |
+ else |
|
58 |
+ echo Using input from a pipe or STDIN redirection... >&2 |
|
59 |
+ while read -r line ; do |
|
60 |
+ echo $line |
|
61 |
+ done | curl -F 'sprunge=<-' http://sprunge.us |
|
62 |
+ fi |
|
63 |
+} |