Skip to content

Instantly share code, notes, and snippets.

@imathis
Created March 27, 2012 18:56
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save imathis/2219214 to your computer and use it in GitHub Desktop.
Save imathis/2219214 to your computer and use it in GitHub Desktop.
Edit Octopress post
desc "Edit a post (defaults to most recent)"
task :edit_post, :title do |t, args|
args.with_defaults(:title => false)
posts = Dir.glob("#{source_dir}/#{posts_dir}/*.*")
post = (args.title) ? post = posts.keep_if {|post| post =~ /#{args.title}/}.last : posts.last
if post
puts "Opening #{post} with #{editor}..."
system "#{ENV['EDITOR']} #{post} &"
else
puts "No posts were found with \"#{args.title}\" in the title."
end
end
@citizen428
Copy link

Pesonally I added a task to my Rakefile:

desc "Open newly generated post in Emacs"
task :edit, :filename do |t, args|
  puts "Opening post in Emacs"
    `emacsclient -n #{args.filename}`
end

You could replace emacsclient -n with an editor variable at the top of the Rakefile (like ssh_user or deploy_branch). Also adding the globbing as a default if there is no args.filename would be easy, but personally I modified new_post and added Rake::Task["edit"].invoke(filename).

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