share-link 852 B

123456789101112131415161718192021222324252627282930
  1. #!/usr/bin/env bash
  2. ssh_server="bryanroessler.com"
  3. ssh_files_path="/var/www/repos.bryanroessler.com/files"
  4. www_files_path="https://repos.bryanroessler.com/files"
  5. share-link () {
  6. if [[ "$#" -lt 1 ]]; then
  7. echo "You must provide at least one argument"
  8. exit 1
  9. else
  10. local -a links_array
  11. for file in "$@"; do
  12. local ext="${file#*.}"
  13. local random32
  14. random32=$(tr -dc 'a-zA-Z0-9' < /dev/urandom | fold -w 32 | head -n 1)
  15. local random_fname="${random32}.${ext}"
  16. scp "${file}" "${ssh_server}:${ssh_files_path}/${random_fname}"
  17. links_array+=("$www_files_path/$random_fname")
  18. done
  19. if [[ "${#links_array[@]}" == 1 ]]; then
  20. printf '%s' "${links_array[@]}" | xclip -sel c
  21. else
  22. printf '%s\n' "${links_array[@]}" | xclip -sel c
  23. fi
  24. fi
  25. }
  26. share-link "$@"
  27. exit $?