]> src.twobees.de Git - dotfiles.git/blob - stow/oh-my-zsh/.oh-my-zsh/plugins/sprunge/sprunge.plugin.zsh
48dff5837c6218fd2f0dc3b1a31b45d6e9adb34d
[dotfiles.git] / stow / oh-my-zsh / .oh-my-zsh / plugins / sprunge / sprunge.plugin.zsh
1 sprunge() {
2   if [[ "$1" = --help ]]; then
3     fmt -s >&2 << EOF
4
5 DESCRIPTION
6   Upload data and fetch URL from the pastebin http://sprunge.us
7
8 USAGE
9   $0 filename.txt
10   $0 text string
11   $0 < filename.txt
12   piped_data | $0
13
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
18   Precedence:
19   STDIN redirection has precedence, then piped input, then a filename as an argument, and finally text strings as arguments. For example:
20
21     echo piped | $0 arguments.txt < stdin_redirection.txt
22
23   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.
24
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 EOF
29     return
30   fi
31
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       sprunge --help
46       return 1
47     fi
48   else
49     echo Using input from a pipe or STDIN redirection... >&2
50     curl -F 'sprunge=<-' http://sprunge.us
51   fi
52 }