+bin/{bin,transfer} scripts for sprunge.us and transfer.sh
This commit is contained in:
parent
9bd47f4091
commit
feb2f7c7c7
67
bin/bin
Executable file
67
bin/bin
Executable file
|
@ -0,0 +1,67 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Sends file(s) or stdin to http://sprunge.us
|
||||
|
||||
set -e
|
||||
|
||||
usage() {
|
||||
more <<EOL
|
||||
Usage: $0 [-l LANG] [FILE]
|
||||
|
||||
Uploads text files/input to sprunge.us, and image/binaries to transfer.sh.
|
||||
|
||||
Options:
|
||||
-l LANG Specify file extension for syntax highlight. Only for text.
|
||||
-h This information.
|
||||
|
||||
Examples:
|
||||
$0 script.py
|
||||
$0 -l py sometext
|
||||
echo "Hello world" | bin
|
||||
echo "puts 'Hi'" | bin -l rb
|
||||
EOL
|
||||
}
|
||||
|
||||
sprunge() {
|
||||
while read in; do
|
||||
echo "$in"
|
||||
done < ${1:-/dev/stdin} \
|
||||
| curl --progress-bar -F 'sprunge=<-' http://sprunge.us \
|
||||
| head -n 1 \
|
||||
| tr -d '\r\n '
|
||||
}
|
||||
|
||||
#
|
||||
while getopts hl: opt; do
|
||||
case $opt in
|
||||
l) lang="?$OPTARG"
|
||||
;;
|
||||
[h?])
|
||||
usage
|
||||
exit
|
||||
;;
|
||||
:) >&2 echo "$OPTARG requires an argument"
|
||||
usage
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
shift $((OPTIND-1))
|
||||
|
||||
if (($# == 0)) && [[ -t 0 ]]; then
|
||||
>&2 echo "Nothing in stdin and no files specified!"
|
||||
>&2 usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Naive lang detection from file extension
|
||||
[[ "$1" = *.* && -z "$lang" ]] && lang="?${1##*.}"
|
||||
|
||||
# Read from stdin or read file(s)
|
||||
url=$(sprunge $1)
|
||||
|
||||
# Assemble URL+langstr and send to clipboard
|
||||
printf "%s%s" "$url" "$lang" | pbcopy
|
||||
|
||||
# Show URL to interactive users
|
||||
[[ -t 0 ]] && pbpaste
|
16
bin/transfer
Normal file
16
bin/transfer
Normal file
|
@ -0,0 +1,16 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Upload file to transfer.sh
|
||||
url="https://transfer.sh"
|
||||
tmpfile=$(mktemp -t transferXXX)
|
||||
if [[ -t 0 ]]; then
|
||||
basefile=$(basename "$1" | sed -e 's/[^a-zA-Z0-9._-]/-/g')
|
||||
curl --progress-bar --upload-file "$1" "$url/$basefile" >> $tmpfile
|
||||
else
|
||||
curl --progress-bar --upload-file "-" "$url/$1" >> $tmpfile
|
||||
fi
|
||||
|
||||
cat $tmpfile
|
||||
rm -f $tmpfile
|
||||
|
||||
# vim:set ft=sh:
|
Loading…
Reference in a new issue