-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-to-day-one.sh
More file actions
executable file
·53 lines (45 loc) · 1.1 KB
/
git-to-day-one.sh
File metadata and controls
executable file
·53 lines (45 loc) · 1.1 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
#!/usr/bin/env bash
dayone=`which dayone`
file=$1
newentry=.new-day-one-entry.txt;
gitdir=$(git rev-parse --git-dir)
# Make sure dayone is in our PATH
if [[ ! -x ${dayone} ]];
then
echo "Please put dayone into your PATH"
exit
fi
# Make sure we have a file name to add to a Day One entry
if [ $# -ne 1 ];
then
echo "Usage: $1 <file name>"
exit
fi
# Make sure we are currently inside of a git repo
if [ -z ${gitdir} ];
then
echo "Not inside of a git repo!"
exit
fi
# Figure out the base name of the folder containing the git repo
if [ "${gitdir}" == ".git" ];
then
repo=`basename $PWD`
else
repo=`basename ${gitdir}`
fi
# Figure out the branch name
branch=`git branch | grep \* | awk '{ print $2 }'`
# Make sure the file containing the Day One log exists and is readable
# Then add the entry
if [ -e "${file}" -a -r "${file}" ];
then
echo -e "New git commit to ${repo}(${branch})\n\n" > ${newentry}
cat ${file} | grep -v ^\# >> ${newentry}
${dayone} new < ${newentry} > /dev/null
echo "Added commit message to Day One!"
rm ${newentry}
else
echo "Could not read file '${file}'"
exit;
fi