Computer Science Fundamentals/ Core SkillsLESSON 31 OF 34Log inSubscribe
Hands On: Creating a Useful Shell Script lesson slide
LESSON 31 OF 34 · IN THE FULL COURSE

This one's part of the full course

Good to see you. This one's in the full course

8 lessons are free to watch right now, no account needed. If they click, grab the course and every lesson is yours to keep.

You've seen how I teach. The other 26 lessons are in the full course, and your progress comes with you.

Already bought it? Log in and it picks up right here.

Your progress comes with you the moment you buy.

Core Skills · LESSON 31

Hands On: Creating a Useful Shell Script

Discuss
THE COURSE, END TO ENDNow playingDoneAheadYou are hereFree to watchIn the full course
Foundations
Logic and Binary
Information Theory
Crypto
CS Theory
Data Structures and Algorithms
Software Design
Core Skills
ABOUT THIS LESSON

I use the static site generator Jekyll to write my blog. I store the site at Github, who then translates and hosts it all for me for free. Jekyll is simple to use and I like it a lot. There’s only one problem: it’s a bit manual.

Every post that you create has to have a very specific filename in the form of year-month-day-post-slug.md. Not that big of a problem, just a mere annoyance. In addition, every post you have must have a blob of text at the top called the front matter. Again: not a huge problem, just kind of time consuming. The perfect candidate for a little help from a shell script.

#!/bin/bash
# a Jekyll post creator, which creates a new file, adds frontmatter,
# and opens the editor and starts Jekyll
new_post() {
  JEKYLL_ROOT=~/Documents/Sites/conery-io-jekyll
  JEKYLL_POSTS=$JEKYLL_ROOT/_posts
  TITLE=$1
  SLUGIFIED="$(echo -n "$TITLE" | sed -e 's/[^[:alnum:]]/-/g' | tr -s '-' | tr A-Z a-z)"
  NEW_POST_FILE=$JEKYLL_POSTS/$(date +%Y-%m-%d-$SLUGIFIED.md)

  cat <<frontmatter > $NEW_POST_FILE
---
-minimal
title: "$TITLE"
image: ''
comments: false
categories:
summary: ""
---
frontmatter

  echo "New post created, opening in Atom, starting Jekyll"
  atom $NEW_POST_FILE
  jekyll serve -s $JEKYLL_ROOT
}
34lessons across 8 sections
8free to watch right now
Foreverbuy it once, it's yours for life

34 lessons · 9.6 hours · all done

You finished Computer Science Fundamentals.

Every lesson, start to finish. That takes some doing, and you did it. Now go build something with it.

Cheers! Rob