Humanity

Edit the world by your favorite way

vim.orgにアップロードされていないプラグインがあるかチェックするgit-unreleased-vimplugins作った

アイスストーム!(訳:Vim Advent Calendar 2012への3回目の投稿です)

この記事はVim Advent Calendar 49日目の記事です。

48日目は@ujihisaさんのif_luaを標準搭載するでした。

目次

vim.orgにアップロードしなくなって久しい

この記事を読んでいる中にはvim.orgに自作プラグインを投稿しているVimmerの方もいるでしょう。
しかし最近はGitHubという便利なものが現れたおかげで、vim.orgにアップロードしなくても
開発者はそれなりに承認欲求が得られる、かつ気軽に公開できるようになってしまい、
一方ユーザはneobundleなどのプラグインを使えばvim.orgからダウンロードするよりずっと楽にプラグインをインストールできてしまいます。
気付けばvim.orgの新着プラグインフィード*1vim-jp.orgVim Magazineでまとめ読みして済ませてしまう始末。
なんということでしょう。
vim.orgはオワコン化してしまったのでしょうか。
Karmaに一喜一憂したあの頃は取り戻せないのでしょうか。*2
しかし、vim.orgに訪れなくなったユーザがいなくなった訳ではありません。
vim.orgを訪問してユーザのページをヲチ見て回る人は日本で自分1人だけかもしれませんが、新着フィードを購読している人は多くいるはずです。
そんな人たちのこと、時々でいいから思い出してあげてください。

スクリプト紹介とインストール

tyru/gittools · GitHub
gittools/git-unreleased-vimplugins at master · tyru/gittools · GitHub
このスクリプトはアップロードし忘れてしまったプラグインをリストアップしてくれるスクリプトです。
Perlで書かれています。
Makefile.PLとか書いてないので「cpanm http://github.com/tyru/gittools」とかできません。インストールは人力でお願いします。ローテク!!!

# 今だとこのモジュール入れれば動くよ(多分)
$ sudo cpan LWP::UserAgent HTTP::Request JSON URI File::Find::Rule Guard List::MoreUtils


自分の場合はこんな出力結果が得られました(途中の出力は省略しています)。

$ git unreleased-vimplugins ~/.vim/bundle/
vim plugins:
  autochmodx.vim
  capture.vim
  ...(略)...

...(略)...

capture.vim:
    Latest commit on vim.org: (not uploaded yet)
caw.vim:
    Latest commit on vim.org: (not uploaded yet)
detect-coding-style.vim:
    Latest commit on vim.org: (not uploaded yet)
dutil.vim:
    Latest commit on vim.org: (not uploaded yet)
emap.vim:
    Latest commit on vim.org: (not uploaded yet)
eskk.vim:
    Latest commit on vim.org: (not uploaded yet)
fileutils.vim:
    Latest commit on vim.org: (not uploaded yet)
ftl-vim-syntax:
    Latest commit on vim.org: (not uploaded yet)
gravit.vim:
    Latest commit on vim.org: (not uploaded yet)
hatena-vim:
    Latest commit on vim.org: (not uploaded yet)
lingr-vim:
    Latest commit on vim.org: (not uploaded yet)
multiprocessing.vim:
    Latest commit on vim.org: (not uploaded yet)
nextfile.vim:
    Latest commit on vim.org: 12a28c22eee35ff8a5dc7f6788842db4b252d21e (17 commits between the HEADs)
    Plugin name on vim.org: nextfile
ohmygrep.vim:
    Latest commit on vim.org: (not uploaded yet)
open-browser.vim:
    Latest commit on vim.org: 684907df0ca142d8c7e7bff68ac0de40bdb46789 (118 commits between the HEADs)
    Plugin name on vim.org: open-browser.vim
operator-camelize.vim:
    Latest commit on vim.org: b279c8d232631be6da0b8a3213afe048b0dbee1e (4 commits between the HEADs)
    Plugin name on vim.org: operator-camelize
