summaryrefslogtreecommitdiff
path: root/bin/.bin/new-episode
blob: c8a23050b7047d881bf5c3a90bea0eb7aaf30f62 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env bash

if [ -z "$1" ]; then
    echo "Usage: new-episode <number> <name>"
    exit 1
fi

EP_NUM=$(printf "%03d" "$1")

# Capture the Name (Shift the first arg so we can join the rest).
shift
RAW_NAME="${*:-untitled}"

# Create the Title (Capitalize first letter of every word).
# Using a simple sed regex to capitalize words.
EP_TITLE=$(echo "$RAW_NAME" | sed 's/\b./\U&/g')

# Create the Filename Slug (Lower case and replace spaces with hyphens)
# tr '[:upper:]' '[:lower:]' handles the casing
# tr ' ' '-' handles the spaces
SLUG=$(echo "$RAW_NAME" | tr '[:upper:]' '[:lower:]' | tr ' ' '-')
FILENAME="episode-${EP_NUM}-${SLUG}.php"

# Generate the file
cat <<EOF > "$FILENAME"
<?php

declare(strict_types=1);

/**
 * Episode ${EP_NUM}: ${EP_TITLE}
 * The Coding Brummie Fundamental PHP Series
 */

EOF