-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathyear.sh
executable file
·59 lines (33 loc) · 880 Bytes
/
year.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
47
48
49
50
51
52
53
54
55
56
57
58
59
set -e
# ensuring we're in the right directory
DIR=`dirname $0`
pushd ${DIR} > /dev/null
DATE_FORMAT=" -f %F"
PROVIDED_DATE=$1
# date doesn't like the f option provided if no date is provided as well
if [ -z "${PROVIDED_DATE}" ] ; then
DATE_FORMAT=""
fi
YEAR="`date -j ${DATE_FORMAT} ${PROVIDED_DATE} "+%Y"`"
# making this year's directory if it doesn't exist
if [ ! -d "${YEAR}" ] ; then
mkdir -p ${YEAR}
fi
FILE="${YEAR}/${YEAR}review.txt"
# if the review file doesn't exist yet, we'll create it
if [ ! -f "${FILE}" ] ; then
# first add month to the top
cat <<EOF > ${FILE}
${YEAR} Review
EOF
# then add template
cat info/templates/month.txt >> ${FILE}
fi
# open file if EDITOR is set
if [ ! -z "${EDITOR}" ] ; then
$EDITOR ${FILE}
else
echo "Set EDITOR environment variable to open file..."
fi
# returning you to wherever you were...
popd > /dev/null