gistyのセットアップ

gistへの投稿を便利してくれるらしい、とのことなのでセットアップしてみたという話。

セットアップ手順

https://github.com/swdyh/gisty のREADMEにあるとおりにやれば良いみたい。

やってみた

gem インストール

% gem install gisty
Fetching: gisty-0.2.3.gem (100%)
Successfully installed gisty-0.2.3
1 gem installed
Installing ri documentation for gisty-0.2.3...
Building YARD (yri) index for gisty-0.2.3...
Installing RDoc documentation for gisty-0.2.3

作業ディレクトリの指定

自分の場合は、以下を追記

% vim ~/.zshenv

export GISTY_DIR="$HOME/work/gists"

Github API アクセストークンの取得

gistyのREADMEにあるように https://swdyh-gisty.heroku.com/ を利用して取得できるらしいけれども、 今回はGithub APIを使うためのaccess tokenを取得するで書いたように自分でやってみた。

scopesはgistを指定すれば良いっぽい。

% curl -u 'username' -d '{"scopes":["gist"],"note":"gisty"}'  https://api.github.com/authorizations
Enter host password for user 'username':        # パスワードの入力
{
  "app": {
    "name": "gisty (API)",
    "url": "http://developer.github.com/v3/oauth/#oauth-authorizations-api"
  },
  "scopes": [
    "gist"
  ],
  "created_at": "2012-09-30T13:34:34Z",
  "note_url": null,
  "note": "gisty",
  "token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  "updated_at": "2012-09-30T13:34:34Z",
  "id": xxxxxx,
  "url": "https://api.github.com/authorizations/xxxxxx"
}

※ username, token, id, urlはブログ掲載にあたり書き換えている。

取得後、https://github.com/settings/applications を確認してみると、Authorized applicationsに"gisty (API) create gists"が追加されていた。

Github API アクセストークンの指定

取得したアクセストークンを以下のように追記

% vim ~/.zshenv

export GISTY_ACCESS_TOKEN="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

gistyを使ってgistへ投稿

適当なファイルを作って投稿してみた。

% vim helloworld.rb
% cat helloworld.rb
puts "Hello World!!"
% gisty post helloworld.rb
https://gist.github.com/3811198
Cloning into '3811198'...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.

投稿すると、投稿したファイルのURL( https://gist.github.com/3811198 )がブラウザで表示されたのと、 投稿したgistyの作業ディレクトリにgit cloneされた。

% tree -a work/gists
work/gists
└── 3811198
    ├── .git
    │   ├── HEAD
    │   ├── config
    │   ├── description
    │   ├── hooks
    │   │   ├── applypatch-msg.sample
    │   │   ├── commit-msg.sample
    │   │   ├── post-update.sample
    │   │   ├── pre-applypatch.sample
    │   │   ├── pre-commit.sample
    │   │   ├── pre-rebase.sample
    │   │   ├── prepare-commit-msg.sample
    │   │   └── update.sample
    │   ├── index
    │   ├── info
    │   │   └── exclude
    │   ├── logs
    │   │   ├── HEAD
    │   │   └── refs
    │   │       ├── heads
    │   │       │   └── master
    │   │       └── remotes
    │   │           └── origin
    │   │               └── HEAD
    │   ├── objects
    │   │   ├── info
    │   │   └── pack
    │   │       ├── pack-4597eadd62b3b8fa63a93cb59a15b8e669f4fc9d.idx
    │   │       └── pack-4597eadd62b3b8fa63a93cb59a15b8e669f4fc9d.pack
    │   ├── packed-refs
    │   └── refs
    │       ├── heads
    │       │   └── master
    │       ├── remotes
    │       │   └── origin
    │       │       └── HEAD
    │       └── tags
    └── helloworld.rb

17 directories, 22 files

ついでに

はてなブログのgist記法を試してみた。

[gist:3811198]

と書くと

のように表示される。