bin: sprunge.us => ix.io

This commit is contained in:
Henrik Lissner 2017-12-18 01:12:39 -05:00
parent 9166534b29
commit e8989afb7a
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 50 additions and 67 deletions

50
bin/ix Executable file
View file

@ -0,0 +1,50 @@
#!/usr/bin/env zsh
# Sends file(s) or stdin to a ix.io
set -e
_usage() {
more <<EOL
Usage: ${0:A:t} [FILE...]
Uploads text files/stdin to ix.io.
Options:
-l LANG Specify file extension for syntax highlight
-h This information
Examples:
${0##*/} script.py
${0##*/} -l py sometext
echo "Hello world" | ${0:A:t}
echo "puts 'Hi'" | ${0:A:t} -l rb
EOL
}
#
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
url=$(cat "$@" | curl -s -F 'f:1=<-' ix.io)
# Naive lang detection from file extension
[[ $1 == *.* && -z $lang ]] && lang="${1##*.}"
# Show url
url=$(printf "%s/%s" "$url" "$lang")
echo $url | clip
echo $url

View file

@ -1,67 +0,0 @@
#!/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