diff options
author | Tuowen Zhao <ztuowen@gmail.com> | 2019-10-09 20:16:18 -0600 |
---|---|---|
committer | Tuowen Zhao <ztuowen@gmail.com> | 2019-10-09 20:16:18 -0600 |
commit | 112a85697481cae663ff281b74fdc1f72a67b294 (patch) | |
tree | e7f6f938fda886c87d296711d853bcc9833b9ec2 /plugins/sprunge | |
parent | 09829ba30c269e35bddf44a21f3357efd31e686f (diff) | |
parent | 710a3d5a1e2888a4dfb1769f8f1edd8a590eee22 (diff) | |
download | zsh-112a85697481cae663ff281b74fdc1f72a67b294.tar.gz zsh-112a85697481cae663ff281b74fdc1f72a67b294.tar.bz2 zsh-112a85697481cae663ff281b74fdc1f72a67b294.zip |
Merge branch 'master' of https://github.com/robbyrussell/oh-my-zsh
Diffstat (limited to 'plugins/sprunge')
-rw-r--r-- | plugins/sprunge/README.md | 31 | ||||
-rw-r--r-- | plugins/sprunge/sprunge.plugin.zsh | 86 |
2 files changed, 71 insertions, 46 deletions
diff --git a/plugins/sprunge/README.md b/plugins/sprunge/README.md new file mode 100644 index 000000000..2a363d3bd --- /dev/null +++ b/plugins/sprunge/README.md @@ -0,0 +1,31 @@ +# Sprunge plugin + +This plugin uploads data and fetch URL from the pastebin http://sprunge.us + +To enable it, add 'sprunge' to your plugins: +``` +plugins=(... sprunge) +``` + +## Usage + +| Command | Description | +|------------------------------|-------------------------------------------| +| `sprunge filename.txt` | Uploads filename.txt | +| `sprunge "this is a string"` | Uploads plain text | +| `sprunge < filename.txt` | Redirects filename.txt content to sprunge | +| `echo data \| sprunge` | Any piped data will be uploaded | + +Once sprunge has processed the input it will give you a unique HTTP address: +``` +$ sprunge "hello" +http://sprunge.us/XxjnKz +``` + +## Notes + +- Sprunge accepts piped data, stdin redirection, text strings as input or filenames. + Only one of these can be used at a time. +- Argument precedence goes as follows: stdin > piped input > text strings. +- If a filename is mispelled or doesn't have the necessary path description, it will NOT + generate an error, but instead treat it as a text string. diff --git a/plugins/sprunge/sprunge.plugin.zsh b/plugins/sprunge/sprunge.plugin.zsh index e1c89b729..5d5687a82 100644 --- a/plugins/sprunge/sprunge.plugin.zsh +++ b/plugins/sprunge/sprunge.plugin.zsh @@ -2,12 +2,9 @@ # Created by the blogger at the URL below...I don't know where to find his/her name # Original found at https://www.shellperson.net/sprunge-pastebin-script/ -usage() { -description | fmt -s >&2 -} - -description() { -cat << HERE +sprunge() { + if [[ "$1" = --help ]]; then + fmt -s >&2 << EOF DESCRIPTION Upload data and fetch URL from the pastebin http://sprunge.us @@ -19,44 +16,41 @@ USAGE piped_data | $0 NOTES --------------------------------------------------------------------------- -* INPUT METHODS * -$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. - -* PRECEDENCE * -STDIN redirection has precedence, then piped input, then a filename as an argument, and finally text strings as an arguments. - - EXAMPLE: - echo piped | "$0" arguments.txt < stdin_redirection.txt - -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. - -* FILENAMES * -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. --------------------------------------------------------------------------- - -HERE -exit -} - -sprunge() { - if [ -t 0 ]; then - echo Running interactively, checking for arguments... >&2 - if [ "$*" ]; then - echo Arguments present... >&2 - if [ -f "$*" ]; then - echo Uploading the contents of "$*"... >&2 - cat "$*" - else - echo Uploading the text: \""$*"\"... >&2 - echo "$*" - fi | curl -F 'sprunge=<-' http://sprunge.us - else - echo No arguments found, printing USAGE and exiting. >&2 - usage - fi - else - echo Using input from a pipe or STDIN redirection... >&2 - curl -F 'sprunge=<-' http://sprunge.us - fi + Input Methods: + $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. + + Precedence: + STDIN redirection has precedence, then piped input, then a filename as an argument, and finally text strings as arguments. For example: + + echo piped | $0 arguments.txt < stdin_redirection.txt + + 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. + + Filenames: + 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. + +EOF + return + fi + + if [ -t 0 ]; then + echo Running interactively, checking for arguments... >&2 + if [ "$*" ]; then + echo Arguments present... >&2 + if [ -f "$*" ]; then + echo Uploading the contents of "$*"... >&2 + cat "$*" + else + echo Uploading the text: \""$*"\"... >&2 + echo "$*" + fi | curl -F 'sprunge=<-' http://sprunge.us + else + echo No arguments found, printing USAGE and exiting. >&2 + sprunge --help + return 1 + fi + else + echo Using input from a pipe or STDIN redirection... >&2 + curl -F 'sprunge=<-' http://sprunge.us + fi } |