Skip to content

Instantly share code, notes, and snippets.

@thcipriani
Last active December 26, 2015 15:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thcipriani/7173671 to your computer and use it in GitHub Desktop.
Save thcipriani/7173671 to your computer and use it in GitHub Desktop.
Perfect Gif/Bash Workflow.
#!/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