From 45c698c099ad293ca79d6f458585e113db801480 Mon Sep 17 00:00:00 2001 From: Simon Gomizelj Date: Mon, 28 Nov 2011 16:19:11 -0500 Subject: [PATCH 1/6] Reworked the sprunge script into a zsh function. There's no need to manipulate $PATH to get a zsh script loading. --- plugins/sprunge/sprunge | 75 -------------------------- plugins/sprunge/sprunge.plugin.zsh | 84 +++++++++++++++++++++++++++--- 2 files changed, 78 insertions(+), 81 deletions(-) delete mode 100755 plugins/sprunge/sprunge diff --git a/plugins/sprunge/sprunge b/plugins/sprunge/sprunge deleted file mode 100755 index 10af8e2b3..000000000 --- a/plugins/sprunge/sprunge +++ /dev/null @@ -1,75 +0,0 @@ -#!/bin/zsh - -# Contributed and SLIGHTLY modded by Matt Parnell/ilikenwf -# Created by the blogger at the URL below...I don't know where to find his/her name -# Original found at http://www.shellperson.net/sprunge-pastebin-script/ - -usage() { - cat << HERE - -DESCRIPTION - Upload data and fetch URL from the pastebin http://sprunge.us - -USAGE - $0 filename.txt - $0 < filename.txt - piped_data | $0 - -INPUT METHODS - -$0 can accept piped data, STDIN redirection [ +# Created by the blogger at the URL below...I don't know where to find his/her name +# Original found at http://www.shellperson.net/sprunge-pastebin-script/ + +sprunge () { + if [ -t 0 ]; then + if [ "$*" ]; then + if [ -f "$*" ]; then + # Use python to attempt to detect the syntax + syntax=$(echo "try: + from pygments.lexers import get_lexer_for_filename + print(get_lexer_for_filename('$*').aliases[0]) +except: + print('text')" | python) + url=$(cat "$*" | curl -F 'sprunge=<-' http://sprunge.us) + fi + else + cat << HERE + +DESCRIPTION + Upload data and fetch URL from the pastebin http://sprunge.us + +USAGE + $0 filename.txt + $0 < filename.txt + piped_data | $0 + +INPUT METHODS + +$0 can accept piped data, STDIN redirection [ Date: Mon, 28 Nov 2011 16:23:46 -0500 Subject: [PATCH 2/6] Sprunge should call return, not exit on failure now. Otherwise it kills the shell... doh. --- plugins/sprunge/sprunge.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/sprunge/sprunge.plugin.zsh b/plugins/sprunge/sprunge.plugin.zsh index 20204b156..208e381e7 100644 --- a/plugins/sprunge/sprunge.plugin.zsh +++ b/plugins/sprunge/sprunge.plugin.zsh @@ -72,7 +72,7 @@ description, it will NOT generate an error, but will instead treat it as a text string and upload it. HERE - exit + return 1 fi else syntax="text" # We're dumb in this mode. So, dumb syntax highlighting! From c5404482a516d7b697afa700cccbca94151c11bb Mon Sep 17 00:00:00 2001 From: Simon Gomizelj Date: Mon, 28 Nov 2011 17:06:13 -0500 Subject: [PATCH 3/6] Its better practise to use [[ and ]] rather than [ and ] --- plugins/sprunge/sprunge.plugin.zsh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/sprunge/sprunge.plugin.zsh b/plugins/sprunge/sprunge.plugin.zsh index 208e381e7..32da7b12f 100644 --- a/plugins/sprunge/sprunge.plugin.zsh +++ b/plugins/sprunge/sprunge.plugin.zsh @@ -11,7 +11,7 @@ # if [[ ${_plugin__path} == "on" ]]; then # Plugin setting: Add this plugin directory to the path # export PATH=$PATH:$ZSH/plugins/sprunge -# elif [ -z "${commands[sprunge]}" ]; then +# elif [[ -z "${commands[sprunge]}" ]]; then # Nope. No `sprunge` command, period. So, dumb/simple alias, here we go! # alias sprunge="curl -F 'sprunge=<-' http://sprunge.us/" # fi @@ -21,9 +21,9 @@ # Original found at http://www.shellperson.net/sprunge-pastebin-script/ sprunge () { - if [ -t 0 ]; then - if [ "$*" ]; then - if [ -f "$*" ]; then + if [[ -t 0 ]]; then + if [[ "$*" ]]; then + if [[ -f "$*" ]]; then # Use python to attempt to detect the syntax syntax=$(echo "try: from pygments.lexers import get_lexer_for_filename @@ -81,7 +81,7 @@ HERE done | curl -F 'sprunge=<-' http://sprunge.us) fi - if [ "$syntax" != "text" ]; then + if [[ "$syntax" != "text" ]]; then echo "$url?$syntax" else echo $url From 1a5e86d9a693922415f204bd4bde698f85518a51 Mon Sep 17 00:00:00 2001 From: Simon Gomizelj Date: Mon, 28 Nov 2011 21:20:06 -0500 Subject: [PATCH 4/6] Variables here should be marked local. --- plugins/sprunge/sprunge.plugin.zsh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/sprunge/sprunge.plugin.zsh b/plugins/sprunge/sprunge.plugin.zsh index 32da7b12f..55dff180b 100644 --- a/plugins/sprunge/sprunge.plugin.zsh +++ b/plugins/sprunge/sprunge.plugin.zsh @@ -21,6 +21,8 @@ # Original found at http://www.shellperson.net/sprunge-pastebin-script/ sprunge () { + local url syntax + if [[ -t 0 ]]; then if [[ "$*" ]]; then if [[ -f "$*" ]]; then From e0535cce8bed4be88a76ed7b769f620335dce925 Mon Sep 17 00:00:00 2001 From: Simon Gomizelj Date: Mon, 28 Nov 2011 21:28:02 -0500 Subject: [PATCH 5/6] One bug fix, one removal of an unnecessary cat. --- plugins/sprunge/sprunge.plugin.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/sprunge/sprunge.plugin.zsh b/plugins/sprunge/sprunge.plugin.zsh index 55dff180b..41c4c2671 100644 --- a/plugins/sprunge/sprunge.plugin.zsh +++ b/plugins/sprunge/sprunge.plugin.zsh @@ -24,7 +24,7 @@ sprunge () { local url syntax if [[ -t 0 ]]; then - if [[ "$*" ]]; then + if [[ -n "$*" ]]; then if [[ -f "$*" ]]; then # Use python to attempt to detect the syntax syntax=$(echo "try: @@ -32,7 +32,7 @@ sprunge () { print(get_lexer_for_filename('$*').aliases[0]) except: print('text')" | python) - url=$(cat "$*" | curl -F 'sprunge=<-' http://sprunge.us) + url=$(curl -F 'sprunge=<-' http://sprunge.us < "$*") fi else cat << HERE From 4028becca3cc8630a49143ee5b761ec93a22c904 Mon Sep 17 00:00:00 2001 From: "Evan LeCompte (Home)" Date: Tue, 29 Nov 2011 04:14:38 -0500 Subject: [PATCH 6/6] copy sprunge $url to clipboard automatically if user has xclip or xsel installed --- plugins/sprunge/sprunge.plugin.zsh | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/plugins/sprunge/sprunge.plugin.zsh b/plugins/sprunge/sprunge.plugin.zsh index 41c4c2671..691a94069 100644 --- a/plugins/sprunge/sprunge.plugin.zsh +++ b/plugins/sprunge/sprunge.plugin.zsh @@ -32,7 +32,7 @@ sprunge () { print(get_lexer_for_filename('$*').aliases[0]) except: print('text')" | python) - url=$(curl -F 'sprunge=<-' http://sprunge.us < "$*") + url=$(curl -s -F 'sprunge=<-' http://sprunge.us < "$*") fi else cat << HERE @@ -40,6 +40,11 @@ except: DESCRIPTION Upload data and fetch URL from the pastebin http://sprunge.us + In addition to printing the returned URL, if the xset or xsel + programs are available (on $PATH), the URL will also be copied to the + PRIMARY selection and the CLIPBOARD selection (allowing to quickly + paste the url into IRC client for example). + USAGE $0 filename.txt $0 < filename.txt @@ -80,12 +85,25 @@ HERE syntax="text" # We're dumb in this mode. So, dumb syntax highlighting! url=$(while read -r line ; do echo $line - done | curl -F 'sprunge=<-' http://sprunge.us) + done | curl -s -F 'sprunge=<-' http://sprunge.us) fi if [[ "$syntax" != "text" ]]; then - echo "$url?$syntax" + # if stdout is not a tty, suppress trailing newline + if [[ ! -t 1 ]] ; then local flags='-n' ; fi + echo $flags "$url?$syntax" else - echo $url + # if stdout is not a tty, suppress trailing newline + if [[ ! -t 1 ]] ; then local flags='-n' ; fi + echo $flags $url + fi + + #copy url to primary and clipboard (middle-mouse & shift+ins/Ctrl+v) + if (( $+commands[xclip] )); then + echo -n "$url?$syntax" | xclip -sel primary + echo -n "$url?$syntax" | xclip -sel clipboard + elif (( $+commands[xsel] )); then + echo -n "$url?$syntax" | xsel -ip #primary + echo -n "$url?$syntax" | xsel -ib #clipboard fi }