-
Notifications
You must be signed in to change notification settings - Fork 1
/
jekyll-serve.sh
executable file
·47 lines (43 loc) · 1.07 KB
/
jekyll-serve.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
#! /bin/bash
set -e
projectdir=$(cd $(dirname $0) && pwd)
jekyll_url="http://localhost:4000/"
jekyll_running() {
jekyll_pid=0
for pid in $(pgrep -f "/jekyll "); do
dir="/$(pwdx $pid | cut -f2- -d/)"
if test "$dir" = "$projectdir"; then
jekyll_pid=$pid
return 0
fi
done
return 1
}
case "$1" in
start)
if jekyll_running; then
echo "Jekyll already running for $projectdir [PID=$jekyll_pid]"
else
jekyll serve --watch >jekyll.log 2>&1 &
disown
for i in $(seq 50); do
echo -n "."
sleep .1
curl -sf "$jekyll_url" >/dev/null && echo -n " Jekyll up and running!" && break || :
done
echo
fi
xdg-open "$jekyll_url"
;;
stop)
if jekyll_running; then
kill $jekyll_pid
else
echo "No running Jekyll process found for $projectdir"
fi
;;
*)
echo "usage: $(basename $0) start|stop"
exit 1
;;
esac