プログラミングではスニペットの文化が浸透しています。同じようにサーバ管理を行う際にもよく行う操作をシェルスクリプトとして登録しておくと便利です。それだけでは個人用ですが、もっと広くチームで共有したり、さらに全世界の人たちと共有できると便利そうです。 そんな便利コマンドのスニペットを管理できるのがcmdshelfです。

cmdshelfの使い方

cmdshelfのコマンドを追加法です。gitコマンドに似た使い勝手です。

$ cmdshelf blob add random https://gist.githubusercontent.com/toshi0383/32728879049e95db41ab801b1f055009/raw/e84fa02c4f9ac7e08b686cee248ab72198470c0b/-

そしてlistで登録してあるスクリプトを確認できます。

$ cmdshelf list
blob:
  random: https://gist.githubusercontent.com/toshi0383/32728879049e95db41ab801b1f055009/raw/e84fa02c4f9ac7e08b686cee248ab72198470c0b/-

さらに外部のコマンドを取り込むこともできます。

$ cmdshelf remote add toshi0383-scripts https://github.com/toshi0383/scripts
$ cmdshelf list
[toshi0383-scripts] Cloning...

blob:
  random: https://gist.githubusercontent.com/toshi0383/32728879049e95db41ab801b1f055009/raw/e84fa02c4f9ac7e08b686cee248ab72198470c0b/-

remote:
  toshi0383-scripts:
    decimal2hex.sh
    fix-framework-infoplist-if-needed.sh
    fix-framework-version.sh
    git-branch-by-author
    open-device-support-dir.sh
    pixelSize.sh
    printUUIDofMobileprovision.sh
    replaceGitOriginWith.sh
    sort-Xcode-project-file
    sort-xcpretty-by-time
    total-test-duration

後はrunを使ってコマンドを実行できます。

$ cmdshelf run remote toshi0383-scripts/decimal2hex.sh
Unknown Arguments: toshi0383-scripts/decimal2hex.sh

Arguments:

    COMMAND - command name alias

cmdshelfを使えばチーム内での便利コマンドをGitHub上で管理して、それをローカルに取り込んでコマンドの実行ができます。個人で作っているちょっとしたスクリプトも共有すれば、きっとチームで役立つコマンドになるはずです。

cmdshelfはSwift製のオープンソース・ソフトウェア(MIT License)です。

toshi0383/cmdshelf: Manage your scripts like a bookshelf.?