newpost.sh 412 Bytes
Newer Older
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
#!/bin/sh
if [ $# -lt 1 ]
then
	echo "usage: $0 title" >&2
	exit 1
fi

FNAME=posts/$(echo "$@" | sed 's/[[:space:]]+/_/g' | tr '[:upper:]' '[:lower:]').md

if [ -f "$FNAME" ]
then
	echo "post (\"$FNAME\") already exists" >&2
	exit 1
fi

cat > "$FNAME" <<EOF
title: $@
date: $(date +"%Y-%m-%d %H:%M")
author: $(getent passwd "$USER" | cut -d: -f5 | cut -d, -f1)
tags: news
---

EOF

exec "${EDITOR:-vi}" "$FNAME"