quickey.vim:
    Latest commit on vim.org: (not uploaded yet)
restart.vim:
    Latest commit on vim.org: 00cc52295b524f02afbc58a4956f818b13552eb3 (2 commits between the HEADs)
    Plugin name on vim.org: restart.vim
sign-diff.vim:
    Latest commit on vim.org: b7b5432a65c35228897444a01b1daebcbb900e7d (8 commits between the HEADs)
    Plugin name on vim.org: sign-diff
simpletap.vim:
    Latest commit on vim.org: (not uploaded yet)
skk.vim:
    Latest commit on vim.org: 01350797cae24abaaf24fe913a1a475b75bc4d17 (112 commits between the HEADs)
    Plugin name on vim.org: skk.vim
skkdict.vim:
    Latest commit on vim.org: (not uploaded yet)
starter.vim:
    Latest commit on vim.org: (not uploaded yet)
tjs.vim:
    Latest commit on vim.org: (not uploaded yet)
undoclosewin.vim:
    Latest commit on vim.org: (not uploaded yet)
unretab.vim:
    Latest commit on vim.org: (not uploaded yet)
vertR.vim:
    Latest commit on vim.org: (not uploaded yet)
vice.vim:
    Latest commit on vim.org: (not uploaded yet)
vim-altercmd:
    Latest commit on vim.org: cad27c8d5a8272798f90c3bb19fce2fd59e4bd89 (26 commits between the HEADs)
    Plugin name on vim.org: altercmd
vim-perlbrew:
    Latest commit on vim.org: (not uploaded yet)
vimtemplate.vim:
    Latest commit on vim.org: cf8e8c2d07de69e564963e5e2f001d58ce7b9616 (30 commits between the HEADs)
    Plugin name on vim.org: vimtemplate
winmove.vim:
    Latest commit on vim.org: da503733e629be063df8dd62b2c79028c64c2620 (2 commits between the HEADs)
    Plugin name on vim.org: WinMove

(アップロードしてないプラグイン多すぎですね。反省します)

  • アップロードしていなかった場合は「(not uploaded yet)」と表示される
  • アップロードしていた場合
    • vim.orgにアップロードしたバージョンのコミット(SHA-1)
    • vim.orgと現在のブランチ間のコミット数
    • vim.org上でのリポジトリ


ちなみにこの場合引数の「~/.vim/bundle/」以下からプラグインのリストを取得してるので他人のプラグインも含まれています。
GitHubのアカウントからプラグインのリストを取得することもできます。詳しくは次項。

引数の説明

適当に「pod2text git-unreleased-vimplugins」の出力結果をぺたり。

  • 」は必須です。bundleのディレクトリ(例:~/.vim/bundle/)を指定します
    • Vimプラグイン開発者でbundleディレクトリない人は流石にいないはず...
  • --no-save辺りはまだ未実装なのでデフォルトで--no-saveのように振舞います
    • 実装されると「~/.gitconfig」にvim.orgのリポジトリのURLが保存され、GitHub APIに余計なリクエスト送る必要なくなり、結果高速化されてGitHubにとってもユーザにとってもハッピーになる予定です
NAME
        git-unreleased-vimplugins - show unreleased vimplugins

SYNOPSIS
        $ git unreleased-vimplugins OPTIONS <vim bundle dir>

