-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotes-day.sh
More file actions
executable file
·55 lines (44 loc) · 839 Bytes
/
notes-day.sh
File metadata and controls
executable file
·55 lines (44 loc) · 839 Bytes
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
#!/bin/bash
show_help()
{
echo "Usage: $(basename $0) NOTE_DIR NOTE_FILES"
echo
echo "Options:"
echo " NOTE_DIR - directory with notes repository"
echo " NOTE_FILES - files to edit and commit"
}
die() {
echo "error: $1" 1>&2
exit 1
}
run_edit()
{
NOTE_DIR=$1
shift
NOTE_FILES=$@
cd $NOTE_DIR || die "$NOTE_DIR can't be used as a NOTE_DIR"
NOW=$(date '+%Y-%m-%d')
LAST=$(git log --pretty=oneline | head -1 | cut -d' ' -f 2)
$DEBUG && echo "# now: $NOW, last: $LAST"
$DEBUG nvim -O $NOTE_FILES
$DEBUG git add $NOTE_FILES
if [[ $NOW = $LAST ]]; then
# we haven't finished yet
$DEBUG git commit --amend -m $NOW
else
$DEBUG git commit -m $NOW
fi
}
#
# main
#
# debug mode
if [[ $1 = "-d" ]]; then
DEBUG=echo
shift
fi
if [[ $# -lt 2 ]]; then
show_help
exit
fi
run_edit $@