From 453cfaf91e9e70b006eae94c557fb0ee2c66e6fb Mon Sep 17 00:00:00 2001 From: Daniel Fichtinger Date: Wed, 23 Apr 2025 23:15:05 -0400 Subject: [PATCH] AutoYADM commit: 2025-04-23 23:15:05 --- .config/fish/completions/jrnl.fish | 1 + .config/fish/functions/jrnl.fish | 25 ++++++++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/.config/fish/completions/jrnl.fish b/.config/fish/completions/jrnl.fish index 8f1b628d..44c43f44 100644 --- a/.config/fish/completions/jrnl.fish +++ b/.config/fish/completions/jrnl.fish @@ -2,3 +2,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 complete -c jrnl -s t -l template -d 'Set the template file' -r +complete -c jrnl -s o -l offset -d 'Set hours from midnight for start of tomorrow' -r -f diff --git a/.config/fish/functions/jrnl.fish b/.config/fish/functions/jrnl.fish index 3848b5b9..dbcd6eb6 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= t/template= e/edit-template -- $argv + argparse h/help d/dir= t/template= e/edit-template o/offset= -- $argv if set -q _flag_h echo (set_color -o)jrnl: a lightweight journaling tool(set_color normal) echo @@ -8,6 +8,11 @@ function jrnl --description 'Lightweight journaling tool' echo (set_color -o)Usage:(set_color normal) echo (set_color -o)\tOpen today\'s entry:(set_color normal) echo \t\> jrnl + echo (set_color -o)\tSet a time offset '(in hours, from midnight)' + echo \tfor start of the next day '(default: 3)':(set_color normal) + echo \t\> set -Ug jrnl_offset 2 + echo \t\> jrnl -o 2 + echo \t\> jrnl --offset 2 echo (set_color -o)\tEdit the template:(set_color normal) echo \t\> jrnl -e echo \t\> jrnl --edit-template @@ -99,8 +104,22 @@ function jrnl --description 'Lightweight journaling tool' return 0 end - # get the date - set today (date +'%Y-%m-%d') + set -g offset 3 + if set -ql _flag_offset[1] + echo flag is set + set offset $_flag_offset[1] + else if set -q jrnl_offset + set offset $jrnl_offset + end + + function get_date -a fmt + if test (date +%H) -lt "$offset" + date -d yesterday +"$fmt" + else + date +"$fmt" + end + end + set today (get_date '%Y-%m-%d') set entry "$jdir/$today.md" # check if journal entry exists if not test -f $entry