OPTIONS
    -h, --help
        Show this help.

    -q, --quiet
        Decrement debug level.

        Default debug level is MSG (=1). QUIET = 0 MSG = 1 INFO = 2 DEBUG =
        3

    -v, --verbose
        Increment debug level.

        See "--quiet" about debug level.

    --github
        Get vimplugin names list from your Github account. But you must have
        repositories which has the same names under vim bundle dir, that is
        specified to the 1st argument. (Pseudo code below)

            $repos = github.get_repos()
                        .filter(seems vimplugin)
            where
                seems vimplugin =
                    URL host is (www.)vim.org
                        or
                    language is VimL
                        or
                    has bundle-ready directory hierarchy

        Default behavior is to see vim bundle dir. (See "--bundle")

        If you combine this option with "--bundle", latter option is only
        effective.

    --bundle
        Get vimplugin names list from your vim bundle dir that is specified
        to the 1st argument. (Pseudo code below)

            $repos = vimbundledir.get_repos()
                        .filter(on github)

        This is default behavior. (See "--github" to change)

        If you combine this option with "--github", latter option is only
        effective.

    --no-save
        Don't save vimplugin names list mapping between repositories of vim
        bundle dir ("--bundle") or Github account ("--github"), and
        repositories of "http://github.com/vim-scripts".

        By default, this mapping is automatically created in your global
        gitconfig, unless specified this option.

        After this mapping is created, this script doesn't need to *scan*
        repositories on "http://github.com/vim-scripts" correspond to
        vimplugin names list. so next time, you don't need to wait for a
        long time.

        ...But not implemented even auto-saving feature yet!

AUTHOR
    tyru <tyru.exe@gmail.com>
「~/.vim/bundle/*」のプラグインを調べたい場合

「--bundle」オプションを付けます。
デフォルトなので付けなくても構いません。

  1. 「~/.vim/bundle/*」のディレクトリをプラグインのリストとして取得
  2. 自身のGitHubアカウントにあるリポジトリのみ抽出

PODに書いたPseudo-codeを示すとこんな感じ。

$repos = vimbundledir.get_repos()
            .filter(on github)
GitHubプラグイン一覧を調べたい場合

「--github」オプションを付けます。
この場合もbundleディレクトリの指定は必須です。

  1. GitHubリポジトリプラグインのリストとして取得
  2. Vimプラグインぽいものをフィルタ (以下のいずれか)
    1. リポジトリのURLがvim.orgのものである
    2. 言語がVimL
    3. 「~/.vim/bundle/」につっこめばそのまま動きそうなディレクトリ構成

PODに書いたPseudo-codeを示すとこんな感じ。

$repos = github.get_repos()
            .filter(seems vimplugin)
where
    seems vimplugin =
        URI host is (www.)vim.org
            or
        language is VimL
            or
        has bundle-ready directory hierarchy

Q. vim.org上でのリポジトリとは → A. github.com/vim-scripts

先程git-unreleased-vimpluginsの出力結果に「vim.org上でのリポジトリ名」が出力されると書きましたが、vim.orgのリポジトリ?そんなものどこにあるの?と思われる方がいらっしゃったかもしれません。
実は、vim.org上のプラグインは全てGitHubにミラーされています。*3
Vim Scripts
vim-scripts · GitHub
このミラーはvundle、neobundle、vim-flavorなど様々なプラグインマネージャーで利用されています。
つまり、もしあなたがpathogenやunbundleなどを使っているなら、
vim.org上にアップロードしたプラグインを手動でインストールする必要はないのです。
(最近はneobundleやvundleで自動インストールが主流かもしれませんが)
そしてgit-unreleased-vimpluginsも言うまでも無くこのミラーを利用しています。

Q. どうやってvim.org上のコミットを探しているのか

  1. github/vim-scripts上のリポジトリを探す
  2. 見つけたリポジトリをgit fetch
  3. Vimに関連ありそうなファイルのblob objectsのSHA-1を(Perlの)ハッシュにつっこむ
  4. コミットを遡り全てのblob objectsのSHA-1が一致したコミットを探す
  5. 見つかったら情報を保存して最後に表示

:wqa!

Vimプラグイン開発者はたまに実行してvim.orgにアップロードしてないプラグインがあるかチェックしましょう!(自分含め)


次のAdvent Calendarは@kmnkさんです。

*1:http://feed43.com/vim-scripts.xml

*2:Unfulfilling付けたの誰だよ出てこいよ http://dic.nicovideo.jp/a/%E3%81%93%E3%81%8F%E3%81%98%E3%82%93

*3:ますます本家がないがしろにされてる感が...