~ecs/dotfiles

295b8fe65dadfcdd3b5f93a0429e0a06e75627d3 — Eyal Sawady 22 days ago 88e7d63
bin/upload: implement custom extensions
1 files changed, 19 insertions(+), 5 deletions(-)

M bin/upload
M bin/upload => bin/upload +19 -5
@@ 20,18 20,32 @@ localpath="$(mktemp)"
trap "rm $localpath" EXIT
remotefile=""

while getopts e:h opt; do
	case "$opt" in
		e)
			remotefile=".$OPTARG"
			;;
		?)
			printf "usage: %s [-e <extension] [<file>]\n" "$0"
			exit 1
			;;
	esac
done

shift "$((OPTIND - 1))"

if [ $# -eq 0 ]; then
	wl-paste --no-newline >"$localpath"
	remotefile=".txt"
	remotefile="${remotefile:-.txt}"
elif [ "z$1" = "z-" ]; then
	cat >"$localpath"
	remotefile=".txt"
	remotefile="${remotefile:-.txt}"
else
	cp "$1" "$localpath"
	if [ "z${1##*.}" = "z$1" ]; then
		remotefile=".txt"
	if [ "z${1##*.}" != "z$1" ]; then
		remotefile="${remotefile:-.${1##*.}}"
	else
		remotefile=".${1##*.}"
		remotefile="${remotefile:-.txt}"
	fi
fi