#!/bin/sh
|
|
# --- SDE-COPYRIGHT-NOTE-BEGIN ---
|
|
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
|
|
#
|
|
# Filename: bin/sde-nopaste
|
|
# Copyright (C) 2010 - 2011 The OpenSDE Project
|
|
#
|
|
# More information can be found in the files COPYING and README.
|
|
#
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; version 2 of the License. A copy of the
|
|
# GNU General Public License can be found in the file COPYING.
|
|
# --- SDE-COPYRIGHT-NOTE-END ---
|
|
|
|
#Description: Paste input or file to http://nopaste.opensde.net/
|
|
#Alias: paste
|
|
|
|
[ -n "$SDEROOT" ] ||
|
|
export SDEROOT=$( cd "${0%/*}/.."; pwd -P )
|
|
|
|
. $SDEROOT/lib/libsde.in
|
|
|
|
NOPASTE='http://nopaste.opensde.net/'
|
|
|
|
nopaste_usage() {
|
|
local progname="$(echo "${0##*/}" | tr '-' ' ')"
|
|
echo "Usage: $progname [<file>]"
|
|
}
|
|
|
|
file= tmpfile=
|
|
if [ $# -gt 0 ]; then
|
|
if [ -s "$1" ]; then
|
|
file="$1"
|
|
else
|
|
nopaste_usage >&2
|
|
exit 1
|
|
fi
|
|
else
|
|
file=$(mktemp)
|
|
cat > "$file"
|
|
tmpfile=yes
|
|
fi
|
|
|
|
mime=$(file --mime-type "$file" | cut -d' ' -f2)
|
|
type=$(file "$file" | cut -d' ' -f2-)
|
|
|
|
# lang = (bash|c|diff|lua|perl|python|text)
|
|
case "$mime" in
|
|
text/x-shellscript|application/x-shellscript) lang=bash ;;
|
|
text/x-diff) lang=diff ;;
|
|
text/x-c) lang=c ;;
|
|
*)
|
|
case "$type" in
|
|
empty) exit ;;
|
|
ASCII*) lang=text ;;
|
|
"diff output text") lang=diff ;;
|
|
*) echo_warning "Assuming plain text (type:$type mime:$mime)"
|
|
lang=text ;;
|
|
esac
|
|
esac
|
|
|
|
hash=$(curl -si -H 'Expect:' -F "sourcefile=@$file" -F lang=$lang \
|
|
$NOPASTE | grep ^Location: | tr -d '\r' | cut -d' ' -f2-)
|
|
|
|
[ -z "$tmpfile" ] || rm -f "$file"
|
|
|
|
if [ -z "$hash" ]; then
|
|
echo_error "failed to paste to $NOPASTE."
|
|
exit 1
|
|
fi
|
|
echo "$NOPASTE$hash" # "(lang:$lang, mime:$mime, type:$type)"
|