/
pre-push
executable file
·39 lines (34 loc) · 1.02 KB
/
pre-push
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
#!/bin/sh
# see https://gist.github.com/matsub/8acba364012560b5a175a0a55e871972
tw_ID="matsubrk"
cname="www.matsub.net"
permalink="posts"
auto_tweet=0
nnnn="\([0-9]\{4\}\)"
nn="\([0-9]\{2\}\)"
echo "start pre-push..."
function get_added() {
git diff remotes/origin/master --name-only --diff-filter=A \
| grep -e "^_posts/[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}-.\+\.md"
}
function extract_pname() {
echo $1 \
| sed -ne "s/^_posts\/${nnnn}-${nn}-${nn}-\(.*\).md/\1\/\2\/\3\/\4/p"
}
# get added post
for post in `get_added`;do
if [[ $auto_tweet -ne 0 ]];then
ans="y"
else
echo "You have added new post: ${post}"
echo "tweet this? [y/N]"
read ans
fi
if [[ $ans =~ ^[Yy]* ]];then
title=`grep -e "^title: " ${post} | cut -d' ' -f2-`
post_page=`extract_pname ${post}`
url="https://${cname}/${permalink}/${post_page}"
tweet="新しい記事を投稿しました。 \"${title}\" ${url}"
sleep 30 && tw ${tweet} --user=${tw_ID} --yes &
fi
done