Skip to content

Instantly share code, notes, and snippets.

@dreww
Forked from bru/newpost.rb
Created December 16, 2011 22:31
Show Gist options
  • Save dreww/1488321 to your computer and use it in GitHub Desktop.
Save dreww/1488321 to your computer and use it in GitHub Desktop.
Creates a new Jekyll post, opens it in a new mvim tab, and adds to the git index
#!/usr/bin/env ruby
require Dir
unless ARGV[0]
puts 'Usage: newpost "the post title"'
exit(-1)
end
blog_root = "/Users/revelation/Projects/studyspace-status/blog"
date_prefix = Time.now.strftime("%Y-%m-%d")
postname = ARGV[0].strip.downcase.gsub(/ /, '-')
post = "#{blog_root}/_posts/#{date_prefix}-#{postname}.md"
header = <<-END
---
layout: post
title: "#{ARGV[0]}"
---
END
Dir.chdir(blog_root)
File.open(post, 'w') do |f|
f << header
end
system("mvim", "--remote-tab", post)
system("git", "add", post)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment