[小ネタ] gitignore.io で .gitignore ファイルをコマンド一行で生成する

2013.12.24

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

使用言語に応じた .gitignore ファイルを簡単生成

.gitignore ファイルとは git リポジトリで index に入れたくないファイル(またはフォルダ)を定義するファイルのことですが、この .gitignore を毎回書くのって面倒ですよね。もちろん自動生成してくれるフレームワークや IDE もありますし、GitHub のようにリポジトリ作成時にデフォルトで作ってくれるサービスもあります。

とはいっても自分で作るときもあると思います。そんなとき役立つツールが「gitignore.io」です。このツールを使うとコマンド一行で .gitignore ファイルを生成することができます。といっても URL を叩くだけなんですけどね。

まずはインストールしましょう。Mac OS X の場合は以下のコマンドでインストールできます。

echo "function gi() { curl http://gitignore.io/api/\$@ ;}" >> ~/.bash_profile && source ~/.bash_profile

zsh の場合はこちらになります。

echo "function gi() { curl http://gitignore.io/api/\$@ ;}" >> ~/.zshrc && source ~/.zshrc

あとは以下のように言語を指定して .gitignore ファイルを生成します。

gi ruby >> .gitignore

こうしてできた .gitignore ファイルはこんな感じです。

# Created by http://gitignore.io

### Ruby ###
*.gem
*.rbc
.bundle
.config
coverage
InstalledFiles
lib/bundler/man
pkg
rdoc
spec/reports
test/tmp
test/version_tmp
tmp

# YARD artifacts
.yardoc
_yardoc
doc/

ちなみに使える言語は list コマンドで確認できます。

gi list
go,wordpress,compass,ocaml,concrete5,jython,turbogears2,django,rhodesrhomobile,jekyll,zendframework,nanoc,cfwheels,magento,symfony2,grails,leiningen,unity,seamgen,c,sdcc,gwt,latex,rails,cmake,erlang,android,cakephp,tasm,objective-c,playframework,forcedotcom,lemonstand,ruby,target3001,dart,sketchup,node,jboss,textpattern,bancha,c++,qooxdoo,maven,typo3,haskell,scala,codeigniter,expressionengine,gcov,appceleratortitanium,clojure,autotools,opa,python,coq,kohana,joomla,visualstudio,oracleforms,eagle,actionscript,sugarcrm,r,fuelphp,lilypond,plone,symfony,java,symphonycms,drupal,yii,perl,qt,opencart,finale,lithium,waf,delphi,sbt,redcar,archives,sass,mercurial,sublimetext,matlab,osx,quartus2,xcode,phpstorm,linux,flexbuilder,espresso,eclipse,vim,cvs,bower,emacs,tags,netbeans,svn,pycharm,textmate,virtualenv,xilinxise,intellij,modelsim,monodevelop,windows,rubymine,dreamweaver,ph7cms,codekit,basercms,silverstripe,justcode,laravel,lazarus,senchatouch,wakanda,xamarinstudio,elixir,openfoam,joe,freepascal,gradle,dotsettings,komodoedit,cloud9,prestashop,elasticbeanstalk,vvvv,ensime,tarmainstallmate,meteor

こんな感じで簡単に .gitignore ファイルを生成することができます。いざというときに便利なので、ぜひインストールしておきましょう!