WordPress themes on the command line: _sh

Last week we had a very fun hack day at Automattic. A couple Automatticians (Hugo and Konstantin) made underscores.me, an awesome and easy way to create custom forks of the _s starter theme that the Automattic theme team released earlier this year. Ian Stewart wrote a post about it on ThemeShaper and today I noticed an interesting discussion in the comments about forking _s from the command line. It seemed like a cool idea, so I spent a little while hacking together a Python script to do it, which I just released on Github.

I’m calling it _sh.

I wrote a detailed README, so I’m going to copy most of that here and let it play out the remainder of this post.

_sh (the _s shell)

_sh is a command line tool to generate forks of the _s WordPress starter theme. It uses underscores.me to create the fork, but lets you do it entirely from the command line.

It lives at https://github.com/evansolomon/_sh.

Installation

_sh is written in Python, so you’ll need to have it installed and have a way to interact with it on the command line, like in Terminal.app.

The easiest way to use _sh is to put it in a place that your PATH can access it. First, clone this repository.

git clone https://github.com/evansolomon/_sh.git /path/to/save/_sh

From the directory that you cloned _sh, you can run the setup.py installer script to create a symlink.

python setup.py

That will give you a prompt where you can type the directory that you want to link _sh to. Here I’ll set it up to live in my ~/bin directory.

Welcome to _sh.

Where do you want to symlink _sh? ~/bin



Running...

ln -s /Users/evan/code/_sh/_sh /Users/evan/bin

Usage

Assuming you’ve setup _sh to be accessible in your PATH, to use it you can just call _sh on the command line from anywhere.

When you call _sh you’ll get an interactive prompt that will walk you through setting up your theme. The new theme will get created in a child directory of wherever the command is run from. Here’s an example:

cd ~/code/themes && _sh

Once I run the _sh command I’ll get an interactive prompt with a few questions to setup my new theme. It’s hard to tell from here, but the introduction and questions all come from _sh, and the answers come from me, typed into an interactive prompt in Terminal. Most of these questions are optional; the only one you must answer is the theme’s name.

I'm going to ask you for some information about your theme.

You have to give your theme a name but you can leave the others blank if you want.

Let's get started.

Name? Stella and Mojo
Slug? stellaandmojo
Author? Evan Solomon
Author URI? http://evansolomon.me
Description? It's a theme named after dogs, because why the hell not.

At this point, _sh will make a request to underscores.me, download a ZIP file with my new theme, and unzip it. Then I’ll have a directory in ~/code/themes/stellaandmojo with my theme files.

That’s it, now I’ve got a new fork on _s with all of my customizations setup.

I updated the post to reflect the new setup.py installer.

2 thoughts on “WordPress themes on the command line: _sh

Comments are closed.