-
Notifications
You must be signed in to change notification settings - Fork 3
/
mkpost.sh
executable file
·75 lines (64 loc) · 1.46 KB
/
mkpost.sh
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
## create a template post and open it in emacs
##
## t - title,
## c - category,
## p - picture, include a link to a picture
## and the timestamp, mmddHHMMYY
# make sure we are in the project root dir, same as script location.
cd $(dirname $0)
# default values
#
title='no title'
category=software
picture=abc.png
# overwrite from command line
#
OPTIONS=t:c:p:
LONGOPTIONS=title:,category:,picture:
PARSED=$(getopt --options=$OPTIONS --longoptions=$LONGOPTIONS --name "$0" -- "$@")
if [[ $? -ne 0 ]]; then
# e.g. $? == 1
# then getopt has complained about wrong arguments to stdout
exit 2
fi
# read getopt’s output this way to handle the quoting right:
eval set -- "$PARSED"
outfile=$(tempfile --suffix .mp3)
while true; do
case "$1" in
-t|--title)
title="$2"
shift 2
;;
-c|--category)
category="$2"
shift 2
;;
-p|--picture)
picture="$2"
shift 2
;;
--)
shift
break
;;
*)
echo "Programming error"
exit 3
;;
esac
done
# remaining arguments, should be one, is the timestamp
date=$(date $1 +%Y-%m-%d)
name=$date-$(echo $title 2>/dev/null | tr ' ' '-').md
timestamp=$(date $1 +"%Y-%m-%d %H:%M")
cat <<EOF >> _posts/$name
---
layout: post
title: "$title"
date: $timestamp
categories: $category
---
EOF
emacsclient -n _posts/$name