From 49c4bb7d984476a09776bb4151b404596f6be680 Mon Sep 17 00:00:00 2001 From: Daniel Fichtinger Date: Wed, 23 Apr 2025 02:15:06 -0400 Subject: [PATCH] AutoYADM commit: 2025-04-23 02:15:06 --- .config/fish/functions/jrnl.fish | 35 +++++++++++++++++++------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/.config/fish/functions/jrnl.fish b/.config/fish/functions/jrnl.fish index 4fa5295b..08a57ef8 100644 --- a/.config/fish/functions/jrnl.fish +++ b/.config/fish/functions/jrnl.fish @@ -1,5 +1,5 @@ function jrnl --description 'Lightweight journaling tool' - argparse h/help d/dir=? -- $argv + argparse h/help d/dir=? e/edit -- $argv if set -q _flag_h echo jrnl: a lightweight journaling tool echo @@ -8,6 +8,9 @@ function jrnl --description 'Lightweight journaling tool' echo Usage: echo \tOpen today\'s entry: echo \t\> jrnl + echo \tEdit the template: + echo \t\> jrnl -e + echo \t\> jrnl --edit echo \tSet the journal directory "(~/jrnl)" by default: echo \tWith environment variable \'jrnl_directory\': echo \t\> set -Ug jrnl_directory path/to/journal @@ -81,7 +84,6 @@ function jrnl --description 'Lightweight journaling tool' break end end - end # get the date @@ -89,19 +91,24 @@ function jrnl --description 'Lightweight journaling tool' 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] - end - set contents ($lines | - string match --invert --regex '^' | - string replace --all '%{date_long}' "$(date +'%A, %b %d, %Y')" | - string replace --all '%{date}' "$today" | - string collect -N ) - echo $contents - return 0 + # 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) - cat $template >$entry + 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 printf "\033[1A\033[2K"