]> git.rmz.io Git - dotfiles.git/blob - zsh/plugins/sprunge/sprunge.plugin.zsh
9f9432ac8c0cb593e6fe43f3be4ef131f707fbc4
[dotfiles.git] / zsh / plugins / sprunge / sprunge.plugin.zsh
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
5 usage() {
6 description | fmt -s >&2
7 }
8
9 description() {
10 cat << HERE
11
12 DESCRIPTION
13 Upload data and fetch URL from the pastebin http://sprunge.us
14
15 USAGE
16 $0 filename.txt
17 $0 text string
18 $0 < filename.txt
19 piped_data | $0
20
21 NOTES
22 --------------------------------------------------------------------------
23 * INPUT METHODS *
24 $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.
25
26 * PRECEDENCE *
27 STDIN redirection has precedence, then piped input, then a filename as an argument, and finally text strings as an arguments.
28
29 EXAMPLE:
30 echo piped | "$0" arguments.txt < stdin_redirection.txt
31
32 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.
33
34 * FILENAMES *
35 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.
36 --------------------------------------------------------------------------
37
38 HERE
39 exit
40 }
41
42 sprunge() {
43 if [ -t 0 ]; then
44 echo Running interactively, checking for arguments... >&2
45 if [ "$*" ]; then
46 echo Arguments present... >&2
47 if [ -f "$*" ]; then
48 echo Uploading the contents of "$*"... >&2
49 cat "$*"
50 else
51 echo Uploading the text: \""$*"\"... >&2
52 echo "$*"
53 fi | curl -F 'sprunge=<-' http://sprunge.us
54 else
55 echo No arguments found, printing USAGE and exiting. >&2
56 usage
57 fi
58 else
59 echo Using input from a pipe or STDIN redirection... >&2
60 while read -r line ; do
61 echo $line
62 done | curl -F 'sprunge=<-' http://sprunge.us
63 fi
64 }