From d31c2a02a6da9f2c5cf9722fe64c5a811d04c6b5 Mon Sep 17 00:00:00 2001 From: Daniel Fichtinger Date: Wed, 23 Apr 2025 14:30:05 -0400 Subject: [PATCH] AutoYADM commit: 2025-04-23 14:30:05 --- .config/fish/completions/jrnl.fish | 7 --- .config/fish/functions/jrnl.fish | 92 +++++++++++++++++------------- 2 files changed, 51 insertions(+), 48 deletions(-) diff --git a/.config/fish/completions/jrnl.fish b/.config/fish/completions/jrnl.fish index 1edaf21b..8f1b628d 100644 --- a/.config/fish/completions/jrnl.fish +++ b/.config/fish/completions/jrnl.fish @@ -1,11 +1,4 @@ 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 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 diff --git a/.config/fish/functions/jrnl.fish b/.config/fish/functions/jrnl.fish index 376b5b49..743fec3e 100644 --- a/.config/fish/functions/jrnl.fish +++ b/.config/fish/functions/jrnl.fish @@ -1,39 +1,41 @@ 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 - echo jrnl: a lightweight journaling tool + echo (set_color -o)jrnl: a lightweight journaling tool(set_color normal) echo echo Call jrnl without options to get started. echo - echo Usage: - echo \tOpen today\'s entry: + echo (set_color -o)Usage:(set_color normal) + echo (set_color -o)\tOpen today\'s entry:(set_color normal) echo \t\> jrnl - echo \tEdit the template: + echo (set_color -o)\tEdit the template:(set_color normal) echo \t\> jrnl -e 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\> jrnl -d=path - echo \t\> jrnl --dir=path - echo \tSet the template file "(relative to journal directory)": + echo \t\> jrnl -d path + echo \t\> jrnl --dir path + echo (set_color -o)\tSet the template file:(set_color normal) 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 -t template_file.md + echo \t\> jrnl --template template_file.md + 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 --help - echo Template file: - echo \tThe template file is a Markdown file inside the - echo \tjournal directory, called \'template.md\' by default. + echo (set_color -o)Template file:(set_color normal) + echo \t"\$jrnl_directory/template.md" is its default location. echo \tMarkdown comments are always skipped. echo \tExtra newlines at the file end are trimmed. echo \tThe literals '\'%{date}\'' and '\'%{date_long}\'' echo \tare substituted for date values. - echo Author: - echo \tDaniel Fichtinger '' - echo URL: - echo \thttps://git.sr.ht/~ficd/jrnl.fish - echo License: + echo (set_color -o)Author:(set_color normal) + echo \tDaniel Fichtinger '<'(set_color -u)daniel@ficd.ca(set_color normal)'>' + echo (set_color -o)URL:(set_color normal) + echo (set_color -u)\thttps://git.sr.ht/~ficd/jrnl.fish(set_color normal) + echo (set_color -o)License:(set_color normal) echo \tMIT '(c)' Daniel Fichtinger 2025 return 0 @@ -52,31 +54,39 @@ function jrnl --description 'Lightweight journaling tool' set -f template $jdir/template.md 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 - set template $jdir/$jrnl_template + set template $jrnl_template end + set -f template_base (path basename $template) 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 '' - echo '' - echo '' - echo '# %{date}' - echo '' - echo - echo 'Today is %{date_long}.' - end >$template - eval $EDITOR $template - set -q _flag_e; and return 0 - break - case n N - break + # first check if template exists in jdir + set -l candidate (fd -F -1 "$template_base" "$jdir") + if test -n "$candidate" + set template (path resolve $candidate) + else + set template $jdir/$template_base + set -l prompt "There is no template at $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 '' + echo '' + echo '' + echo '# %{date}' + echo '' + echo + 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