可以自動 deploy hexo 並 push source code

在 root 編寫檔案,此處檔名為 hexo

(shell 可不需副檔名)

hexo
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
#!/usr/bin/env bash
# Usage
if [ "$1" == "" ];
then
echo "Usage: `basename $0` [deploy|push] [comment]"
echo "[comment] should use double quotes"
exit 0
fi
if [ $1 == "deploy" ];
then
# Hexo modify themes and deploy all (themes + post)
echo "deploy start:"
hexo clean
hexo generate
hexo deploy
fi
# push hexo source
if [ $1 != "" ];
then
# use double qoutes to quote all sentence in $2
if [ "$2" != "" ];
then
echo "push start:"
git add .
git commit -m "$2"
git push
fi
fi

Usage

1
2
3
4
# deploy + push
$ ./hexo deploy "give some comment"
# only push
$ ./hexo push "give some comment"

"$2" 只要用雙引號刮起來就可以吃含有空格的句子

也可以自訂別名讓指令縮短

1
2
# 使用 ${HOME} 自動抓家目錄位置
$ alias hd="${HOME}/hexo deploy"

延伸閱讀:為指令自訂別名(alias)