Sprunge plugin detects the syntax

This commit is contained in:
Colin Shea 2011-11-27 02:46:41 -07:00
commit 3f3da1eb47

View file

@ -41,22 +41,22 @@ exit
sprunge() { sprunge() {
if [ -t 0 ]; then if [ -t 0 ]; then
echo Running interactively, checking for arguments... >&2
if [ "$*" ]; then if [ "$*" ]; then
echo Arguments present... >&2
if [ -f "$*" ]; then if [ -f "$*" ]; then
echo Uploading the contents of "$*"... >&2 # 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)
cat "$*" cat "$*"
else else
echo Uploading the text: \""$*"\"... >&2
echo "$*" echo "$*"
fi | curl -F 'sprunge=<-' http://sprunge.us fi | curl -F 'sprunge=<-' http://sprunge.us
else else
echo No arguments found, printing USAGE and exiting. >&2
usage usage
fi fi
else else
echo Using input from a pipe or STDIN redirection... >&2
while read -r line ; do while read -r line ; do
echo $line echo $line
done | curl -F 'sprunge=<-' http://sprunge.us done | curl -F 'sprunge=<-' http://sprunge.us