#!/bin/sh # # Grab a random gif from giphy.com # # Example: # $ gif // places a gif url on your clipboard # $ gif -o // opens a gif url in your default browser # $ gif chicago+bulls // places a Bulls-related gif url on your clipboard # $ gif chicago+bulls -o // opens a Bulls-related gif url in your default browser # # Author: Christopher Webb # Website: conspirator.co # Updated: 12/18/13 # function jsonval { temp=`echo $json | sed 's/\\\\\//\//g' | sed 's/[{}]//g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | sed 's/\"\:\"/\|/g' | sed 's/[\,]/ /g' | sed 's/\"//g' | grep -w $prop` echo ${temp##*|} } api="http://api.giphy.com/v1/gifs/random?api_key=dc6zaTOxFJmzC&tag=${*//-o/}" json=`curl -s -X GET $api` prop='data' dataCheck=`jsonval` if [[ ${dataCheck//data:/} == *[]* ]] then echo "No results" else prop='image_original_url' url=`jsonval` if [[ $* == *-o* ]] then open $url else echo $url | pbcopy echo "In clipboard: $url" fi fi