2009-09-01

Sprunge

Sprunge is lovely. It's a pastebin but without all the crap. Here's my sprunge script:

#!/bin/bash
url=$(curl -F 'sprunge=<-' -H "Expect: " http://sprunge.us 2>/dev/null)
if [ $? -ne 0 ]; then
 echo "request failed" >&2
 exit 1
fi
if [ $# -gt 0 ]; then
 url="$url?$1"
fi
echo $url
if [ $DISPLAY ]; then
 { which xsel >/dev/null 2>/dev/null && echo -n $url | xsel; } \
  || { which xclip >/dev/null 2>/dev/null && echo -n $url | xclip; } \
  || echo "haven't copied to the clipboard: no xsel or xclip" >&2
else
 echo "haven't copied to the clipboard: no \$DISPLAY" >&2
fi

The empty Expect header is to get around a bug which rears its head if the request goes through a proxy like Squid.

This will pastebin the standard input and output the URL at which you can retrieve it. Additionally, if it can it'll put it on the X selection so you can paste it into IRC or whatever.

Give a filetype as an argument if you want the code highlighted. All that does is add a parameter to the URL which is printed and put on the clipboard.

So I might run some command | sprunge to show the command's output to someone or sprunge python <script.py to show a buggy Python file to someone.

No comments:

Post a Comment