Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
TextMate snippet to quickly populate a fresh gemspec
#!/usr/bin/env ruby
def git_config(key)
value = `git config #{key}`.chomp
value.empty?? nil : value
name = File.basename(ENV['TM_FILENAME'] || 'name').split('.').first
user = git_config('github.user') || ENV['USER'] || ENV['USERNAME'] || 'user'
email = git_config('') || ''
full_name = git_config('') || 'Your Full Name'
puts <<-GEMSPEC do |gem| = '${1:#{name}}'
gem.version = '${2:0.0.1}' =
# gem.add_dependency 'hpricot', '~> 0.8.2'
# gem.add_development_dependency 'rspec', '~> 1.2.9'
gem.summary = "${3:summary}"
gem.description = "${4:Longer description.}"
gem.authors = ['${5:#{full_name}}'] = '${6:#{email}}'
gem.homepage = '{user}/$1'
gem.rubyforge_project = nil
gem.has_rdoc = true
gem.rdoc_options = ['--main', 'README.rdoc', '--charset=UTF-8']
gem.extra_rdoc_files = ['README.rdoc', 'LICENSE', 'CHANGELOG.rdoc']
gem.files = Dir['Rakefile', '{bin,lib,man,test,spec}/**/*', 'README*', 'LICENSE*'] & \\`git ls-files -z\\`.split("\\0")

How to install:

  1. Create a new command
  2. Paste the ruby code into it
  3. Output: "Insert as Snippet"
  4. Tab trigger: gemspec
  5. Scope: source.ruby

This comment has been minimized.

Copy link

@mrrooijen mrrooijen commented Apr 7, 2010

Hey Mislav, Thanks for the nice snippet!

It all seems to work, except for the part where I invoke the "git_config" method.

See Pastie Snippet:

First 3 lines error out for some reason, do you have any idea why?
When I manually execute "git config" etc from the command line it does work, but something goes wrong when doing it from TextMate.

This isn't a big issue or anything, I can manually insert the variables of course, but if you know why this happens, please let me know. :)



This comment has been minimized.

Copy link
Owner Author

@mislav mislav commented Apr 7, 2010

TextMate can't find your git. First check where it is:

$ which git

Then make sure it's in TextMate's PATH: "Settings → Advanced → Shell variables". If you don't have PATH there, create it by copying it from the shell:

$ echo $PATH | pbcopy

This comment has been minimized.

Copy link

@mrrooijen mrrooijen commented Apr 7, 2010

Thanks, that did the trick!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment