LoginSignup
292
296

More than 5 years have passed since last update.

.gitignore ファイルを生成するサービス gitignore.io

Last updated at Posted at 2013-05-22

.gitignore ファイルを手動で書くのは面倒だし、漏れもありそうです。 GitHub の人気プロジェクトの1つである github/gitignore にはさまざまなプロジェクト・環境に合わせた.gitignore ファイルのテンプレートが置いてあり、ここを参考にファイルを作る人も多いでしょう。

gitignore.io はこのプロジェクトのテンプレートを Web から見やすくした感じのサービスです。開発環境に使うものを指定すると自動で .gitignore ファイルのテンプレートを生成してくれます。

これをブラウザから使うのもいいのですが、 API が用意されているのでそこから使うこともできます。つまりターミナルから以下のようにコマンドを叩くと OSX と Linux で開発する Ruby のプロジェクトにあわせた .gitignore テンプレートを生成してくれます。

$ curl http://www.gitignore.io/api/osx,linux,ruby
# Generated by http://www.gitignore.io

### OSX ###
.DS_Store
.AppleDouble
.LSOverride
Icon


# Thumbnails
._*

# Files that might appear on external disk
.Spotlight-V100
.Trashes

### Linux ###
.*
!.gitignore
*~

### 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/

さらに環境指定を省略して API を叩くと

$ curl http://www.gitignore.io/api/
gitignore.io help:
  list    - lists the operating systems, programming languages and IDE input types
  :types: - generates .gitignore files for types of operating systems, programming languages or IDEs

このように簡単なヘルプまで表示してくれます。となればこの API を叩くコマンドを定義して CUI から使おうという発想に至りますね。

http://www.gitignore.io/cli に例があるのですが、こういうコマンドはたまにしか使わないので忘れやすい。そこでいっそのこと git のサブコマンドとして使えるようにするのが良いと思います。 ~/.gitconfig ファイルの[alias]セクションに次のように書いておきます。

[alias]
    ignore = !"f() { local s=$1; shift; \
      while [ $# -gt 0 ]; do s=\"$s,$1\"; shift; done;\
      curl \"https://www.gitignore.io/api/$s\"; }; f"

すると、次のようにして 簡単に .gitignore ファイルを生成できるようになりました。

$ git ignore osx linux ruby > .gitignore

$ cat .gitignore
# Generated by http://www.gitignore.io

### OSX ###
.DS_Store
.AppleDouble
.LSOverride
Icon


# Thumbnails
._*

# Files that might appear on external disk
.Spotlight-V100
.Trashes

### Linux ###
.*
!.gitignore
*~

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

# YARD artifacts
.yardoc
_yardocp
doc/

その他、git ignoregit ignore helpでヘルプを表示、git ignore listで指定できる環境のリストを表示できます。

$ git ignore
gitignore.io help:
  list    - lists the operating systems, programming languages and IDE input types
  :types: - generates .gitignore files for types of operating systems, programming languages or IDEs

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