scrotpomf.sh 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/bin/bash
  2. # scrot -> pomf.se, by @__akiaki
  3. SCROTARGS=()
  4. while (( "$#" )); do
  5. if [ "$1" == "--delete" ]; then
  6. DELETE=1
  7. else
  8. SCROTARGS+=($1)
  9. fi
  10. shift
  11. done
  12. # take the shot
  13. FILE="`scrot ${SCROTARGS[@]} -e 'echo -n $f'`"
  14. # upload it and grab the URL
  15. BASE=""; TRY=0
  16. while [[ "x$BASE" == "x" ]] && [[ $TRY -lt 3 ]]; do
  17. TRY=$[$TRY + 1]
  18. echo "Uploading... (try $TRY)"
  19. JSON="`curl -sf -F "files[]=@$FILE" http://pomf.se/upload.php`"
  20. BASE="`echo "$JSON" | python -c "from __future__ import print_function;print(__import__('json').loads(__import__('sys').stdin.read())['files'][0]['url'])" 2>/dev/null`"
  21. done
  22. if [[ $TRY -eq 3 ]]; then
  23. echo "Giving up."
  24. exit 1
  25. fi
  26. URL="http://a.pomf.se/$BASE"
  27. # copy the URL to the clipboard
  28. if [[ `type -p xclip` ]]; then
  29. echo -n "$URL" | xclip -selection clipboard
  30. echo "$URL (has been copied to clipboard)"
  31. elif [[ `type -p pbcopy` ]]; then
  32. echo -n "$URL" | pbcopy
  33. echo "$URL (has been copied to clipboard)"
  34. else
  35. echo "$URL"
  36. fi
  37. if [[ $DELETE -eq 1 ]]; then
  38. rm -f "${FILE}"
  39. fi