Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Perfect Gif/Bash Workflow.

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