Simplest solution under current structure:  Walk the dir path upwards until you find a Gemfile.

Better solution:  don't use a separate CLI tool.  Make a barebones Rakefile as part of the scaffolding.  It should hold no actual tasks directly but pick them up via a call to an Octopress API.  For example:

----Rakefile----
require 'rubygems'
require 'bundler/setup'
Bundler.setup
require 'octopress/rake'
Octopress::Rake.init!(self)
----end Rakefile----

The relevant method would look something like this:

----lib/octopress/rake.rb----
module Octopress
  module Rake
    def self.init!(ctx)
      ctx.instance_eval do
        Dir[path_to_dot_rake_files].each do |fname|
          load fname
        end
      end
    end
  end
end
---- end ----

This gives people easy discoverability ("rake -T"), easy integration points for plugins that want to extend CLI behavior, an easy way for users to incorporate their own CLI behavior, and a deterministic way of finding the project root with certainty.

-JF

Sent from my iPhone

On May 23, 2013, at 9:22 AM, Parker Moore <notifications@github.com> wrote:

> In lib/octopress.rb:
> 
> > @@ -12,7 +12,7 @@ def self.lib_root
> >    #
> >    # Returns the absolute path of the main octopress installation
> >    def self.root
> > -    File.dirname(lib_root)
> > +    Dir.pwd
> There is no way for us to know the root of your Octopress directory, as lib/ will be distributed as a gem, much like jekyll. Do you know of a better way to find this directory?
> 
> As you can see from the diff, this used to be an absolute directory relative to this file, but it's no longer possible to do so when this is distributed as a gem.
> 
> —
> Reply to this email directly or view it on GitHub.