-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev-diary.sh
More file actions
executable file
·56 lines (41 loc) · 1.44 KB
/
Copy pathdev-diary.sh
File metadata and controls
executable file
·56 lines (41 loc) · 1.44 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
53
54
55
56
#!/bin/bash
# Create diary entry using gum
TODAY=$(date "+%Y-%m-%d")
HEADER="# Development Diary"
# Check for existing entry. Confirming falls through to write a second one for
# the day, to be merged by hand; declining stops here.
if grep -q "## $TODAY" DEVDIARY.md; then
gum confirm "Entry for today already exists! Continue? (You will have to manually merge your entries afterwards)" || exit 1
fi
# Get user inputs
TITLE=$(gum input --placeholder "Enter today's diary entry title")
SUMMARY=$(gum input --placeholder "Enter entry summary (4-6 sentences)")
NOTES=$(gum input --placeholder "Enter additional notes")
# Get today's git commits in chronological order
COMMITS=$(git log --since="midnight" --until="23:59:59" --reverse --format="%h %s")
# Build commit list
COMMIT_ENTRIES=""
while read -r commit; do
sha=$(echo "$commit" | cut -d' ' -f1)
msg=$(echo "$commit" | cut -d' ' -f2-)
COMMIT_ENTRIES+="- \`$sha\` $msg"$'\n'
done <<< "$COMMITS"
# Create entry template
ENTRY="$HEADER
## $TODAY
### $TITLE
$SUMMARY
$COMMIT_ENTRIES
### Notes for $TODAY
$NOTES
"
# File handling
if [ ! -f DEVDIARY.md ]; then
echo "$HEADER" > DEVDIARY.md
fi
# Preview and confirmation
echo -e "$ENTRY" | gum format -t markdown
gum confirm "Does this look correct?" || exit 1
# Build new file with entry + existing content
{ echo -e "$ENTRY"; tail -n +3 DEVDIARY.md; } > tmp.md && mv tmp.md DEVDIARY.md
gum style --foreground 212 "Diary entry added for $TODAY!"