share-link 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/usr/bin/env bash
  2. # A simple script with nautilus, wl-clipboard, and notify-send support for creating one or more shared links
  3. ssh_server="bryanroessler.com"
  4. ssh_files_path="/var/www/repos.bryanroessler.com/files"
  5. www_files_path="https://repos.bryanroessler.com/files"
  6. if [[ "$#" -lt 1 ]]; then
  7. echo "You must provide at least one argument"
  8. exit 1
  9. fi
  10. ! hash wl-copy &>/dev/null && sudo dnf install -y wl-clipboard
  11. if [[ -v NAUTILUS_SCRIPT_SELECTED_URIS ]]; then
  12. readarray -t files <<< "$NAUTILUS_SCRIPT_SELECTED_URIS"
  13. files=("${files[@]#file://}")
  14. files=("${files[@]//\%20/ }")
  15. else
  16. files=("$@")
  17. fi
  18. for file in "${files[@]}"; do
  19. [[ "$file" == "" ]] && continue
  20. echo here
  21. fname="${file##*/}"
  22. random64=$(tr -dc 'a-zA-Z0-9' < /dev/urandom | fold -w 64 | head -n 1)
  23. echo "rsync -a ${file} ${ssh_server}:${ssh_files_path}/${random64}/"
  24. rsync -a "${file}" "${ssh_server}:${ssh_files_path}/${random64}/" &
  25. links_array+=("$www_files_path/${random64}/${fname// /%20}")
  26. done
  27. if [[ "${#links_array[@]}" == 1 ]]; then
  28. printf '%s' "${links_array[@]}" | wl-copy
  29. else
  30. printf '%s\n' "${links_array[@]}" | wl-copy
  31. fi
  32. notify-send -t 3000 -i face-smile "share-link" "File(s) uploaded and link copied to clipboard"
  33. exit 0