AutoYADM commit: 2025-04-23 02:15:06
This commit is contained in:
parent
aa3140fe6a
commit
49c4bb7d98
1 changed files with 21 additions and 14 deletions
|
@ -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"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue