dackdive's blog

新米webエンジニアによる技術ブログ。JavaScript(React), Salesforce, Python など

ターミナルからGistに投稿できるCLIが便利

ブログにコードを貼付ける時、たまに Gist を使ってるんですが
(Apexのsyntax highlight があるので!)
コードはローカルで vim でちょろっと書いて、それを Gist にアップロードできるツールとかないのかなと思ってたらありました。

これ。

インストールから使い方まで超簡単だったのでメモ。

インストール

私は Mac OS X + Homebrew という環境だったので、以下のコマンド一発でOKでした。

$ brew install gist

ログイン

$ gist --login
Obtaining OAuth2 access_token from github.
GitHub username: *******
GitHub password:
Success! https://github.com/settings/applications

Gist に投稿

ローカルで作成した sample.py というファイルを投稿してみます。

$ gist sample.py -d '[python]さんぷる'
https://gist.github.com/35a4c163f9e8e0967cbc

gist [ファイル名] で簡単にできます。
-d は Description を書きたい時のオプションです。

投稿が完了すると URL が表示されるので、アクセスすると...

f:id:dackdive:20141205171526p:plain

ちゃんとアップロードされてる!

というわけで、とっても便利です。
他にもオプションは色々あるようなので、機会があるときに試してみよう。

$ gist --help
Gist (v4.3.0) lets you upload to https://gist.github.com/

...(中略)...

Usage: gist [-o|-c|-e] [-p] [-s] [-R] [-d DESC] [-a] [-u URL] [-P] [-f NAME|-t EXT]* FILE*
       gist --login

        --login                      Authenticate gist on this computer.
    -f, --filename [NAME.EXTENSION]  Sets the filename and syntax type.
    -t, --type [EXTENSION]           Sets the file extension and syntax type.
    -p, --private                    Makes your gist private.
        --no-private
    -d, --description DESCRIPTION    Adds a description to your gist.
    -s, --shorten                    Shorten the gist URL using git.io.
    -u, --update [ URL | ID ]        Update an existing gist.
    -a, --anonymous                  Create an anonymous gist.
    -c, --copy                       Copy the resulting URL to the clipboard
    -e, --embed                      Copy the embed code for the gist to the clipboard
    -o, --open                       Open the resulting URL in a browser
        --no-open
    -P, --paste                      Paste from the clipboard to gist
    -R, --raw                        Raw url of the new gist
    -l, --list [USER]                List all gists for user
    -h, --help                       Show this message.
    -v, --version                    Print the version.