Refactoring jrnl completion

- Apply format
- Update URL
- Update flags to latest version
This commit is contained in:
Shohei YOSHIDA 2026-01-23 19:08:20 +09:00
parent 6370f5a58f
commit 93dc422070
No known key found for this signature in database
GPG Key ID: C9A1BB11BB940CF2
1 changed files with 67 additions and 33 deletions

View File

@ -28,7 +28,7 @@
# Description # Description
# ----------- # -----------
# #
# Completion script for jrnl a simple journal application for your command line. (https://maebert.github.io/jrnl/). # Completion script for jrnl v4.2.1 (https://github.com/jrnl-org/jrnl).
# #
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Authors # Authors
@ -38,36 +38,48 @@
# #
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
_jrnl() { _jrnl() {
typeset -A opt_args
local context state line
local curcontext="$curcontext"
local ret=1 local ret=1
_arguments -C \ _arguments -C \
'(- 1 *)'-h"[Show help and exit]" \ '--debug[Print information useful for troubleshooting]' \
'(- 1 *)'-v"[Prints version information and exits]" \ '(- *)--help[Show help message]' \
'(- 1 *)'-ls"[Displays accessible journals]" \ '(- *)--version[print version information]' \
'(- 1 *)'-d"[Execute in debug mode]" \ '--list[List all configured journals]' \
'(- 1 *)'--tags"[Returns a list of all tags and number of occurrences]" \ '--encrypt[Encrypt selected journal with a password]' \
"--short[Show only titles or line containing the search]" \ '--decrypt[Decrypt selected journal and store it in plain text]' \
"-from[View entries after this date]:date:" \ '--import[Import entries from another journal]' \
"-until[View entries before this date]:date:" \ '-on[Show entries on this date]:date' \
"-to[View entries before this date]:date:" \ '-today-in-history[Show entries of today over the years]' \
"-on[View entries on this date]:date:" \ '-month[Show entries on this month of any year]:date' \
"-and[Filter by tags using AND (default: OR)]" \ '-day[Show entries on this day of any month]:date' \
"-starred[Show only starred entries]" \ '-year[Show entries of a specific year]:date' \
"-n[Shows the last n entries matching the filter. And '-3' have the same effect.]":number: \ '-from[Show entries after, or on, this date]:date' \
"--export[Export your journal. TYPE can be json, markdown text.]:format:(json markdown text)" \ '(-to -until)'{-to,-until}'[Show entries before, or on, this date]' \
"-o[Optionally specifies output file when using --export If OUTPUT is a directory, exports each entry in individual file instead.]:output file:" \ '-contains[Show entries containing specific text]:text' \
"--encrypt[Encrypts your existing journal with a new pass]" \ '-and[Show only entries that match all conditions(default: OR)]' \
"--decrypt[Decrypts your journal and stores it in plain text]" \ '-starred[Show only starred entries (marked with *)]' \
"--edit[Opens your editor to edit the selected entries.]" \ '-tagged[Show only entries that have at least one tag]' \
'-n[Show a maximum of NUMBER entries. And "-3" has the same effect]:number' \
'-not[exclude entries with that tag]:tag_or_flag' \
'--edit[Opens the selected entries in your configured editor]' \
'--delete[Interactively deletes selected entries]' \
'--change-time[Change timestamp for selected entries(default: now)]:date' \
'--format[Display selected entries in an alternate format]:format:_jrnl_formats' \
'--tags[Alias for "--format tags"]' \
'--short[Show only titles or line containing the search tags]' \
'--config-override[Override configured key-value pair]:key_value' \
'--config-file[Override default config file]:path:_files' \
'*:: :->args' \ '*:: :->args' \
&& ret=0 && ret=0
case $state in case $state in
(args) (args)
if [[ $PREFIX = @* ]]; then if [[ $PREFIX = @* ]]; then
local -a tags=($(jrnl --tags 2>/dev/null | grep -oE '@\S+')) local -a tags=($(jrnl --tags 2>/dev/null | command grep -oE '@\S+'))
_describe -t tags 'tags' tags && ret=0 _describe -t tags 'tags' tags && ret=0
fi fi
;; ;;
@ -76,5 +88,27 @@ _jrnl() {
return ret return ret
} }
_jrnl (( $+functions[_jrnl_formats] )) ||
_jrnl_formats() {
local -a formats
if (( $+opt_args[--list] )); then
formats=(json yaml)
elif (( $+opt_args[--import] )); then
formats=(jrnl)
else
formats=(boxed calendar dates fancy heatmap json markdown md pretty short tags text txt xml yaml)
fi
_values 'format' $formats
}
_jrnl "$@"
# Local Variables:
# mode: Shell-Script
# sh-indentation: 2
# indent-tabs-mode: nil
# sh-basic-offset: 2
# End:
# vim: ft=zsh sw=2 ts=2 et