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
@imathis
Copy link
Author

imathis commented Mar 29, 2012

@joliss I think there's definitely a difference between challenge and complexity. The challenge may be due to my lack of knowledge in this area (why I asked for help). I'm not trying to replicate Wordpress. Jekyll's job is generating the blog. Octopress is trying to be both a nice default theme and an environment that makes it easier to work with Jekyll. Many of the rake tasks may be considered overly complex and not treating people like a developer. For example, setting up someone's blog for GitHub deployment based on their repo url is not simple or straightforward. It used to be a way harder multistep process. It was well documented but people kept messing up, so I automated it.

If I can't make this feature work like I want it, I won't include it in Octopress. I'm not interested in supporting something that annoys users. That being said, once you create a new post, I wish it was smoother to get into writing that post, especially since you can't just use shell command history to find the file created and pass it to your editor.

You may be right, this might be something that I can't get right and it doesn't belong in Octopress. I'm not sure yet.

@jasonwryan
Copy link

once you create a new post, I wish it was smoother to get into writing that post, especially since you can't just use shell command history to find the file created and pass it to your editor.

I have this hacked up in my .bashrc (dirty, but it works...)
pedit() { find source/_posts/ -name "*$1*" -exec $EDITOR {} \; ;}

@Crosse
Copy link

Crosse commented Mar 29, 2012

@imathis Weird...I just have to hit Enter a time or two to get back to a clean prompt.

I believe that this would be a worthwhile addition. It doesn't take away the user's ability to run things manually if they still want to, but it could be welcome functionality for other users. Note that I am in the group of users for which this probably wouldn't work: within the _posts directory I have a directory called "published" for all my published things, and a "drafts" folder for all my drafts. I made a small hack to 'rake isolate' to handle directories. But since I keep all my work-in-progress in a separate folder--and since I don't have a ton of drafts--I don't have to wade through a bunch of extraneous posts to find what I want to work on. But I still think this would be a good idea, if it can be implemented correctly.

@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