AutoYADM commit: 2025-04-23 02:30:05
This commit is contained in:
parent
49c4bb7d98
commit
abd8998d71
1 changed files with 25 additions and 46 deletions
|
@ -1,5 +1,5 @@
|
|||
function jrnl --description 'Lightweight journaling tool'
|
||||
argparse h/help d/dir=? e/edit -- $argv
|
||||
argparse h/help d/dir=? t/template=? e/edit-template -- $argv
|
||||
if set -q _flag_h
|
||||
echo jrnl: a lightweight journaling tool
|
||||
echo
|
||||
|
@ -10,13 +10,15 @@ function jrnl --description 'Lightweight journaling tool'
|
|||
echo \t\> jrnl
|
||||
echo \tEdit the template:
|
||||
echo \t\> jrnl -e
|
||||
echo \t\> jrnl --edit
|
||||
echo \t\> jrnl --edit-template
|
||||
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 \tSet the template file "(relative to journal directory)":
|
||||
echo \t\> set -Ug jrnl_template template_file
|
||||
echo \t\> jrnl -t=template_file.md
|
||||
echo \t\> jrnl --template=template_file.md
|
||||
echo \tShow this help menu:
|
||||
echo \t\> jrnl -h
|
||||
echo \t\> jrnl --help
|
||||
|
@ -30,7 +32,7 @@ function jrnl --description 'Lightweight journaling tool'
|
|||
|
||||
set -f jdir ~/jrnl
|
||||
if set -ql _flag_dir[1]
|
||||
set jdir _flag_dir[1]
|
||||
set jdir $_flag_dir[1]
|
||||
else if set -q jrnl_directory
|
||||
set jdir $jrnl_directory
|
||||
end
|
||||
|
@ -39,7 +41,12 @@ function jrnl --description 'Lightweight journaling tool'
|
|||
mkdir -p $jdir
|
||||
end
|
||||
|
||||
set template $jdir/.template.md
|
||||
set -f template $jdir/template.md
|
||||
if set -ql _flag_template[1]
|
||||
set template $jdir/$_flag_template[1]
|
||||
else if set -q jrnl_template
|
||||
set template $jdir/$jrnl_template
|
||||
end
|
||||
|
||||
if not test -f $template
|
||||
set -l prompt "There is no template, create one now? (y/n): "
|
||||
|
@ -48,66 +55,38 @@ function jrnl --description 'Lightweight journaling tool'
|
|||
switch $response
|
||||
case y Y
|
||||
begin
|
||||
echo '# %{date}'\n
|
||||
echo '<!-- Use the %{date} placeholder for the date. -->'
|
||||
echo '<!-- Comments will be ignored. -->'
|
||||
|
||||
# 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
|
||||
echo '<!-- This is the jrnl template file. -->'
|
||||
echo '<!-- Markdown comments will be ignored! -->'
|
||||
echo '<!-- Date placeholders are supported. -->'
|
||||
echo '# %{date}'
|
||||
echo '<!-- Everything besides comments and dates are copied directly! -->'
|
||||
echo
|
||||
echo 'Today is %{date_long}.'
|
||||
end >$template
|
||||
eval $EDITOR $template
|
||||
set -q _flag_e; and return 0
|
||||
break
|
||||
case n N
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
if set -q _flag_e
|
||||
eval $EDITOR $template
|
||||
return 0
|
||||
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
|
||||
# set lines (cat $template)
|
||||
# while test -z "$lines[-1]"
|
||||
# set -e lines[-1]
|
||||
# echo empty
|
||||
# end
|
||||
# echo $lines
|
||||
set contents (cat $template | \
|
||||
string match --invert --regex '^<!--.*-->' | \
|
||||
string replace --all '%{date_long}' "$(date +'%A, %b %d, %Y')" | \
|
||||
string replace --all '%{date}' "$today" | \
|
||||
string collect -N)
|
||||
set contents (string trim --right $contents | string collect -N)
|
||||
# echo -n $contents
|
||||
# echo $contents
|
||||
# echo $contents | string collect -N
|
||||
# return 0
|
||||
# set contents (string join \n "# $today" "$(tail -n +2 $template)" | string collect -N)
|
||||
echo -n "$contents" >$entry
|
||||
set -l prompt "Created $entry, open in $EDITOR? (y/n)"
|
||||
while read --nchars 1 -l response --prompt-str="$prompt" or return 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue