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'
|
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
|
if set -q _flag_h
|
||||||
echo jrnl: a lightweight journaling tool
|
echo jrnl: a lightweight journaling tool
|
||||||
echo
|
echo
|
||||||
|
@ -10,13 +10,15 @@ function jrnl --description 'Lightweight journaling tool'
|
||||||
echo \t\> jrnl
|
echo \t\> jrnl
|
||||||
echo \tEdit the template:
|
echo \tEdit the template:
|
||||||
echo \t\> jrnl -e
|
echo \t\> jrnl -e
|
||||||
echo \t\> jrnl --edit
|
echo \t\> jrnl --edit-template
|
||||||
echo \tSet the journal directory "(~/jrnl)" by default:
|
echo \tSet the journal directory "(~/jrnl)" by default:
|
||||||
echo \tWith environment variable \'jrnl_directory\':
|
|
||||||
echo \t\> set -Ug jrnl_directory path/to/journal
|
echo \t\> set -Ug jrnl_directory path/to/journal
|
||||||
echo \tWith command option:
|
|
||||||
echo \t\> jrnl -d=path
|
echo \t\> jrnl -d=path
|
||||||
echo \t\> jrnl --dir=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 \tShow this help menu:
|
||||||
echo \t\> jrnl -h
|
echo \t\> jrnl -h
|
||||||
echo \t\> jrnl --help
|
echo \t\> jrnl --help
|
||||||
|
@ -30,7 +32,7 @@ function jrnl --description 'Lightweight journaling tool'
|
||||||
|
|
||||||
set -f jdir ~/jrnl
|
set -f jdir ~/jrnl
|
||||||
if set -ql _flag_dir[1]
|
if set -ql _flag_dir[1]
|
||||||
set jdir _flag_dir[1]
|
set jdir $_flag_dir[1]
|
||||||
else if set -q jrnl_directory
|
else if set -q jrnl_directory
|
||||||
set jdir $jrnl_directory
|
set jdir $jrnl_directory
|
||||||
end
|
end
|
||||||
|
@ -39,7 +41,12 @@ function jrnl --description 'Lightweight journaling tool'
|
||||||
mkdir -p $jdir
|
mkdir -p $jdir
|
||||||
end
|
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
|
if not test -f $template
|
||||||
set -l prompt "There is no template, create one now? (y/n): "
|
set -l prompt "There is no template, create one now? (y/n): "
|
||||||
|
@ -48,66 +55,38 @@ function jrnl --description 'Lightweight journaling tool'
|
||||||
switch $response
|
switch $response
|
||||||
case y Y
|
case y Y
|
||||||
begin
|
begin
|
||||||
echo '# %{date}'\n
|
echo '<!-- This is the jrnl template file. -->'
|
||||||
echo '<!-- Use the %{date} placeholder for the date. -->'
|
echo '<!-- Markdown comments will be ignored! -->'
|
||||||
echo '<!-- Comments will be ignored. -->'
|
echo '<!-- Date placeholders are supported. -->'
|
||||||
|
echo '# %{date}'
|
||||||
# echo "## Gratitude"\n
|
echo '<!-- Everything besides comments and dates are copied directly! -->'
|
||||||
|
echo
|
||||||
# echo "I'm grateful for ..."\n
|
echo 'Today is %{date_long}.'
|
||||||
|
|
||||||
# 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
|
end >$template
|
||||||
eval $EDITOR $template
|
eval $EDITOR $template
|
||||||
|
set -q _flag_e; and return 0
|
||||||
break
|
break
|
||||||
case n N
|
case n N
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if set -q _flag_e
|
||||||
|
eval $EDITOR $template
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
# get the date
|
# get the date
|
||||||
set today (date +'%Y-%m-%d')
|
set today (date +'%Y-%m-%d')
|
||||||
set entry "$jdir/$today.md"
|
set entry "$jdir/$today.md"
|
||||||
# check if journal entry exists
|
# check if journal entry exists
|
||||||
if not test -f $entry
|
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 | \
|
set contents (cat $template | \
|
||||||
string match --invert --regex '^<!--.*-->' | \
|
string match --invert --regex '^<!--.*-->' | \
|
||||||
string replace --all '%{date_long}' "$(date +'%A, %b %d, %Y')" | \
|
string replace --all '%{date_long}' "$(date +'%A, %b %d, %Y')" | \
|
||||||
string replace --all '%{date}' "$today" | \
|
string replace --all '%{date}' "$today" | \
|
||||||
string collect -N)
|
string collect -N)
|
||||||
set contents (string trim --right $contents | 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
|
echo -n "$contents" >$entry
|
||||||
set -l prompt "Created $entry, open in $EDITOR? (y/n)"
|
set -l prompt "Created $entry, open in $EDITOR? (y/n)"
|
||||||
while read --nchars 1 -l response --prompt-str="$prompt" or return 1
|
while read --nchars 1 -l response --prompt-str="$prompt" or return 1
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue