2023-11-18 06:14:41 +00:00
|
|
|
#!/usr/bin/env nix-shell
|
|
|
|
#! nix-shell -i zsh
|
|
|
|
#! -p zsh coreutils gpg
|
2023-08-28 18:25:12 +00:00
|
|
|
|
2023-08-28 18:27:24 +00:00
|
|
|
# ====
|
|
|
|
# journal.sh
|
|
|
|
# Manages a simple journaling system.
|
|
|
|
#
|
2023-11-18 06:14:41 +00:00
|
|
|
# Uses nix to manage all deps
|
2023-08-28 18:27:24 +00:00
|
|
|
# ====
|
|
|
|
|
2023-08-28 18:25:12 +00:00
|
|
|
set_dates() {
|
2023-11-18 06:14:41 +00:00
|
|
|
nowtime=$(date "+%H:%M") || exit
|
|
|
|
day=$(date "+%A" -d "$*") || exit
|
|
|
|
daynum=$(date "+%e" -d "$*") || exit
|
|
|
|
month=$(date "+%m" -d "$*") || exit
|
|
|
|
year=$(date "+%Y" -d "$*") || exit
|
|
|
|
date=$(date "+%Y-%m-%d" -d "$*") || exit
|
2023-08-28 18:25:12 +00:00
|
|
|
|
2023-11-18 06:14:41 +00:00
|
|
|
date_path=$(date "+%Y/%m" -d "$*") || exit
|
2023-08-28 18:25:12 +00:00
|
|
|
journal_prefix=~/code/txt/cal
|
|
|
|
file="$journal_prefix/$date_path/$date.txt"
|
|
|
|
}
|
|
|
|
|
|
|
|
change_status="Edited"
|
|
|
|
|
|
|
|
for arg in $@
|
|
|
|
case "$arg" in
|
|
|
|
show)
|
|
|
|
shift
|
|
|
|
set_dates $*
|
|
|
|
if [ ! -f "$file" ]; then
|
|
|
|
printf "journal entry for $date not found.\n"
|
|
|
|
exit 1;
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $(wc -l < $file) -le $["$LINES" - 20] ]]; then
|
|
|
|
cat "$file"
|
|
|
|
else
|
|
|
|
$PAGER "$file"
|
|
|
|
fi
|
|
|
|
|
|
|
|
exit 0
|
|
|
|
esac
|
|
|
|
|
|
|
|
set_dates $*
|
|
|
|
cd "$journal_prefix"
|
|
|
|
|
|
|
|
#setup header
|
|
|
|
if [ ! -f "$file" ]; then
|
|
|
|
mkdir -p $(dirname "$file") 2> /dev/null
|
|
|
|
|
|
|
|
printf "%0.s=" {1..13} >> $file
|
|
|
|
printf "\n" >> $file
|
2023-11-18 06:14:41 +00:00
|
|
|
cal -h "$month" "$year" | sed "0,/$daynum/{s//XX/}" >> $file
|
2023-08-28 18:25:12 +00:00
|
|
|
truncate -s -1 $file
|
|
|
|
|
|
|
|
printf "\n$day\n" >> $file
|
|
|
|
printf "%0.s=" {1..13} >> $file
|
|
|
|
printf "\n" >> $file
|
|
|
|
|
|
|
|
change_status="Created"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! grep -xq "$nowtime" "$file"; then
|
|
|
|
printf "\n* At $nowtime\n" >> $file
|
|
|
|
fi
|
|
|
|
|
|
|
|
$EDITOR $file
|
|
|
|
|
|
|
|
stty sane
|
|
|
|
printf "Save in git? [Y|n]: "
|
|
|
|
read yn
|
|
|
|
case $yn in
|
|
|
|
Y|y| )
|
|
|
|
git add "$file"
|
|
|
|
git commit -S -m "$change_status entry for $date at $nowtime" -m "$(randomart.py --ascii "$file")"
|
|
|
|
esac
|