upload.sh 999 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env bash
  2. set -euo pipefail # bash strict mode
  3. SCRIPT_NAME="${0##*/}"
  4. DIR="/tmp/${SCRIPT_NAME}"
  5. DATE="$(date +%s)"
  6. CLIP_FILE="${DIR}/clipboard_${DATE}"
  7. URL_HIST_FILE="${DIR}/history"
  8. display_help() {
  9. echo "Dependencies: curl xclip"
  10. echo "Example:"
  11. echo "- ${SCRIPT_NAME} ./path/to/file.{txt,pdf}"
  12. echo "- ${SCRIPT_NAME} clipboard"
  13. exit 2
  14. }
  15. [[ $# -lt 1 ]] && display_help
  16. file="$1"
  17. mkdir -p "$DIR"
  18. if [[ $file == 'clipboard' ]]; then
  19. file="$CLIP_FILE"
  20. xclip -o -sel clip > "$file"
  21. fi
  22. path=$(realpath "$file")
  23. # url=$(curl -s -F "reqtype=fileupload" -F "fileToUpload=@${path}" https://catbox.moe/user/api.php)
  24. url=$(curl -s -F "reqtype=fileupload" -F "fileToUpload=@${path}" -F "time=24h" https://litterbox.catbox.moe/resources/internals/api.php)
  25. echo "$url" | grep -v "^$" | xclip -selection c
  26. # echo "$url" | sed '/^$/d' | xsel
  27. notify-send "URL copied to clipboard" "Uploaded at: ${url}"
  28. echo "${url} contains file: ${path}" | tee -a "$URL_HIST_FILE"