├── icon.png
├── README-example.gif
├── README-screenshot.png
├── .dockerignore
├── .github
├── dependabot.yml
└── workflows
│ ├── publish.yml
│ └── ci.yml
├── src
├── Properties
│ └── launchSettings.json
├── ActionSelectOptions.cs
├── GiphyCli.csproj
├── GiphyApi.cs
└── Program.cs
├── Dockerfile
├── GiphyCli.sln.DotSettings
├── .vscode
├── launch.json
└── tasks.json
├── GiphyCli.sln
├── docs
└── dotnet-interactive-notebook-sample.ipynb
├── README.md
├── .gitattributes
├── CODE_OF_CONDUCT.md
└── .gitignore
/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DavidDeSloovere/giphy-cli/HEAD/icon.png
--------------------------------------------------------------------------------
/README-example.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DavidDeSloovere/giphy-cli/HEAD/README-example.gif
--------------------------------------------------------------------------------
/README-screenshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DavidDeSloovere/giphy-cli/HEAD/README-screenshot.png
--------------------------------------------------------------------------------
/.dockerignore:
--------------------------------------------------------------------------------
1 | # directories
2 | **/bin/
3 | **/obj/
4 | **/out/
5 |
6 | # files
7 | Dockerfile*
8 | **/*.md
--------------------------------------------------------------------------------
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 | updates:
3 | - package-ecosystem: nuget
4 | directory: "/"
5 | schedule:
6 | interval: daily
--------------------------------------------------------------------------------
/src/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "profiles": {
3 | "GiphyCli": {
4 | "commandName": "Project",
5 | "commandLineArgs": "cheeseburger"
6 | }
7 | }
8 | }
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
2 | WORKDIR /source
3 |
4 | # copy csproj and restore as distinct layers
5 | COPY ./src/*.csproj .
6 | RUN dotnet restore
7 |
8 | # copy and publish app and libraries
9 | COPY ./src/. .
10 | RUN dotnet publish -c Release -o /app --no-restore
11 |
12 | # final stage/image
13 | FROM mcr.microsoft.com/dotnet/runtime:6.0
14 | WORKDIR /app
15 | COPY --from=build /app .
16 | ENTRYPOINT ["dotnet", "GiphyCli.dll", "--no-questions-asked"]
--------------------------------------------------------------------------------
/src/ActionSelectOptions.cs:
--------------------------------------------------------------------------------
1 | namespace GiphyCli
2 | {
3 | using System.ComponentModel.DataAnnotations;
4 |
5 | internal enum ActionSelectOptions
6 | {
7 | [Display(Name = "Open Giphy.com")]
8 | OpenGiphyCom,
9 |
10 | [Display(Name = "Copy gif URL to clipboard")]
11 | CopyUrl,
12 |
13 | [Display(Name = "Copy markdown to clipboard")]
14 | CopyMarkdown,
15 |
16 | [Display(Name ="Exit")]
17 | Exit,
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/GiphyCli.sln.DotSettings:
--------------------------------------------------------------------------------
1 |
2 | True
3 | True
--------------------------------------------------------------------------------
/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "0.2.0",
3 | "configurations": [
4 | {
5 | // Use IntelliSense to find out which attributes exist for C# debugging
6 | // Use hover for the description of the existing attributes
7 | // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
8 | "name": ".NET Core Launch (console)",
9 | "type": "coreclr",
10 | "request": "launch",
11 | "preLaunchTask": "build",
12 | // If you have changed target frameworks, make sure to update the program path.
13 | "program": "${workspaceFolder}/src/bin/Debug/net6.0/GiphyCli.dll",
14 | "args": [],
15 | "cwd": "${workspaceFolder}/src",
16 | // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
17 | "console": "internalConsole",
18 | "stopAtEntry": false
19 | },
20 | {
21 | "name": ".NET Core Attach",
22 | "type": "coreclr",
23 | "request": "attach"
24 | }
25 | ]
26 | }
--------------------------------------------------------------------------------
/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "2.0.0",
3 | "tasks": [
4 | {
5 | "label": "build",
6 | "command": "dotnet",
7 | "type": "process",
8 | "args": [
9 | "build",
10 | "${workspaceFolder}/src/GiphyCli.csproj",
11 | "/property:GenerateFullPaths=true",
12 | "/consoleloggerparameters:NoSummary"
13 | ],
14 | "problemMatcher": "$msCompile"
15 | },
16 | {
17 | "label": "publish",
18 | "command": "dotnet",
19 | "type": "process",
20 | "args": [
21 | "publish",
22 | "${workspaceFolder}/src/GiphyCli.csproj",
23 | "/property:GenerateFullPaths=true",
24 | "/consoleloggerparameters:NoSummary"
25 | ],
26 | "problemMatcher": "$msCompile"
27 | },
28 | {
29 | "label": "watch",
30 | "command": "dotnet",
31 | "type": "process",
32 | "args": [
33 | "watch",
34 | "run",
35 | "--project",
36 | "${workspaceFolder}/src/GiphyCli.csproj"
37 | ],
38 | "problemMatcher": "$msCompile"
39 | }
40 | ]
41 | }
--------------------------------------------------------------------------------
/.github/workflows/publish.yml:
--------------------------------------------------------------------------------
1 | name: Publish
2 |
3 | on:
4 | workflow_dispatch:
5 |
6 | jobs:
7 | build_nuget:
8 | runs-on: ubuntu-latest
9 | env:
10 | DOTNET_NOLOGO: true
11 |
12 | steps:
13 | - name: Checkout
14 | uses: actions/checkout@v2
15 | with:
16 | fetch-depth: 0
17 |
18 | - name: .NET SDK
19 | uses: actions/setup-dotnet@v1
20 | with:
21 | dotnet-version: "6.0"
22 |
23 | - name: Install dependencies
24 | run: dotnet restore
25 |
26 | - name: Build
27 | run: dotnet build --configuration Release --no-restore
28 |
29 | - name: Publish
30 | id: publish_nuget
31 | uses: rohith/publish-nuget@v2
32 | with:
33 | PROJECT_FILE_PATH: src/GiphyCli.csproj
34 | NUGET_KEY: ${{secrets.NUGET_API_KEY}}
35 |
36 | build_docker:
37 | runs-on: ubuntu-latest
38 |
39 | permissions:
40 | contents: read
41 | packages: write
42 |
43 | steps:
44 | - name: Docker Login to Docker Hub
45 | uses: docker/login-action@v2
46 | with:
47 | username: ${{ secrets.DOCKER_USERNAME }}
48 | password: ${{ secrets.DOCKER_TOKEN }}
49 |
50 | - name: Build and push to Docker Hub
51 | uses: docker/build-push-action@v3
52 | with:
53 | push: true
54 | tags: daviddesloovere/giphy-cli:latest
55 |
--------------------------------------------------------------------------------
/GiphyCli.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.28010.2003
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GiphyCli", "src\GiphyCli.csproj", "{BFB541A5-D745-4E56-B52B-3284AAA87D82}"
7 | EndProject
8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{B4F10BDC-E9D8-4932-A1FD-7FE0EBD9336D}"
9 | ProjectSection(SolutionItems) = preProject
10 | README.md = README.md
11 | EndProjectSection
12 | EndProject
13 | Global
14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
15 | Debug|Any CPU = Debug|Any CPU
16 | Release|Any CPU = Release|Any CPU
17 | EndGlobalSection
18 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
19 | {BFB541A5-D745-4E56-B52B-3284AAA87D82}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
20 | {BFB541A5-D745-4E56-B52B-3284AAA87D82}.Debug|Any CPU.Build.0 = Debug|Any CPU
21 | {BFB541A5-D745-4E56-B52B-3284AAA87D82}.Release|Any CPU.ActiveCfg = Release|Any CPU
22 | {BFB541A5-D745-4E56-B52B-3284AAA87D82}.Release|Any CPU.Build.0 = Release|Any CPU
23 | EndGlobalSection
24 | GlobalSection(SolutionProperties) = preSolution
25 | HideSolutionNode = FALSE
26 | EndGlobalSection
27 | GlobalSection(ExtensibilityGlobals) = postSolution
28 | SolutionGuid = {5571FEB9-6F9A-40D1-BBD0-966726336622}
29 | EndGlobalSection
30 | EndGlobal
31 |
--------------------------------------------------------------------------------
/docs/dotnet-interactive-notebook-sample.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "# Giphy CLI\n",
8 | "\n",
9 | "Example of Giphy CLI .NET global tool in a notebook with the new `--markdown` option available in v2.0.\n",
10 | "\n",
11 | "To install the tool:\n",
12 | "`dotnet tool install --global giphycli`\n",
13 | "\n",
14 | "If you need to update the tool:\n",
15 | "`dotnet tool update --global giphycli`\n",
16 | "\n",
17 | "Needs .NET Interactive Notebooks for VS Code:\n",
18 | "https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.dotnet-interactive-vscode\n",
19 | "\n",
20 | "More info: \n",
21 | "https://channel9.msdn.com/Events/dotnetConf/2020/S231\n",
22 | ""
23 | ]
24 | },
25 | {
26 | "cell_type": "code",
27 | "execution_count": 1,
28 | "metadata": {},
29 | "source": [
30 | "#!pwsh\n",
31 | "giphy.exe work --markdown | Out-Display -MimeType \"text/markdown\""
32 | ],
33 | "outputs": [
34 | {
35 | "output_type": "execute_result",
36 | "data": {
37 | "text/markdown": ""
38 | },
39 | "execution_count": 1,
40 | "metadata": {}
41 | }
42 | ]
43 | }
44 | ],
45 | "metadata": {
46 | "kernelspec": {
47 | "display_name": ".NET (C#)",
48 | "language": "C#",
49 | "name": ".net-csharp"
50 | },
51 | "language_info": {
52 | "file_extension": ".cs",
53 | "mimetype": "text/x-csharp",
54 | "name": "C#",
55 | "pygments_lexer": "csharp",
56 | "version": "8.0"
57 | }
58 | },
59 | "nbformat": 4,
60 | "nbformat_minor": 4
61 | }
--------------------------------------------------------------------------------
/src/GiphyCli.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | giphy
4 | True
5 | Exe
6 | net6.0
7 | DavidDeSloovere
8 |
9 | Unofficial Giphy CLI as global dotnet tool - get that url or markdown fast.
10 | > `giphy lolcats`
11 | https://github.com/DavidDeSloovere/giphy-cli
12 | https://github.com/DavidDeSloovere/giphy-cli.git
13 | giphy cli
14 | Giphy CLI
15 | git
16 |
17 | 2.2.0
18 | Extra `-m` option to only output markdown.
19 | icon.png
20 | MIT
21 | readme.md
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/.github/workflows/ci.yml:
--------------------------------------------------------------------------------
1 | name: CI build
2 |
3 | on:
4 | push:
5 | branches: [main]
6 | pull_request:
7 | branches: [main]
8 |
9 | jobs:
10 | build_nuget:
11 | runs-on: ubuntu-latest
12 |
13 | env:
14 | DOTNET_NOLOGO: true
15 | DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
16 |
17 | steps:
18 | - name: Checkout
19 | uses: actions/checkout@v2
20 | with:
21 | fetch-depth: 0
22 |
23 | - name: .NET SDK
24 | uses: actions/setup-dotnet@v1
25 | with:
26 | dotnet-version: "6.0"
27 |
28 | - name: Install dependencies
29 | run: dotnet restore
30 |
31 | - name: Build
32 | run: dotnet build --configuration Release --no-restore
33 | # - name: Test
34 | # run: dotnet test --no-restore --verbosity normal
35 |
36 | - name: Pack
37 | run: dotnet pack ./src/GiphyCli.csproj -c Release -o ./artifacts --no-build
38 |
39 | - name: Artifacts
40 | uses: actions/upload-artifact@v2
41 | with:
42 | name: artifacts
43 | path: artifacts/**/*
44 |
45 | build_docker:
46 | runs-on: ubuntu-latest
47 |
48 | env:
49 | REGISTRY: ghcr.io
50 |
51 | permissions:
52 | contents: read
53 | packages: write
54 |
55 | steps:
56 | - name: Get current date # get the date of the build
57 | id: date
58 | run: echo "::set-output name=date::$(date +'%Y-%m-%d--%M-%S')"
59 |
60 | - name: Docker Login
61 | uses: docker/login-action@v2
62 | with:
63 | registry: ${{ env.REGISTRY }}
64 | username: ${{ github.actor }}
65 | password: ${{ secrets.GITHUB_TOKEN }}
66 |
67 | - name: Build and push
68 | uses: docker/build-push-action@v3
69 | with:
70 | push: ${{ github.ref == 'refs/heads/main' }}
71 | tags: |
72 | ghcr.io/daviddesloovere/giphy-cli:${{ steps.date.outputs.date }}
73 | ghcr.io/daviddesloovere/giphy-cli:latest
74 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # giphy-cli
2 |
3 | A CLI, published as Docker image and .NET Global tool, to search for a gif on Giphy and optionally open the link in the browser or copy the link or markdown to the clipboard.
4 |
5 | Was featured in a presentation about **.NET interactive notebooks** at .NET Conf 2020: https://youtu.be/938jBJ-tK3c?t=1025
6 |
7 | There is an example notebook included [dotnet-interactive-notebook-sample.ipynb](https://github.com/DavidDeSloovere/giphy-cli/blob/main/docs/dotnet-interactive-notebook-sample.ipynb)
8 |
9 | Comments, ideas, bug reports and PR are welcome here.
10 |
11 | 
12 |
13 | ## Docker
14 |
15 | You can run this CLI via Docker. This will output markdown and a link to giphy.com.
16 |
17 | Published version on Docker Hub:
18 |
19 | `docker run --rm -it daviddesloovere/giphy-cli:latest "lolcats"`
20 |
21 | Latest on GitHub:
22 |
23 | `docker run --rm -it ghcr.io/daviddesloovere/giphy-cli:latest "lolcats"`
24 |
25 | ## .NET global tool
26 |
27 | Head over to [GiphyCli on NuGet](https://www.nuget.org/packages/GiphyCli) or continue reading:
28 |
29 | You'll need the [.NET 6 runtime](https://www.microsoft.com/net/download) or newer.
30 |
31 | Install the Giphy CLI with this command:
32 |
33 | ```
34 | > dotnet tool install --global GiphyCli
35 | ```
36 |
37 | Update the Giphy CLI with this command:
38 |
39 | ```
40 | > dotnet tool update --global Giphycli
41 | ```
42 |
43 | To search for a gif, simply use
44 |
45 | ```
46 | > giphy lolcats
47 | ```
48 |
49 | ## Usage
50 |
51 | ```
52 | > giphy cheeseburger
53 | > giphy "awesome cheeseburger"
54 | ```
55 |
56 | Output markdown only, great for using in notebooks.
57 |
58 | ```
59 | > giphy cheeseburger -m
60 | > giphy cheeseburger --markdown
61 | ```
62 |
63 | Giphy CLI now an includes interactive prompt.
64 |
65 | 
66 |
67 | Have markdown copied to clipboard _et voila_.
68 |
69 | 
70 |
71 | ## Features
72 |
73 | - Interactive prompt: Open giphy.com URL, copy .gif deeplink or **copy markdown to clipboard**
74 | - Preview image in iTerm2 (PR by https://github.com/slang25)
75 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6 |
7 | ## Our Standards
8 |
9 | Examples of behavior that contributes to creating a positive environment include:
10 |
11 | * Using welcoming and inclusive language
12 | * Being respectful of differing viewpoints and experiences
13 | * Gracefully accepting constructive criticism
14 | * Focusing on what is best for the community
15 | * Showing empathy towards other community members
16 |
17 | Examples of unacceptable behavior by participants include:
18 |
19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances
20 | * Trolling, insulting/derogatory comments, and personal or political attacks
21 | * Public or private harassment
22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission
23 | * Other conduct which could reasonably be considered inappropriate in a professional setting
24 |
25 | ## Our Responsibilities
26 |
27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28 |
29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30 |
31 | ## Scope
32 |
33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34 |
35 | ## Enforcement
36 |
37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at david.desloovere@outlook.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38 |
39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40 |
41 | ## Attribution
42 |
43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
44 |
45 | [homepage]: http://contributor-covenant.org
46 | [version]: http://contributor-covenant.org/version/1/4/
47 |
--------------------------------------------------------------------------------
/src/GiphyApi.cs:
--------------------------------------------------------------------------------
1 | namespace GiphyCli
2 | {
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using RestSharp;
7 | using RestSharp.Deserializers;
8 |
9 | public class GiphyApi
10 | {
11 | const string BaseUrl = "https://api.giphy.com";
12 |
13 | readonly string apiKey;
14 |
15 | public GiphyApi(string apiKey)
16 | {
17 | this.apiKey = apiKey;
18 | }
19 |
20 | public GifObject Search(string search)
21 | {
22 | var restRequest = new RestRequest();
23 | restRequest.Resource = "/v1/gifs/search?api_key={api_key}&q={q}&limit=1";
24 | restRequest.AddParameter("q", search, ParameterType.UrlSegment);
25 | var result = this.Execute(restRequest);
26 | var rawGifObject = result.Data.FirstOrDefault();
27 | if (rawGifObject == null)
28 | {
29 | return null;
30 | }
31 |
32 | return new GifObject
33 | {
34 | Id = rawGifObject.Id,
35 | Slug = rawGifObject.Slug,
36 | Title = rawGifObject.Title,
37 | Url = rawGifObject.Url,
38 | GifUrl = rawGifObject.Images.OriginalGif.Url,
39 | };
40 | }
41 |
42 | private T Execute(RestRequest request) where T : new()
43 | {
44 | var client = new RestClient();
45 | client.BaseUrl = new System.Uri(BaseUrl);
46 | request.AddParameter("api_key", this.apiKey, ParameterType.UrlSegment); // used on every request
47 | var response = client.Execute(request);
48 |
49 | if (response.ErrorException != null)
50 | {
51 | const string message = "Error retrieving response. Check inner details for more info.";
52 | var giphyException = new ApplicationException(message, response.ErrorException);
53 | throw giphyException;
54 | }
55 | return response.Data;
56 | }
57 |
58 | private class RawGifSearchResult
59 | {
60 | public List Data { get; set; }
61 | }
62 |
63 | private class RawGifObject
64 | {
65 | // https://developers.giphy.com/docs/#gif-object
66 | public string Id { get; set; }
67 |
68 | public string Slug { get; set; }
69 |
70 | public string Title { get; set; }
71 |
72 | public string Url { get; set; }
73 |
74 | public RawGifImagesObject Images { get; set; }
75 | }
76 |
77 | private class RawGifImagesObject
78 | {
79 | [DeserializeAs(Name = "fixed_width")]
80 | public RawImageObject FixedWidthGif { get; set; }
81 |
82 | [DeserializeAs(Name = "original")]
83 | public RawImageObject OriginalGif { get; set; }
84 | }
85 |
86 | private class RawImageObject
87 | {
88 | public string Url { get; set; }
89 | }
90 | }
91 |
92 | public class GifObject
93 | {
94 | public string Id { get; set; }
95 |
96 | public string Slug { get; set; }
97 |
98 | public string Title { get; set; }
99 |
100 | public string Url { get; set; }
101 |
102 | public string GifUrl { get; set; }
103 | }
104 | }
--------------------------------------------------------------------------------
/src/Program.cs:
--------------------------------------------------------------------------------
1 | namespace GiphyCli
2 | {
3 | using System;
4 | using System.ComponentModel.DataAnnotations;
5 | using System.Diagnostics;
6 | using System.Net.Http;
7 | using McMaster.Extensions.CommandLineUtils;
8 | using TextCopy;
9 |
10 | [Command(Description = "CLI to quickly get a Giphy link or markdown for your search (which should always be lolcats).")]
11 | public class Program
12 | {
13 | // one API key for now
14 | private const string ApiKey = "1TePlQM14HIjQLf8QyivWGH9NwAVQXsd";
15 |
16 | public static int Main(string[] args) => CommandLineApplication.Execute(args);
17 |
18 | [Argument(0, Description = "The search to execute.")]
19 | [Required]
20 | public string Search { get; }
21 |
22 | [Option(ShowInHelpText = true, ShortName = "m", LongName = "markdown", Description = "Output only markdown")]
23 | public bool MarkdownOnly { get; set; }
24 |
25 | [Option(ShowInHelpText = true, ShortName = "nq", LongName = "no-questions-asked", Description = "Output markdown and link - don't ask any questions")]
26 | public bool NoQuestionsAsked { get; set; }
27 |
28 | private void OnExecute()
29 | {
30 | if (!this.MarkdownOnly)
31 | {
32 | Console.WriteLine("");
33 | Colorful.Console.WriteAscii("GIPHY CLI");
34 | Console.WriteLine("");
35 | Console.WriteLine($"Searching giphy.com API for `{this.Search}`...");
36 | Console.WriteLine("");
37 | }
38 |
39 | var client = new GiphyApi(ApiKey);
40 | var result = client.Search(this.Search);
41 | if (result == null)
42 | {
43 | Console.WriteLine("Oh no. Didn't get any results back. What crazy thing are you searching for?");
44 | Console.WriteLine("");
45 | return;
46 | }
47 |
48 | var markdownText = $"";
49 | if (this.MarkdownOnly)
50 | {
51 | Console.WriteLine(markdownText);
52 | return;
53 | }
54 |
55 | var gifUrlText = $"{result.GifUrl}";
56 |
57 | Console.WriteLine($"> Found `{result.Title}`");
58 | Console.WriteLine($"{result.Url}");
59 | Console.WriteLine("");
60 |
61 | Console.WriteLine("> GIF URL");
62 | Console.WriteLine(gifUrlText);
63 | Console.WriteLine("");
64 |
65 | Console.WriteLine("> MARKDOWN");
66 | Console.WriteLine(markdownText);
67 | Console.WriteLine("");
68 |
69 | if (this.NoQuestionsAsked)
70 | {
71 | Thanks();
72 | return;
73 | }
74 |
75 | if (Environment.GetEnvironmentVariable("TERM_PROGRAM") == "iTerm.app")
76 | {
77 | Console.Write("\u001B]1337");
78 | Console.Write(";File=;inline=1:");
79 | using (var httpClient = new HttpClient())
80 | {
81 | var bytes = httpClient.GetByteArrayAsync(result.GifUrl).GetAwaiter().GetResult();
82 | Console.Write(Convert.ToBase64String(bytes));
83 | }
84 | Console.Write("\u0007");
85 | Console.WriteLine("");
86 | }
87 |
88 | Console.WriteLine("");
89 | // Awesome lib: https://github.com/shibayan/Sharprompt
90 | var value = Sharprompt.Prompt.Select("What should I do next?");
91 | switch (value)
92 | {
93 | case ActionSelectOptions.OpenGiphyCom:
94 | OpenBrowser(result.Url);
95 | break;
96 |
97 | case ActionSelectOptions.CopyUrl:
98 | ClipboardService.SetText(gifUrlText);
99 | break;
100 |
101 | case ActionSelectOptions.CopyMarkdown:
102 | ClipboardService.SetText(markdownText);
103 | break;
104 | }
105 |
106 | Thanks();
107 | }
108 |
109 | private static void Thanks()
110 | {
111 | Console.WriteLine("");
112 | Console.WriteLine("Thanks for using the Giphy CLI - visit https://github.com/DavidDeSloovere/giphy-cli for comments, issues, ...");
113 | }
114 |
115 | public static void OpenBrowser(string url)
116 | {
117 | var psi = new ProcessStartInfo
118 | {
119 | FileName = url,
120 | UseShellExecute = true
121 | };
122 | Process.Start(psi);
123 | }
124 | }
125 | }
126 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | bld/
21 | [Bb]in/
22 | [Oo]bj/
23 | [Ll]og/
24 |
25 | # Visual Studio 2015 cache/options directory
26 | .vs/
27 | # Uncomment if you have tasks that create the project's static files in wwwroot
28 | #wwwroot/
29 |
30 | # MSTest test Results
31 | [Tt]est[Rr]esult*/
32 | [Bb]uild[Ll]og.*
33 |
34 | # NUNIT
35 | *.VisualState.xml
36 | TestResult.xml
37 |
38 | # Build Results of an ATL Project
39 | [Dd]ebugPS/
40 | [Rr]eleasePS/
41 | dlldata.c
42 |
43 | # DNX
44 | project.lock.json
45 | project.fragment.lock.json
46 | artifacts/
47 |
48 | *_i.c
49 | *_p.c
50 | *_i.h
51 | *.ilk
52 | *.meta
53 | *.obj
54 | *.pch
55 | *.pdb
56 | *.pgc
57 | *.pgd
58 | *.rsp
59 | *.sbr
60 | *.tlb
61 | *.tli
62 | *.tlh
63 | *.tmp
64 | *.tmp_proj
65 | *.log
66 | *.vspscc
67 | *.vssscc
68 | .builds
69 | *.pidb
70 | *.svclog
71 | *.scc
72 |
73 | # Chutzpah Test files
74 | _Chutzpah*
75 |
76 | # Visual C++ cache files
77 | ipch/
78 | *.aps
79 | *.ncb
80 | *.opendb
81 | *.opensdf
82 | *.sdf
83 | *.cachefile
84 | *.VC.db
85 | *.VC.VC.opendb
86 |
87 | # Visual Studio profiler
88 | *.psess
89 | *.vsp
90 | *.vspx
91 | *.sap
92 |
93 | # TFS 2012 Local Workspace
94 | $tf/
95 |
96 | # Guidance Automation Toolkit
97 | *.gpState
98 |
99 | # ReSharper is a .NET coding add-in
100 | _ReSharper*/
101 | *.[Rr]e[Ss]harper
102 | *.DotSettings.user
103 |
104 | # JustCode is a .NET coding add-in
105 | .JustCode
106 |
107 | # TeamCity is a build add-in
108 | _TeamCity*
109 |
110 | # DotCover is a Code Coverage Tool
111 | *.dotCover
112 |
113 | # NCrunch
114 | _NCrunch_*
115 | .*crunch*.local.xml
116 | nCrunchTemp_*
117 |
118 | # MightyMoose
119 | *.mm.*
120 | AutoTest.Net/
121 |
122 | # Web workbench (sass)
123 | .sass-cache/
124 |
125 | # Installshield output folder
126 | [Ee]xpress/
127 |
128 | # DocProject is a documentation generator add-in
129 | DocProject/buildhelp/
130 | DocProject/Help/*.HxT
131 | DocProject/Help/*.HxC
132 | DocProject/Help/*.hhc
133 | DocProject/Help/*.hhk
134 | DocProject/Help/*.hhp
135 | DocProject/Help/Html2
136 | DocProject/Help/html
137 |
138 | # Click-Once directory
139 | publish/
140 |
141 | # Publish Web Output
142 | *.[Pp]ublish.xml
143 | *.azurePubxml
144 | # TODO: Comment the next line if you want to checkin your web deploy settings
145 | # but database connection strings (with potential passwords) will be unencrypted
146 | #*.pubxml
147 | *.publishproj
148 |
149 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
150 | # checkin your Azure Web App publish settings, but sensitive information contained
151 | # in these scripts will be unencrypted
152 | PublishScripts/
153 |
154 | # NuGet Packages
155 | *.nupkg
156 | # The packages folder can be ignored because of Package Restore
157 | **/packages/*
158 | # except build/, which is used as an MSBuild target.
159 | !**/packages/build/
160 | # Uncomment if necessary however generally it will be regenerated when needed
161 | #!**/packages/repositories.config
162 | # NuGet v3's project.json files produces more ignoreable files
163 | *.nuget.props
164 | *.nuget.targets
165 |
166 | # Microsoft Azure Build Output
167 | csx/
168 | *.build.csdef
169 |
170 | # Microsoft Azure Emulator
171 | ecf/
172 | rcf/
173 |
174 | # Windows Store app package directories and files
175 | AppPackages/
176 | BundleArtifacts/
177 | Package.StoreAssociation.xml
178 | _pkginfo.txt
179 |
180 | # Visual Studio cache files
181 | # files ending in .cache can be ignored
182 | *.[Cc]ache
183 | # but keep track of directories ending in .cache
184 | !*.[Cc]ache/
185 |
186 | # Others
187 | ClientBin/
188 | ~$*
189 | *~
190 | *.dbmdl
191 | *.dbproj.schemaview
192 | *.jfm
193 | *.pfx
194 | *.publishsettings
195 | node_modules/
196 | orleans.codegen.cs
197 |
198 | # Since there are multiple workflows, uncomment next line to ignore bower_components
199 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
200 | #bower_components/
201 |
202 | # RIA/Silverlight projects
203 | Generated_Code/
204 |
205 | # Backup & report files from converting an old project file
206 | # to a newer Visual Studio version. Backup files are not needed,
207 | # because we have git ;-)
208 | _UpgradeReport_Files/
209 | Backup*/
210 | UpgradeLog*.XML
211 | UpgradeLog*.htm
212 |
213 | # SQL Server files
214 | *.mdf
215 | *.ldf
216 |
217 | # Business Intelligence projects
218 | *.rdl.data
219 | *.bim.layout
220 | *.bim_*.settings
221 |
222 | # Microsoft Fakes
223 | FakesAssemblies/
224 |
225 | # GhostDoc plugin setting file
226 | *.GhostDoc.xml
227 |
228 | # Node.js Tools for Visual Studio
229 | .ntvs_analysis.dat
230 |
231 | # Visual Studio 6 build log
232 | *.plg
233 |
234 | # Visual Studio 6 workspace options file
235 | *.opt
236 |
237 | # Visual Studio LightSwitch build output
238 | **/*.HTMLClient/GeneratedArtifacts
239 | **/*.DesktopClient/GeneratedArtifacts
240 | **/*.DesktopClient/ModelManifest.xml
241 | **/*.Server/GeneratedArtifacts
242 | **/*.Server/ModelManifest.xml
243 | _Pvt_Extensions
244 |
245 | # Paket dependency manager
246 | .paket/paket.exe
247 | paket-files/
248 |
249 | # FAKE - F# Make
250 | .fake/
251 |
252 | # JetBrains Rider
253 | .idea/
254 | *.sln.iml
255 |
256 | # CodeRush
257 | .cr/
258 |
259 | # Python Tools for Visual Studio (PTVS)
260 | __pycache__/
261 | *.pyc
--------------------------------------------------------------------------------