Create a Jekyll command from the _plugins folder

I want to create a command that extracts a few stats for me. So I’m trying to create a local command in the _plugins folder.

To start, I added this code in the _plugins/hello.rb file :

class Hello < Jekyll::Command
    class << self
      def init_with_program(prog)
        prog.command(:hello) do |c|
            c.action do |args, options|
              Jekyll.logger.info "Hello!"
            end
        end
      end
    end
end

and in config.yml

plugins:
  - ./_plugins/hello.rb

I can start a server without error, but when I try to launch bundle exec jekyll hello, I get this error :

fatal: 'jekyll hello' could not be found. You may need to install the jekyll-hello gem or a related gem to be able to use this subcommand. 

Is it possible to create a command without a gem ? For me right now, a gem would be overkill, but it feels like I don’t have a choice.

It’s certainly possible to add plugins w/o a gem. I haven’t done a command yet, but tags and blocks, and they all have a line like

Liquid::Template.register_tag('accordion2', Jekyll::Accordion2Tag)

at the end (here it has something to do with an accordion, so different names for you, of course). And I don’t mention them in config.yml.
Maybe that helps.

According to the docs:

This is possible by including the relevant plugins in a Gemfile group called :jekyll_plugins :

group :jekyll_plugins do
  gem "my_fancy_jekyll_plugin"
end

So you probably need to add it to the relevant part of your Gemfile. Maybe do something like what is done in this post when it specifies a local path to the plugin:

group :jekyll_plugins do
   gem 'jekyll-hello', '0.1.0', :path => '/Users/maxchadwick/Projects/jekyll-hello'
end