The Autodidacts

Exploring the universe from the inside out

How to (Rapidly) Switch Ghost Themes from the Command Line

Screenshot of FZF-powered Ghost-theme-selector

I do a lot of Ghost theme development, and have to swap which theme is running on my local install all the time. The Ghost admin interface takes a lot of clicking to get to the page where you can change themes. And I don’t like clicking.

Neither Google nor GPT could tell me how to change the Ghost theme from the command line, using the Ghost Admin API or Ghost CLI.

Fortunately, standard Unix tools can get the job done.

In preparation:

  1. Make sure you don’t have a theme installed called “current”.
  2. Create a symbolic link called “current” in your Ghost /path/to/ghost/content/themes directory, pointing at a working theme. (For example, from the themes directory: ln -s casper current.)
  3. Navigate to the theme settings page of Ghost admin (http://localhost:2368/ghost/#/settings/design/change-theme), click installed, and activate the theme that says “(current)” after the title, if it isn’t already active.
  4. Make sure the needed Unix utilities are installed: ln, find, basename, xargs and fzf. Likely, FZF is the only one you'll need to install (sudo apt install fzf). Note: while this symlink-updating approach should work on any OS, and many of the commands probably work pretty much the same way on MacOS (or maybe even Windows Subsystem for Linux 🤮), I have only tested them on Ubuntu Linux.

Now, we’re ready for fast theme switching. Change into the directory with your Ghost install (from here on, referred to as /path/to/ghost, which would be a terrible place for a Ghost install):

rm content/themes/current && ln -s $THEME content/themes/current

Here, $THEME is the directory (no path needed) of the theme you want to activate.

But this isn’t fancy enough yet. We want one command to do it all. Here it is:

ln -sfn "$(find content/themes -maxdepth 1 -type d -print | fzf | xargs basename)" content/themes/current

What this does is find directories that are direct children of the “themes” folder, pipe them to a fuzzy finder to let you pick, strip the path, and then update the existing symlink, passing the bare directory name as the target for ln.

Now, you can add something like this to your .bashrc, if you want it to be even more convenient:

alias gt='cd /path/to/ghost && ln -sfn "$(find content/themes -maxdepth 1 -type d -print | fzf | xargs basename)" content/themes/current'

Presto!