-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnew-post.sh
More file actions
executable file
·88 lines (73 loc) · 1.66 KB
/
new-post.sh
File metadata and controls
executable file
·88 lines (73 loc) · 1.66 KB
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
#!/bin/sh
# Blog post creation script
# Author: Levis Agaba <@alevis>
today=`date +%Y-%m-%d`
ext=".md"
title=$1
new_post=""
template="new-post-template$ext"
postdir="./_posts/"
tries=1
create_title(){
title=${title// /-}
new_post=$title$ext
new_post="$today-$new_post"
}
is_unique_title(){
echo "--------------------------------------------------"
while [ -f "$postdir$new_post" ]
do
if [[ $tries -gt 3 ]]; then
echo "Too many tries, goodbye!"
exit
fi
echo ""
echo "Oops!"
echo "File already exits!"
read -p "Enter your post's title ($tries): " title
create_title $title
tries=$((tries+1))
done
}
create_post(){
create_title $title $new_post $ext
is_unique_title $new_post $title
echo "Creating your blog post."
cp $postdir$template $postdir$new_post
sleep 3
echo "Get ready to edit in ..."
echo "...3"
sleep 1
echo "...2"
sleep 1
echo "...1"
sleep 1
if ! command -v vi &> /dev/null
then
if ! command -v nano &> /dev/null
then
if !command -v notepad &> /dev/null
then
echo "What planet are you from?"
echo "Nevermind, it does not matter!"
echo "Goodbye!"
fi
else
notepad $postdir/$new_post
fi
nano $postdir/$new_post
else
vi $postdir/$new_post
fi
}
echo ""
if [[ -n $title ]]; then
echo "One moment..."
create_post
else
read -p "What is the title of your post? " title
create_post $title
fi
git add $postdir$new_post
git status
# fin