summaryrefslogtreecommitdiff
path: root/oh-my-zsh/plugins/sprunge
diff options
context:
space:
mode:
authorAditya <bluenerd@protonmail.com>2023-02-27 20:04:56 +0530
committerAditya <bluenerd@protonmail.com>2023-02-27 20:04:56 +0530
commitedc449275b6c04445f58b108ca0937a87c1e8430 (patch)
tree9fd484d58145b616f29a78857cc0b1c8b1c18f05 /oh-my-zsh/plugins/sprunge
parent6f5424ca96c4221ef433f545642669e9c104d0ed (diff)
add zsh
Diffstat (limited to 'oh-my-zsh/plugins/sprunge')
-rw-r--r--oh-my-zsh/plugins/sprunge/README.md38
-rw-r--r--oh-my-zsh/plugins/sprunge/sprunge.plugin.zsh52
2 files changed, 90 insertions, 0 deletions
diff --git a/oh-my-zsh/plugins/sprunge/README.md b/oh-my-zsh/plugins/sprunge/README.md
new file mode 100644
index 0000000..80e3b30
--- /dev/null
+++ b/oh-my-zsh/plugins/sprunge/README.md
@@ -0,0 +1,38 @@
+# Sprunge plugin
+
+This plugin uploads data and fetch URL from the pastebin http://sprunge.us
+
+To enable it, add 'sprunge' to your plugins:
+
+```zsh
+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:
+
+```console
+$ 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 misspelled or doesn't have the necessary path description, it will NOT
+ generate an error, but instead treat it as a text string.
+
+## Credits
+
+- Original code: [shellperson.net](https://web.archive.org/web/20190910065842/https://www.shellperson.net/sprunge-pastebin-script/).
+- Adapted by: Matt Parnell (@ilikenwf).
diff --git a/oh-my-zsh/plugins/sprunge/sprunge.plugin.zsh b/oh-my-zsh/plugins/sprunge/sprunge.plugin.zsh
new file mode 100644
index 0000000..48dff58
--- /dev/null
+++ b/oh-my-zsh/plugins/sprunge/sprunge.plugin.zsh
@@ -0,0 +1,52 @@
+sprunge() {
+ if [[ "$1" = --help ]]; then
+ fmt -s >&2 << EOF
+
+DESCRIPTION
+ Upload data and fetch URL from the pastebin http://sprunge.us
+
+USAGE
+ $0 filename.txt
+ $0 text string
+ $0 < filename.txt
+ 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 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
+}