#!/bin/bash #---------------------------------------------------- # Author: Florian "Bluewind" Pritz # # Licensed under WTFPL v2 # (see COPYING for full license text) # #---------------------------------------------------- # only works if useragent contains libcurl # Dependencies: curl # Optional: xclip #---------------------------------------------------- VERSION="0.6.1" DELETE=0 EXTENSION="" GET=0 PASTEBIN="http://paste.xinu.at" do_upload() { local EXTRA="" if [[ -n $EXTENSION ]]; then EXTRA="-F extension=$EXTENSION" fi URL="$(curl -# -n -L $EXTRA -F "file=@$1" "$PASTEBIN/file/do_upload")" echo $URL echo -n "$URL" | nohup &> /dev/null xclip } read_stdin() { if tty -s; then echo "^C to exit, ^D to send" fi cat > "$1" } help() { echo "fb-client version $VERSION" echo "usage: [cat |] $(basename "$0") [switches] [file(s)|ID(s)]" echo " Upload/nopaste file/stdin to paste.xinu.at and copy URL to clipboard." echo " ~/.netrc: machine paste.xinu.at password PASSWORD" echo "" echo "Switches:" echo " -e EXTENSION extension for default highlighting (e.g. \"diff\")" echo " -d delete the IDs" echo " -g download the IDs and output on stdout (use with care!)" echo " -h this help" exit 0 } while getopts ":e:gdh" OPTION; do case $OPTION in e) EXTENSION="$OPTARG";; g) GET=1;; d) DELETE=1;; h) help;; \?) echo "unknown option \"-$OPTARG\"" >&2; exit 1;; :) echo "Option \"-$OPTARG\" needs an argument" >&2; exit 1;; esac done shift $((OPTIND - 1)) TMPDIR="$(mktemp -d "/tmp/fb.XXXXXX")" if (($# == 0)); then read_stdin "$TMPDIR/stdin" do_upload "$TMPDIR/stdin" else for i in "$@"; do if [[ $DELETE == 1 ]]; then curl -n -L "$PASTEBIN/file/delete/$i" elif [[ $GET == 1 ]]; then curl -s -o - "$PASTEBIN/$i" else do_upload $i fi done fi