Merge pull request #1218 from zsh-users/refactor-jrnl
Refactoring jrnl completion
This commit is contained in:
commit
d41e237045
100
src/_jrnl
100
src/_jrnl
|
|
@ -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,43 +38,77 @@
|
||||||
#
|
#
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
_jrnl() {
|
_jrnl() {
|
||||||
local ret=1
|
typeset -A opt_args
|
||||||
|
local context state line
|
||||||
|
local curcontext="$curcontext"
|
||||||
|
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]' \
|
||||||
'*:: :->args' \
|
'-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' \
|
||||||
&& 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
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
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
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue