-
Notifications
You must be signed in to change notification settings - Fork 0
/
new-post.sh
executable file
·63 lines (50 loc) · 1.21 KB
/
new-post.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
#!/bin/bash
# Defaults
date=$(date '+%Y-%m-%d')
time=$(date '+%Y-%m-%d %H:%M:%S')
layout="post"
format="md"
editor="gedit"
# Parse the arguments:
for i in "$@"
do
case $i in
-t=*|--title=*)
title=$(echo $i | sed 's/[-a-zA-Z0-9]*=//')
;;
-a=*|--author=*)
author=$(echo $i | sed 's/[-a-zA-Z0-9]*=//')
;;
-l=*|--layout=*)
layout=$(echo $i | sed 's/[-a-zA-Z0-9]*=//')
;;
-d=*|--date=*)
date=$(echo $i | sed 's/[-a-zA-Z0-9]*=//')
;;
-c=*|--category=*|--categories=*)
category=$(echo $i | sed 's/[-a-zA-Z0-9]*=//')
;;
--tag=*|--tags=*)
tag=$(echo $i | sed 's/[-a-zA-Z0-9]*=//')
;;
-e=*|--editor=*)
editor=$(echo $i | sed 's/[-a-zA-Z0-9]*=//')
;;
*)
echo "Unknown option: $i"
;;
esac
done
# Create the file with the appropriate data
filename="_posts/$date-$(echo $title | sed 's/[ _+()!@#$%^&*.]/-/g' | sed 's/-+/-/g' | tr [:upper:] [:lower:]).$format"
echo '---' > "$filename"
echo "title: $title" >> "$filename"
echo "author: $author" >> "$filename"
echo "date: $time" >> "$filename"
echo "category: $category" >> "$filename"
echo "tag: $tag" >> "$filename"
echo "layout: $layout" >> "$filename"
echo '---' >> "$filename"
echo '' >> "$filename"
# Open the file in the specified editor
$editor "$filename"