Skip to content

Instantly share code, notes, and snippets.

@conspirator
Last active December 31, 2015 19:49
Show Gist options
  • Select an option

  • Save conspirator/8035808 to your computer and use it in GitHub Desktop.

Select an option

Save conspirator/8035808 to your computer and use it in GitHub Desktop.

Revisions

  1. conspirator revised this gist Dec 19, 2013. 1 changed file with 15 additions and 8 deletions.
    23 changes: 15 additions & 8 deletions gif.sh
    Original file line number Diff line number Diff line change
    @@ -17,14 +17,21 @@ 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##*|}
    }
    url="http://api.giphy.com/v1/gifs/random?api_key=dc6zaTOxFJmzC&tag=${*//-o/}"
    json=`curl -s -X GET $url`
    prop='image_original_url'
    url=`jsonval`
    if [[ $* == *-o* ]]
    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
    open $url
    echo "No results"
    else
    echo $url | pbcopy
    echo "In clipboard: $url"
    prop='image_original_url'
    url=`jsonval`
    if [[ $* == *-o* ]]
    then
    open $url
    else
    echo $url | pbcopy
    echo "In clipboard: $url"
    fi
    fi
  2. conspirator created this gist Dec 19, 2013.
    30 changes: 30 additions & 0 deletions gif.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    #!/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 <hello@conspirator.co>
    # 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##*|}
    }
    url="http://api.giphy.com/v1/gifs/random?api_key=dc6zaTOxFJmzC&tag=${*//-o/}"
    json=`curl -s -X GET $url`
    prop='image_original_url'
    url=`jsonval`
    if [[ $* == *-o* ]]
    then
    open $url
    else
    echo $url | pbcopy
    echo "In clipboard: $url"
    fi