Last active
August 29, 2015 14:05
-
-
Save cdzombak/d6bac33a447bd84cf37d to your computer and use it in GitHub Desktop.
Script to create new posts in my customized Jenkins setup.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Warning: this script assumes it's contained in the scripts/ folder within a project. | |
set -o nounset | |
set -o errexit | |
if [[ $# -eq 0 ]] ; then | |
echo 'usage: new-post "Post Title"' | |
exit 1 | |
fi | |
SCRIPT_DIR=$(dirname "$0") | |
TITLE="$1" | |
DATE_FORMATTED="$(date +%F)" | |
DATETIME_FORMATTED_UTC="$(TZ=GMT date "+%Y-%m-%d %H:%M:%S")" | |
TITLE_ESCAPED="${TITLE//[^a-zA-Z0-9]/-}" | |
FILENAME="$DATE_FORMATTED-$TITLE_ESCAPED.md" | |
POSTFILE="$SCRIPT_DIR/../source/_posts/$FILENAME" | |
if [[ -f "$POSTFILE" ]] ; then | |
echo "!!! file exists: $POSTFILE" | |
exit 2 | |
else | |
echo "creating: $POSTFILE" | |
fi | |
cat << EOF > "$POSTFILE" | |
--- | |
layout: post | |
title: "$TITLE" | |
date: $DATETIME_FORMATTED_UTC | |
description: "TKTK" | |
--- | |
--- | |
_As always, I welcome discussion and feedback; I’m [@cdzombak on Twitter](https://twitter.com/cdzombak)._ | |
EOF | |
git add "$POSTFILE" | |
open -a "Byword" -g "$POSTFILE" | |
open -a "Marked 2" -g "$POSTFILE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment