~skiqqy/bin

8a4ceb2c316ffe37e87466b3bd12445ed183bf8f — Stephen Cochrane 2 months ago 67ba772
Added compile option
1 files changed, 36 insertions(+), 2 deletions(-)

M diary
M diary => diary +36 -2
@@ 9,6 9,9 @@ declare -A commands
commands[help]='help COMMAND\nShows helpful information for a specific command.'
commands[list]='list\nShows available commands.'
commands[open]='open\nOpen current diary entry for editing.'
commands[compile]='compile [PASSWORD]\nCompile diary entries to a single pdf, with an option password.'

### Helper Funcs

usage()
{


@@ 29,6 32,16 @@ EOF
	exit "${1:-0}"
}

conv_dates()
{
	while read -r line
	do
		date -d "$line" "+[%e/%m/%Y](## %e %B %Y, %A)"
	done
}

### End Helper Funcs

dlist()
{
	local msg


@@ 62,7 75,7 @@ dopen()
	local count
	local date

	date=$(date "+%C%m%Y")
	date=$(date "+%d%m%Y")
	count="$(dir -A1 "$workdir/entries/"*.md | wc -l | cut -d " " -f 1)"
	entry="$(find "$workdir/entries" -regex ".*/[0-9]+_$date.md")"



@@ 70,7 83,7 @@ dopen()
	then
		entry="$workdir/entries/$count""_$date.md"
		cat << EOF > "$entry"
## $(date "+%C %B %Y, %A")
## $(date "+%e %B %Y, %A")

Dear Diary...
EOF


@@ 79,6 92,27 @@ EOF
	$ed "$entry"
}

# TODO: Add password.
dcompile()
{
	cat << EOF > "$workdir/diary.md"
$(whoami)'s Diary

## TOC

$(dir -v1 "$workdir/entries/"*.md |
	sed -E "s|$workdir/entries/[0-9]+_(.*)\.md|\1|g" |
	sed -E "s|([0-9]{2})([0-9]{2})([0-9]{4})|\2/\1/\3|g" | conv_dates)

EOF
	for file in $(dir -v1 "$workdir/entries/"*.md)
	do
		cat "$file" >> "$workdir/diary.md"
	done

	command -v pandoc && pandoc "$workdir/diary.md" -o "$workdir/diary.pdf"
}

main()
{
	workdir="$HOME/.diary"