ptpb / pb

pb is a formerly-lightweight pastebin and url shortener
Other
549 stars 52 forks source link

Script for taking a screenshot, uploading, and copying the URL to clipboard. #162

Closed krompus closed 8 years ago

krompus commented 8 years ago

I currently use this script, bound to a keybind, to quickly upload and share scrots:

#!/bin/bash
img=$(date '+/tmp/%N.png')
scrot -z "$@" $img >/dev/null 2>&1 || exit
res=$(curl -F c=@$img https://ptpb.pw | awk -F'url:' '{print $2}') && (printf $res | xclip; printf "\a")
notify-send `echo $res`

It works very well, and I highly recommend using it! I'm wondering if anyone could suggest a way to modify it to copy to the clipboard rather than primary selection; I keep losing the URL when I accidentally highlight things before pasting.

jetpacktuxedo commented 8 years ago

xclip -selection c will likely put it in the clipboard that you are wanting

Overall, if I am correctly reading what you are trying to do, you could replace the last two lines with: curl -F c=@$img https://ptpb.pw?u=1 | xclip -f -selection c

That should post $img, returning only the URL (due to the ?u=1 at the end), and then send that to xclip which should put it in your ^C/^V clipboard (might vary across systems), while passing the stdin back to stdout with the -f flag.

Edit: just saw you were doing notify-send, so I guess continue saving the results off to a variable so you can notify-send it.

krompus commented 8 years ago

Oh, well, that works!

Haha, I had already tried xclip -selection secondary, but I guess I misread the manpage, as I thought that "secondary" was equivalent to "clipboard".

Thanks a bunch!