gif 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/env bash
  2. # Dropbox + Bash = Lighting Fast .gif retrieval
  3. # -----------------------
  4. # Usage: gif <part-of-gif-basename>
  5. # Prerequisites:
  6. # - keep a butt-load of gifs in your "$HOME/Dropbox/Public/gifs" folder
  7. # - Export a DROPBOX_UID variable that has your dropboxusercontent id
  8. # - ...like a boss (https://dl.dropboxusercontent.com/u/2372716/gifs/like-a-boss.gif)
  9. arg=$1
  10. if [ -z $1 ]; then
  11. arg='.'
  12. fi
  13. db_path=http://tyler.zone/public/gifs/
  14. j=0
  15. while read file; do
  16. files[ $j ]="$file"
  17. (( j++ ))
  18. done < <(ls "$HOME/Sync/Public/gifs" | grep -i "$arg")
  19. # Less options:
  20. # -F or --quit-if-one-screen
  21. # -i or --ignore-case (this is smart ignore case)
  22. # -r or --raw-control-chars
  23. # -S or --chop-long-lines (no line wrap)
  24. # -X or --no-init (doesn't clear screen on escape)
  25. printf "%s\n" "${files[@]}" | nl | less -FirSX
  26. printf "[ $(tput setaf 2)?$(tput sgr0) ]\tEnter the gif's number: "
  27. read index
  28. array_pos=$(( $index - 1 ))
  29. files_count=$(( ${#files[@]} - 1 ))
  30. for i in $(seq 0 $files_count); do
  31. if [ $i -eq $array_pos ]; then
  32. if [ $(uname -s) = 'Linux' ]; then
  33. echo "${db_path}${files[ $i ]}" | xclip -sel clip
  34. elif [ $(uname -s) = 'Darwin' ]; then
  35. echo "${db_path}${files[ $i ]}" | pbcopy
  36. fi
  37. break;
  38. fi
  39. done