AutoYADM commit: 2025-04-23 14:30:05

This commit is contained in:
Daniel Fichtinger 2025-04-23 14:30:05 -04:00
parent ef22c23678
commit d31c2a02a6
2 changed files with 51 additions and 48 deletions

View file

@ -1,11 +1,4 @@
complete -c jrnl -s h -l help -d 'Print help' complete -c jrnl -s h -l help -d 'Print help'
complete -c jrnl -s e -l edit-template -d 'Edit the journal entry template' complete -c jrnl -s e -l edit-template -d 'Edit the journal entry template'
complete -c jrnl -s d -l dir -d 'Set the journal directory' -r complete -c jrnl -s d -l dir -d 'Set the journal directory' -r
function __jrnl_dir
if set -q jrnl_directory
echo $jrnl_directory
else
echo ~/jrnl
end
end
complete -c jrnl -s t -l template -d 'Set the template file' -r complete -c jrnl -s t -l template -d 'Set the template file' -r

View file

@ -1,39 +1,41 @@
function jrnl --description 'Lightweight journaling tool' function jrnl --description 'Lightweight journaling tool'
argparse h/help d/dir=? t/template=? e/edit-template -- $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 (set_color -o)jrnl: a lightweight journaling tool(set_color normal)
echo echo
echo Call jrnl without options to get started. echo Call jrnl without options to get started.
echo echo
echo Usage: echo (set_color -o)Usage:(set_color normal)
echo \tOpen today\'s entry: echo (set_color -o)\tOpen today\'s entry:(set_color normal)
echo \t\> jrnl echo \t\> jrnl
echo \tEdit the template: echo (set_color -o)\tEdit the template:(set_color normal)
echo \t\> jrnl -e echo \t\> jrnl -e
echo \t\> jrnl --edit-template echo \t\> jrnl --edit-template
echo \tSet the journal directory "(~/jrnl)" by default: echo (set_color -o)\tSet the journal directory "(~/jrnl)" by default:(set_color normal)
echo \t\> set -Ug jrnl_directory path/to/journal echo \t\> set -Ug jrnl_directory path/to/journal
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 (set_color -o)\tSet the template file:(set_color normal)
echo \t\> set -Ug jrnl_template template_file echo \t\> set -Ug jrnl_template template_file
echo \t\> jrnl -t=template_file.md echo \t\> jrnl -t template_file.md
echo \t\> jrnl --template=template_file.md echo \t\> jrnl --template template_file.md
echo \tShow this help menu: echo (set_color -i)\tIf the variable or option resolves to a real file,(set_color normal)
echo (set_color -i)\tit will be used as the template. Otherwise, the(set_color normal)
echo (set_color -i)\tjrnl directory is searched for the file name.(set_color normal)
echo (set_color -o)\tShow this help menu:(set_color normal)
echo \t\> jrnl -h echo \t\> jrnl -h
echo \t\> jrnl --help echo \t\> jrnl --help
echo Template file: echo (set_color -o)Template file:(set_color normal)
echo \tThe template file is a Markdown file inside the echo \t"\$jrnl_directory/template.md" is its default location.
echo \tjournal directory, called \'template.md\' by default.
echo \tMarkdown comments are always skipped. echo \tMarkdown comments are always skipped.
echo \tExtra newlines at the file end are trimmed. echo \tExtra newlines at the file end are trimmed.
echo \tThe literals '\'%{date}\'' and '\'%{date_long}\'' echo \tThe literals '\'%{date}\'' and '\'%{date_long}\''
echo \tare substituted for date values. echo \tare substituted for date values.
echo Author: echo (set_color -o)Author:(set_color normal)
echo \tDaniel Fichtinger '<daniel@ficd.ca>' echo \tDaniel Fichtinger '<'(set_color -u)daniel@ficd.ca(set_color normal)'>'
echo URL: echo (set_color -o)URL:(set_color normal)
echo \thttps://git.sr.ht/~ficd/jrnl.fish echo (set_color -u)\thttps://git.sr.ht/~ficd/jrnl.fish(set_color normal)
echo License: echo (set_color -o)License:(set_color normal)
echo \tMIT '(c)' Daniel Fichtinger 2025 echo \tMIT '(c)' Daniel Fichtinger 2025
return 0 return 0
@ -52,31 +54,39 @@ function jrnl --description 'Lightweight journaling tool'
set -f template $jdir/template.md set -f template $jdir/template.md
if set -ql _flag_template[1] if set -ql _flag_template[1]
set template $jdir/$_flag_template[1] set template (path resolve $_flag_template[1])
else if set -q jrnl_template else if set -q jrnl_template
set template $jdir/$jrnl_template set template $jrnl_template
end end
set -f template_base (path basename $template)
if not test -f $template if not test -f $template
set -l prompt "There is no template, create one now? (y/n): " # first check if template exists in jdir
while read --nchars 1 -l response --prompt-str="$prompt" or return 1 set -l candidate (fd -F -1 "$template_base" "$jdir")
printf "\033[1A\033[2K" if test -n "$candidate"
switch $response set template (path resolve $candidate)
case y Y else
begin set template $jdir/$template_base
echo '<!-- This is the jrnl template file. -->' set -l prompt "There is no template at $template, create one now? (y/n): "
echo '<!-- Markdown comments will be ignored! -->' while read --nchars 1 -l response --prompt-str="$prompt" or return 1
echo '<!-- Date placeholders are supported. -->' printf "\033[1A\033[2K"
echo '# %{date}' switch $response
echo '<!-- Everything besides comments and dates are copied directly! -->' case y Y
echo begin
echo 'Today is %{date_long}.' echo '<!-- This is the jrnl template file. -->'
end >$template echo '<!-- Markdown comments will be ignored! -->'
eval $EDITOR $template echo '<!-- Date placeholders are supported. -->'
set -q _flag_e; and return 0 echo '# %{date}'
break echo '<!-- Everything besides comments and dates are copied directly! -->'
case n N echo
break echo 'Today is %{date_long}.'
end >$template
eval $EDITOR $template
set -q _flag_e; and return 0
break
case n N
return 0
end
end end
end end
end end