105 lines
2.9 KiB
Fish
105 lines
2.9 KiB
Fish
function jrnl --description 'Lightweight journaling tool'
|
|
argparse h/help d/dir=? -- $argv
|
|
if set -q _flag_h
|
|
echo jrnl: a lightweight journaling tool
|
|
echo
|
|
echo Call jrnl without options to get started.
|
|
echo
|
|
echo Usage:
|
|
echo \tOpen today\'s entry:
|
|
echo \t\> jrnl
|
|
echo \tSet the journal directory "(~/jrnl)" by default:
|
|
echo \tWith environment variable \'jrnl_directory\':
|
|
echo \t\> set -Ug jrnl_directory path/to/journal
|
|
echo \tWith command option:
|
|
echo \t\> jrnl -d=path
|
|
echo \t\> jrnl --dir=path
|
|
echo \tShow this help menu:
|
|
echo \t\> jrnl -h
|
|
echo \t\> jrnl --help
|
|
echo Author:
|
|
echo \tDaniel Fichtinger '<daniel@ficd.ca>'
|
|
echo License:
|
|
echo \tMIT '(c)' Daniel Fichtinger 2025
|
|
return 0
|
|
|
|
end
|
|
|
|
set -f jdir ~/jrnl
|
|
if set -ql _flag_dir[1]
|
|
set jdir _flag_dir[1]
|
|
else if set -q jrnl_directory
|
|
set jdir $jrnl_directory
|
|
end
|
|
|
|
if not test -d $jdir
|
|
mkdir -p $jdir
|
|
end
|
|
|
|
set template $jdir/.template.md
|
|
|
|
if not test -f $template
|
|
set -l prompt "There is no template, create one now? (y/n): "
|
|
while read --nchars 1 -l response --prompt-str="$prompt" or return 1
|
|
printf "\033[1A\033[2K"
|
|
switch $response
|
|
case y Y
|
|
begin
|
|
echo "# $(date +'%A, %b %d, %Y')"\n
|
|
|
|
echo "## Gratitude"\n
|
|
|
|
echo "I'm grateful for ..."\n
|
|
|
|
echo "## + Wins"\n
|
|
|
|
echo "- small_victories"\n
|
|
|
|
echo "## - Challenges"\n
|
|
|
|
echo "- hard_things"\n
|
|
|
|
echo "## Reflection"\n
|
|
|
|
echo "_One sentence to reflect on today:_"\n
|
|
|
|
echo "- reflection"\n
|
|
|
|
echo "## Learned"\n
|
|
|
|
echo "- fact_insight_or_skill"\n
|
|
|
|
echo "## Tomorrow"\n
|
|
|
|
echo "- prep"\n
|
|
end >$template
|
|
eval $EDITOR $template
|
|
set -f new_template
|
|
case n N
|
|
break
|
|
end
|
|
end
|
|
|
|
end
|
|
|
|
# get the date
|
|
set today (date +'%Y-%m-%d')
|
|
set entry "$jdir/$today.md"
|
|
# check if journal entry exists
|
|
if not test -f $entry
|
|
cat $template >$entry
|
|
set -l prompt "Created $entry, open in $EDITOR? (y/n)"
|
|
while read --nchars 1 -l response --prompt-str="$prompt" or return 1
|
|
printf "\033[1A\033[2K"
|
|
switch $response
|
|
case y Y
|
|
eval $EDITOR $entry
|
|
break
|
|
case n N
|
|
break
|
|
end
|
|
end
|
|
else
|
|
eval $EDITOR $entry
|
|
end
|
|
end
|