79
80

More than 5 years have passed since last update.

Dash Ver.2で独自のCheatSheet作成!かなり良い!

Last updated at Posted at 2014-03-16

Macから様々なリファレンスを閲覧出来る、Dashがメジャーアップデートされました。
何と言っても目玉機能は CheatSheet という、リファレンスではなく所謂カンペ的なコマンド集のようなものを閲覧出来る様になったこと。
しかも、このCheatSheetはRubyのDSLで簡単に独自のものを作成できます。今回はその方法を解説。


前提

  • OSX 10.9
  • Xcode Command Line Tools (必須)

CheatSheet作成手順

後述の手順を踏んでrubyファイルを書けば、こんなcheatsheetが作れます!今回はGit Commandsというコマンド集を作成。
(左の一覧でGit Commandsの上にあるGitはデフォルトで準備されている英語のcheatsheet)

スクリーンショット 2014-03-16 19.46.19.png

CheatSheet作成のために以下を実行

$ sudo gem install cheatset # dashが読み込むdocsetファイルの生成に必要
$ xcode-select --install # Xcode Xcode Command Line Toolsをインストールしていない場合は実行
$ vim git_commands.rb # チートシートのファイル名(任意)。ファイルの内容は後述
$ cheatset generate git_commands.rb # docsetファイルに変換
# cheatset command not foundのようなことを言われる場合は source .zshrcなりターミナルを閉じるなりしてからコマンド再実行
$ open git_commands.docset # 生成されたdocsetをdashに読み込む

CheatSheet内容

チートシートの内容は、rubyのDSLで記述します。日本語もOK。以下の内容でスクショと同じものが生成される。

git_commands.rb
cheatsheet do
  title 'Git Commands'
  docset_file_name 'git_commands'
  keyword 'git'
  source_url 'http://cheat.kapeli.com'

  category do
    id 'コミット'

    entry do
      name '部分的にコミット'
      notes <<-'CODE'
        ```bash
        $ git add -p hoge.txt
        ```
      CODE
    end
  end

  category do
    id '変更を退避'

    entry do
      name '変更を一時退避'
      notes <<-'CODE'
        ```bash
        $ git stash
        ```
      CODE
    end

    entry do
      name '変更に名前をつけて退避'
      notes <<-'CODE'
        ```bash
        $ git stash save 'hogehoge'
        ```
      CODE
    end

    entry do
      name 'stashを一覧表示'
      notes <<-'CODE'
        ```bash
        $ git stash list
        ```
      CODE
    end

    entry do
      name '最新のstashを復元'
      notes <<-'CODE'
        ```bash
        $ git stash pop
        ```
      CODE
    end

    entry do
      name '特定のstashを復元'
      notes <<-'CODE'
        ```bash
        $ git stash pop stash@{1}
        ```
      CODE
    end
  end
end

参考ページ

79
80
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
79
80