Make send accept input from another process

This commit is contained in:
Tom Willemse 2014-04-27 01:56:14 +02:00
parent d3f6ba5ca5
commit e46b5baef0
2 changed files with 25 additions and 6 deletions

View file

@ -35,8 +35,9 @@
found in the URL) to remove. found in the URL) to remove.
- =scrot= :: Run [[http://freecode.com/projects/scrot][scrot]] to take a screen shot and upload it to hypo. - =scrot= :: Run [[http://freecode.com/projects/scrot][scrot]] to take a screen shot and upload it to hypo.
All arguments given are passed directly to ~scrot~. All arguments given are passed directly to ~scrot~.
- =send= :: Upload a file to hypo. It requires one argument: the file - =send= :: Upload a file to hypo. It can either accept output from
to send to hypo. another process, or it needs the name of a file as a
first parameter.
* License * License

26
hypo
View file

@ -22,19 +22,37 @@ URL="https://ryuslash.org/hypo"
function help_send function help_send
{ {
echo "Usage: $xname send FILE" echo "Usage: $xname send FILE"
echo " $xname send [SUFFIX]"
echo echo
echo "FILE will be uploaded to a hypo instance and the URL at which it can be visited" echo "Using the first form FILE will be uploaded to a hypo instance and the URL at "
echo "will be printed." echo "which it can be visited will be printed."
echo
echo "Using the second form requires that input come from a pipe. Such as:"
echo
echo " cat somefile.txt | hypo send"
echo
echo "In this case the argument to send is optional, if it is specified it should "
echo "include a \`.' to help pygments decide on the syntax highlighting to use. If the "
echo "argument is left unspecified it defaults to \`.txt'."
} }
function cmd_send function cmd_send
{ {
if [[ -z "$1" ]]; then if [[ ! -t 0 ]]; then
sendfile="$(mktemp --suffix ${1-.txt})"
cat - > "$sendfile"
elif [[ -z "$1" ]]; then
cmd_help "send" cmd_help "send"
exit 1 exit 1
else
sendfile="$1"
fi fi
curl --upload-file "$1" "$URL/" curl --upload-file "$sendfile" "$URL/"
if [[ -t 0 ]]; then
rm "$sendfile"
fi
} }
function help_scrot function help_scrot