Skip to content

Writing a CLI to Help me Blog More

I'm not a big fan of using a GUI/WebUI for creating or editing markdown files...or really any plain-text file for that matter. I live in the Terminal most days and I want to limit the amount of time I have to spend context switching. So, in an effort to increase my blog output AND to scratch an itch, I'm developing a simple program that I hope will help me blog just a bit more.

Squidblog

What I want out of this little exercise is a tool that can:

  • Create new blog posts for Material for MkDocs
  • Edit existing posts

I was going to have a couple more bullet points there for the feature list, but as I was thinking about what else I would want, I decided to just start with the two features and expand from there while I dogfooded the tool.

To do this, I will be using Typer. Mostly because it was something I found while researching how to create CLI tools with Python and I've found it very pleasant and even fun to work with.

Oh, and I chose the name based on the creator of Material for MkDocs and the word blog. squidfunk - funk + blog.

Create

The create feature should create a new post ensuring that:

  • The post has a Title, a slug, and other various metadata
  • The filename for the post should match the slug
  • The new file should contain the frontmatter pre-populated with the needed variables
  • Respect your EDITOR variable...even if it isn't vim

squidblog_cli_create

Comments, Categories, and Draft

During some downtime I was able to add a couple quick quality-of-life improvements to the squidblog posts create command. You can now specify if you want to enable or disable comments, specify the categories via a comma separated list of values, and if you want enable or disable the post's draft status.

squidblog_cli_comments_categories_drafts

Edit

The edit feature should open an existing post and be smart enough to know what posts you have already.

  • Open an existing post respecting your EDITOR
  • Offer tab-completion (thanks Typer!) for the existing post files to make editing easier

squidblog_cli_edit

Future

Maybe if I'm feeling frisky, I'll add some hooks to automatically run mkdocs serve and open the browser so I can view the rendered post each time I write to / save the post file.

Or maybe find a CLI markdown viewer and somehow shove that into another frame or maybe just another terminal.

I could also see myself adding in some hooks to do a bit of the ole git add and git commit for me after a post leaves the draft state.

Until that day I'll probably just clean up the code a bit and make the repo public so others can look upon my code and either be in wondrous awe at my skillz...or much more likely vomit a little in their mouths 🤮

Comments