: ${PB_INSTANCE:=ptpb.pw} : ${PB_CURL_ARGS:=""} PASTE_LOG_DIR="$HOME/.local/pb/$PB_INSTANCE" local LIVE="$PASTE_LOG_DIR/live" local DEAD="$PASTE_LOG_DIR/dead" mkdir -p "$LIVE" "$DEAD" function pbupload() { local res if [ "$#" -eq 0 ]; then # paste from stdin res=$(curl $PB_CURL_ARGS -sF c=@- "https://$PB_INSTANCE$PB_URL_PATH") else res=$(curl $PB_CURL_ARGS -sF "c=@$1" "https://$PB_INSTANCE$PB_URL_PATH") fi local full_name=$(awk '/url/ { print $2 }' <<<"$res" | tr -d '\n' | sed 's@.*://.*/\(.*\)@\1@') local name="${full_name%%.*}" if [ -z "$name" ]; then echo "$res" 1>&2 exit 1 fi if [ ! -e "$LIVE/$name" ]; then echo "$res" > "$LIVE/$name" fi echo "$name" } local function pbexists() { [ -e "$LIVE/$1" ] } local function pbget() { local short="$1" local attr="$2" awk "/$attr/ { print \$2 }" < "$LIVE/$short" | tr -d '\n' } local function pbclip() { local name="$1" local url=$(sed 's@.*://\(.*\)@\1@' <<<"$2") if [[ -v DISPLAY ]]; then xclip -i <<<"$url" notify-send "$name" "Copied to clipboard: $url" fi } # pb upload function pbu() { local short=$(pbupload "$@") local url=$(pbget "$short" "url") pbclip "pbu" "$url" } # pb change function pbc() { local short=$1 local file=$2 local uuid=$(pbget "$short" "uuid") if [ "$#" -eq 1 ]; then # update from stdin curl $PB_CURL_ARGS -X PUT -F c=@- "https://$PB_INSTANCE/$uuid" else curl $PB_CURL_ARGS -X PUT -F "c=@$file" "https://$PB_INSTANCE/$uuid" fi } # pb list function pbl() { find "$LIVE" -type f -exec basename {} \; } # pb delete, takes short id # someone please fix this function pbd() { local uuid=$(pbget "$1" "uuid") curl $PB_CURL_ARGS -X DELETE "https://$PB_INSTANCE/$uuid" mv "$LIVE/$1" "$DEAD/" } # pb delete all function pbdall() { for p in $(pbl); pbd $p } # pb shorten function pbs() { local name=$(PB_URL_PATH="/u" pbupload) local url=$(pbget "$name" "url") pbclip "pbs" "$url" } # pb vanity function pbv() { local name="$1" shift pbexists "~$1" && pbd "~$1" local short=$(PB_URL_PATH="/~$1" pbupload "$@") local url=$(pbget "$short" "url") pbclip "pbv" "$url" } # pb image function pbi() { local tmp=$(mktemp '/tmp/XXXXXXXX') scrot --select --quality 0 $tmp.png pngcrush -ow $tmp.png # Remove .png suffix, for shorter URL # Relies on sending the correct mimetype local short=$(pbupload $tmp.png) local url=$(pbget "$short" "url") pbclip "pbi" "$(echo $url | sed 's@\(.*\)\.png@\1@')" } # pb record function pbr() { local tmp=$(mktemp '/tmp/XXXXXXXX') asciinema rec $tmp local short=$(pbupload $tmp) pbclip "pbr" "$PB_INSTANCE/t/$short" } function termbin() { nc termbin.com 9999 }