-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblog.sh
executable file
·105 lines (97 loc) · 1.51 KB
/
blog.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/bash
DIR=~/Documents/projects/blog
P_DIR="$DIR/posts"
create() {
local cat="$1"
local title="$2"
local slug=$(echo "$title" | tr '[:upper:]' '[:lower:]' | tr ' ' '-')
local fn="$P_DIR/$cat/$slug.md"
if [ -f "$fn" ]; then
echo "File '$fn' already exists!"
return
else
echo $fn
echo "---" > $fn
echo "title: ''" >> $fn
echo "date: '$(date '+%Y-%m-%d')'" >> $fn
echo "---" >> $fn
echo "" >> $fn
read -p "1. vscode; 2. typora: " choice
case $choice in
1)
code "$fn"
;;
2)
typora "$fn"
;;
*)
echo "Invalid."
exit 1
;;
esac
fi
}
edit() {
read -p "1. vscode; 2. typora: " choice
case $choice in
1)
code "$1"
;;
2)
typora "$1"
;;
*)
echo "Invalid."
exit 1
;;
esac
}
run() {
local pwd=$(pwd);
cd $DIR
npm run dev
cd $pwd
}
build() {
local pwd=$(pwd);
cd $DIR
npm run build
cd $pwd
}
push() {
local pwd=$(pwd)
cd $DIR
git add .
git commit -m "$1"
git push
cd $pwd
}
case "$1" in
new)
create "$2" "$3"
;;
edit)
edit "$2"
;;
run)
run
;;
build)
build
;;
push)
push "$2"
;;
help)
echo "Commands:"
echo " new [category] [title] Create a new post. Then choose your preferred editor."
echo " edit <ctrl>t Edit an existing file. Use with FZF. Then choose your preferred editor."
echo " run Run *npm run dev*."
echo " build Run *npm run build*."
echo " push [message] Create a git commit and push."
echo " help This page."
;;
*)
echo "Run *_blog help* for help."
;;
esac