Add completions for pueue, tea, todoman

This commit is contained in:
crater2150 2021-06-21 12:14:07 +02:00
parent b180a08336
commit 798865b233
3 changed files with 852 additions and 0 deletions

505
compdef/_pueue Normal file
View file

@ -0,0 +1,505 @@
#compdef pueue
autoload -U is-at-least
_pueue() {
typeset -A opt_args
typeset -a _arguments_options
local ret=1
if is-at-least 5.2; then
_arguments_options=(-s -S -C)
else
_arguments_options=(-s -C)
fi
local context curcontext="$curcontext" state line
_arguments "${_arguments_options[@]}" \
'-c+[Path to a specific pueue config file to use. This ignores all other config files]' \
'--config=[Path to a specific pueue config file to use. This ignores all other config files]' \
'*-v[Verbose mode (-v, -vv, -vvv)]' \
'*--verbose[Verbose mode (-v, -vv, -vvv)]' \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
":: :_pueue_commands" \
"*::: :->Pueue client" \
&& ret=0
case $state in
(Pueue client)
words=($line[1] "${words[@]}")
(( CURRENT += 1 ))
curcontext="${curcontext%:*:*}:pueue-command-$line[1]:"
case $line[1] in
(add)
_arguments "${_arguments_options[@]}" \
'(-i --immediate)-d+[Prevents the task from being enqueued until <delay> elapses. See "enqueue" for accepted formats]' \
'(-i --immediate)--delay=[Prevents the task from being enqueued until <delay> elapses. See "enqueue" for accepted formats]' \
'-g+[Assign the task to a group. Groups kind of act as separate queues. I.e. all groups run in parallel and you can specify the amount of parallel tasks for each group. If no group is specified, the default group will be used]' \
'--group=[Assign the task to a group. Groups kind of act as separate queues. I.e. all groups run in parallel and you can specify the amount of parallel tasks for each group. If no group is specified, the default group will be used]' \
'*-a+[Start the task once all specified tasks have successfully finished. As soon as one of the dependencies fails, this task will fail as well]' \
'*--after=[Start the task once all specified tasks have successfully finished. As soon as one of the dependencies fails, this task will fail as well]' \
'-l+[Add some information for yourself. This string will be shown in the "status" table. There'\''s no additional logic connected to it]' \
'--label=[Add some information for yourself. This string will be shown in the "status" table. There'\''s no additional logic connected to it]' \
'-e[Escape any special shell characters (" ", "&", "!", etc.). Beware: This implicitly disables basically all shell specific syntax ("&&", "&>")]' \
'--escape[Escape any special shell characters (" ", "&", "!", etc.). Beware: This implicitly disables basically all shell specific syntax ("&&", "&>")]' \
'(-s --stashed)-i[Immediately start the task]' \
'(-s --stashed)--immediate[Immediately start the task]' \
'(-i --immediate)-s[Create the task in Stashed state. Useful to avoid immediate execution if the queue is empty]' \
'(-i --immediate)--stashed[Create the task in Stashed state. Useful to avoid immediate execution if the queue is empty]' \
'-p[Only return the task id instead of a text. This is useful when scripting and working with dependencies]' \
'--print-task-id[Only return the task id instead of a text. This is useful when scripting and working with dependencies]' \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
'*::command -- The command to be added:' \
&& ret=0
;;
(remove)
_arguments "${_arguments_options[@]}" \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
'*::task-ids -- The task ids to be removed:' \
&& ret=0
;;
(switch)
_arguments "${_arguments_options[@]}" \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
':task-id-1 -- The first task id:' \
':task-id-2 -- The second task id:' \
&& ret=0
;;
(stash)
_arguments "${_arguments_options[@]}" \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
'*::task-ids -- Stash these specific tasks:' \
&& ret=0
;;
(enqueue)
_arguments "${_arguments_options[@]}" \
'-d+[Delay enqueuing these tasks until <delay> elapses. See DELAY FORMAT below]' \
'--delay=[Delay enqueuing these tasks until <delay> elapses. See DELAY FORMAT below]' \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
'*::task-ids -- Enqueue these specific tasks:' \
&& ret=0
;;
(start)
_arguments "${_arguments_options[@]}" \
'(-a --all)-g+[Resume a specific group and all paused tasks in it. The group will be set to running and its paused tasks will be resumed]' \
'(-a --all)--group=[Resume a specific group and all paused tasks in it. The group will be set to running and its paused tasks will be resumed]' \
'-a[Resume all groups! All groups will be set to running and paused tasks will be resumed]' \
'--all[Resume all groups! All groups will be set to running and paused tasks will be resumed]' \
'-c[Also resume direct child processes of your paused tasks. By default only the main process will get a SIGSTART]' \
'--children[Also resume direct child processes of your paused tasks. By default only the main process will get a SIGSTART]' \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
'*::task-ids -- Start these specific tasks. Paused tasks will resumed. Queued or Stashed tasks will be force-started:' \
&& ret=0
;;
(restart)
_arguments "${_arguments_options[@]}" \
'(-s --stashed)-k[Immediately start the tasks]' \
'(-s --stashed)--start-immediately[Immediately start the tasks]' \
'-s[Set the restarted task to a "Stashed" state. Useful to avoid immediate execution]' \
'--stashed[Set the restarted task to a "Stashed" state. Useful to avoid immediate execution]' \
'-i[Restart the task by reusing the already existing tasks. This will overwrite any previous logs of the restarted tasks]' \
'--in-place[Restart the task by reusing the already existing tasks. This will overwrite any previous logs of the restarted tasks]' \
'-a[Restart all failed tasks]' \
'--all-failed[Restart all failed tasks]' \
'-e[Edit the tasks'\'' command before restarting]' \
'--edit[Edit the tasks'\'' command before restarting]' \
'-p[Edit the tasks'\'' path before restarting]' \
'--edit-path[Edit the tasks'\'' path before restarting]' \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
'*::task-ids -- Restart these specific tasks:' \
&& ret=0
;;
(pause)
_arguments "${_arguments_options[@]}" \
'(-a --all)-g+[Pause a specific group]' \
'(-a --all)--group=[Pause a specific group]' \
'-a[Pause all groups!]' \
'--all[Pause all groups!]' \
'-w[Only pause the specified group and let already running tasks finish by themselves]' \
'--wait[Only pause the specified group and let already running tasks finish by themselves]' \
'-c[Also pause direct child processes of a task'\''s main process. By default only the main process will get a SIGSTOP. This is useful when calling bash scripts, which start other processes themselves. This operation is not recursive!]' \
'--children[Also pause direct child processes of a task'\''s main process. By default only the main process will get a SIGSTOP. This is useful when calling bash scripts, which start other processes themselves. This operation is not recursive!]' \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
'*::task-ids -- Pause these specific tasks. Does not affect the default group, groups or any other tasks:' \
&& ret=0
;;
(kill)
_arguments "${_arguments_options[@]}" \
'(-a --all)-g+[Kill all running tasks in a group. This also pauses the group]' \
'(-a --all)--group=[Kill all running tasks in a group. This also pauses the group]' \
'-a[Kill all running tasks across ALL groups. This also pauses all groups]' \
'--all[Kill all running tasks across ALL groups. This also pauses all groups]' \
'-c[Send the SIGTERM signal to all children as well. Useful when working with shell scripts]' \
'--children[Send the SIGTERM signal to all children as well. Useful when working with shell scripts]' \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
'*::task-ids -- Kill these specific tasks:' \
&& ret=0
;;
(send)
_arguments "${_arguments_options[@]}" \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
':task-id -- The id of the task:' \
':input -- The input that should be sent to the process:' \
&& ret=0
;;
(edit)
_arguments "${_arguments_options[@]}" \
'-p[Edit the path of the task]' \
'--path[Edit the path of the task]' \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
':task-id -- The id of the task:' \
&& ret=0
;;
(group)
_arguments "${_arguments_options[@]}" \
'(-r --remove)-a+[Add a group by name]' \
'(-r --remove)--add=[Add a group by name]' \
'-r+[Remove a group by name. This will move all tasks in this group to the default group!]' \
'--remove=[Remove a group by name. This will move all tasks in this group to the default group!]' \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
&& ret=0
;;
(status)
_arguments "${_arguments_options[@]}" \
'-g+[Only show tasks of a specific group]' \
'--group=[Only show tasks of a specific group]' \
'-j[Print the current state as json to stdout. This does not include stdout/stderr of tasks. Use `log -j` if you want everything]' \
'--json[Print the current state as json to stdout. This does not include stdout/stderr of tasks. Use `log -j` if you want everything]' \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
&& ret=0
;;
(log)
_arguments "${_arguments_options[@]}" \
'(-f --full)-l+[Only print the last X lines of each task'\''s output. This is done by default if you'\''re looking at multiple tasks]' \
'(-f --full)--lines=[Only print the last X lines of each task'\''s output. This is done by default if you'\''re looking at multiple tasks]' \
'-j[Print the resulting tasks and output as json. Can be very large!]' \
'--json[Print the resulting tasks and output as json. Can be very large!]' \
'-f[Show the whole stdout and stderr output. This is the default if only a single task is being looked at]' \
'--full[Show the whole stdout and stderr output. This is the default if only a single task is being looked at]' \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
'*::task-ids -- View the task output of these specific tasks:' \
&& ret=0
;;
(follow)
_arguments "${_arguments_options[@]}" \
'-e[Show stderr instead of stdout]' \
'--err[Show stderr instead of stdout]' \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
'::task-id -- The id of the task you want to watch. If no or multiple tasks are running, you have to specify the id. If only a single task is running, you can omit the id:' \
&& ret=0
;;
(wait)
_arguments "${_arguments_options[@]}" \
'(-a --all)-g+[Wait for all tasks in a specific group]' \
'(-a --all)--group=[Wait for all tasks in a specific group]' \
'-a[Wait for all tasks across all groups and the default group]' \
'--all[Wait for all tasks across all groups and the default group]' \
'-q[Don'\''t show any log output while waiting]' \
'--quiet[Don'\''t show any log output while waiting]' \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
'*::task-ids -- This allows you to wait for specific tasks to finish:' \
&& ret=0
;;
(clean)
_arguments "${_arguments_options[@]}" \
'-s[Only clean tasks that finished successfully]' \
'--successful-only[Only clean tasks that finished successfully]' \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
&& ret=0
;;
(reset)
_arguments "${_arguments_options[@]}" \
'-c[Send the SIGTERM signal to all children as well. Useful when working with shell scripts]' \
'--children[Send the SIGTERM signal to all children as well. Useful when working with shell scripts]' \
'-f[Don'\''t ask for any confirmation]' \
'--force[Don'\''t ask for any confirmation]' \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
&& ret=0
;;
(shutdown)
_arguments "${_arguments_options[@]}" \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
&& ret=0
;;
(parallel)
_arguments "${_arguments_options[@]}" \
'-g+[Set the amount for a specific group]' \
'--group=[Set the amount for a specific group]' \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
':parallel-tasks -- The amount of allowed parallel tasks:' \
&& ret=0
;;
(completions)
_arguments "${_arguments_options[@]}" \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
':shell -- The target shell:(bash elvish fish power-shell zsh)' \
':output-directory -- The output directory to which the file should be written:' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
&& ret=0
;;
esac
;;
esac
}
(( $+functions[_pueue_commands] )) ||
_pueue_commands() {
local commands; commands=(
"add:Enqueue a task for execution" \
"remove:Remove tasks from the list. Running or paused tasks need to be killed first" \
"switch:Switches the queue position of two commands. Only works on queued and stashed commands" \
"stash:Stashed tasks won't be automatically started. You have to enqueue them or start them by hand" \
"enqueue:Enqueue stashed tasks. They'll be handled normally afterwards" \
"start:Resume operation of specific tasks or groups of tasks.
By default, this resumes the default group and all its tasks.
Can also be used force-start specific tasks." \
"restart:Restart task(s). Identical tasks will be created and by default enqueued. By default, a new task will be created" \
"pause:Either pause running tasks or specific groups of tasks.
By default, pauses the default group and all its tasks.
A paused queue (group) won't start any new tasks." \
"kill:Kill specific running tasks or whole task groups. Kills all tasks of the default group when no ids are provided" \
"send:Send something to a task. Useful for sending confirmations such as 'y\n'" \
"edit:Edit the command or path of a stashed or queued task.
The command is edited by default." \
"group:Use this to add or remove groups. By default, this will simply display all known groups" \
"status:Display the current status of all tasks" \
"log:Display the log output of finished tasks. Prints either all logs or only the logs of specified tasks" \
"follow:Follow the output of a currently running task. This command works like tail -f" \
"wait:Wait until tasks are finished. This can be quite useful for scripting. By default, this will wait for all tasks in the default group to finish. Note: This will also wait for all tasks that aren't somehow 'Done'. Includes: \[Paused, Stashed, Locked, Queued, ...\]" \
"clean:Remove all finished tasks from the list (also clears logs)" \
"reset:Kill all tasks, clean up afterwards and reset EVERYTHING!" \
"shutdown:Remotely shut down the daemon. Should only be used if the daemon isn't started by a service manager" \
"parallel:Set the amount of allowed parallel tasks. By default, adjusts the amount of the default group" \
"completions:Generates shell completion files. This can be ignored during normal operations" \
"help:Prints this message or the help of the given subcommand(s)" \
)
_describe -t commands 'pueue commands' commands "$@"
}
(( $+functions[_pueue__add_commands] )) ||
_pueue__add_commands() {
local commands; commands=(
)
_describe -t commands 'pueue add commands' commands "$@"
}
(( $+functions[_pueue__clean_commands] )) ||
_pueue__clean_commands() {
local commands; commands=(
)
_describe -t commands 'pueue clean commands' commands "$@"
}
(( $+functions[_pueue__completions_commands] )) ||
_pueue__completions_commands() {
local commands; commands=(
)
_describe -t commands 'pueue completions commands' commands "$@"
}
(( $+functions[_pueue__edit_commands] )) ||
_pueue__edit_commands() {
local commands; commands=(
)
_describe -t commands 'pueue edit commands' commands "$@"
}
(( $+functions[_pueue__enqueue_commands] )) ||
_pueue__enqueue_commands() {
local commands; commands=(
)
_describe -t commands 'pueue enqueue commands' commands "$@"
}
(( $+functions[_pueue__follow_commands] )) ||
_pueue__follow_commands() {
local commands; commands=(
)
_describe -t commands 'pueue follow commands' commands "$@"
}
(( $+functions[_pueue__group_commands] )) ||
_pueue__group_commands() {
local commands; commands=(
)
_describe -t commands 'pueue group commands' commands "$@"
}
(( $+functions[_pueue__help_commands] )) ||
_pueue__help_commands() {
local commands; commands=(
)
_describe -t commands 'pueue help commands' commands "$@"
}
(( $+functions[_pueue__kill_commands] )) ||
_pueue__kill_commands() {
local commands; commands=(
)
_describe -t commands 'pueue kill commands' commands "$@"
}
(( $+functions[_pueue__log_commands] )) ||
_pueue__log_commands() {
local commands; commands=(
)
_describe -t commands 'pueue log commands' commands "$@"
}
(( $+functions[_pueue__parallel_commands] )) ||
_pueue__parallel_commands() {
local commands; commands=(
)
_describe -t commands 'pueue parallel commands' commands "$@"
}
(( $+functions[_pueue__pause_commands] )) ||
_pueue__pause_commands() {
local commands; commands=(
)
_describe -t commands 'pueue pause commands' commands "$@"
}
(( $+functions[_pueue__remove_commands] )) ||
_pueue__remove_commands() {
local commands; commands=(
)
_describe -t commands 'pueue remove commands' commands "$@"
}
(( $+functions[_pueue__reset_commands] )) ||
_pueue__reset_commands() {
local commands; commands=(
)
_describe -t commands 'pueue reset commands' commands "$@"
}
(( $+functions[_pueue__restart_commands] )) ||
_pueue__restart_commands() {
local commands; commands=(
)
_describe -t commands 'pueue restart commands' commands "$@"
}
(( $+functions[_pueue__send_commands] )) ||
_pueue__send_commands() {
local commands; commands=(
)
_describe -t commands 'pueue send commands' commands "$@"
}
(( $+functions[_pueue__shutdown_commands] )) ||
_pueue__shutdown_commands() {
local commands; commands=(
)
_describe -t commands 'pueue shutdown commands' commands "$@"
}
(( $+functions[_pueue__start_commands] )) ||
_pueue__start_commands() {
local commands; commands=(
)
_describe -t commands 'pueue start commands' commands "$@"
}
(( $+functions[_pueue__stash_commands] )) ||
_pueue__stash_commands() {
local commands; commands=(
)
_describe -t commands 'pueue stash commands' commands "$@"
}
(( $+functions[_pueue__status_commands] )) ||
_pueue__status_commands() {
local commands; commands=(
)
_describe -t commands 'pueue status commands' commands "$@"
}
(( $+functions[_pueue__switch_commands] )) ||
_pueue__switch_commands() {
local commands; commands=(
)
_describe -t commands 'pueue switch commands' commands "$@"
}
(( $+functions[_pueue__wait_commands] )) ||
_pueue__wait_commands() {
local commands; commands=(
)
_describe -t commands 'pueue wait commands' commands "$@"
}
_pueue "$@"

16
compdef/_tea Normal file
View file

@ -0,0 +1,16 @@
#compdef tea
local -a opts
local cur
cur=${words[-1]}
if [[ "$cur" == "-"* ]]; then
opts=("${(@f)$(_CLI_ZSH_AUTOCOMPLETE_HACK=1 ${words[@]:0:#words[@]-1} ${cur} --generate-bash-completion)}")
else
opts=("${(@f)$(_CLI_ZSH_AUTOCOMPLETE_HACK=1 ${words[@]:0:#words[@]-1} --generate-bash-completion)}")
fi
if [[ "${opts[1]}" != "" ]]; then
_describe 'values' opts
else
_files
fi

331
compdef/_todo Normal file
View file

@ -0,0 +1,331 @@
#compdef todo
# {{{ sub commands common options variables
local common_options_help=(
'(- :)--help[Show a help message and exit]'
)
local common_options_start=(
{-s,--start=}'[When the task starts]:DATE:__todo_date'
)
local common_options_due=(
{-d,--due=}'[When the task is due]:DATE:__todo_date'
)
local common_options_priority=(
'--priority=[The priority for this todo]:PRIORITY:("low" "medium" "high")'
)
local common_options_interactive=(
{-i,--interactive}'[Go into interactive mode before saving the task]'
)
local common_options_location=(
'--location=[The location where this todo takes place]:LOCATION:'
)
# }}}
# {{{ option helper: color mode
__color_mode(){
local modes=(
"always:enable regardless of stdout"
"auto:enable only when not on tty (default)"
"never:disable colored output entirely"
)
_describe "mode" modes
}
# }}}
# {{{ general helper: set variable of path to configuration file
__todo_set_conf(){
todoman_configuration_file=${XDG_CONFIG_DIR:-${HOME}/.config}/todoman/todoman.conf
if [[ -f $todoman_configuration_file ]]; then
return 0
else
return 1
fi
}
# }}}
# {{{ general helper: set variable main.path from configuration file
__todo_set_conf_path(){
if __todo_set_conf; then
tasks_lists_path="$(sed -n -e 's/^[^#]\s*path\s*=\s*\(.*\)$/\1/p' $todoman_configuration_file 2>/dev/null)"
# the eval echo is needed since the path may contain ~ which should be evalueated to $HOME
tasks_lists_dir="$(eval echo ${tasks_lists_path%/\**})"
if [[ -z "${tasks_lists_path}" || ! -d "${tasks_lists_dir}" ]]; then
return 1
else
return 0
fi
else
return 1
fi
}
# }}}
# {{{ general helper: set variables related to date and time formats for __todo_date
__todo_set_conf_dt(){
if __todo_set_conf; then
date_format="$(eval echo $(sed -n -e 's/^[^#]\s*date_format\s*=\s*\(.*\)$/\1/p' $todoman_configuration_file 2>/dev/null))"
dt_separator="$(eval echo $(sed -n -e 's/^[^#]\s*dt_separator\s*=\s*\(.*\)$/\1/p' $todoman_configuration_file 2>/dev/null))"
time_format="$(eval echo $(sed -n -e 's/^[^#]\s*time_format\s*=\s*\(.*\)$/\1/p' $todoman_configuration_file 2>/dev/null))"
# default value according to documentation: https://todoman.readthedocs.io/en/stable/configure.html
if [[ -z "${date_format}" ]]; then
date_format="%x"
fi
if [[ -z "${dt_separator}" ]]; then
dt_separator=""
fi
if [[ -z "${time_format}" ]]; then
time_format="%x"
fi
return 0
else
return 1
fi
}
# }}}
# {{{ option helper: due and start date
__todo_date(){
if __todo_set_conf_dt; then
_message "date in format ${date_format//\%/%%}${dt_separator//\%/%%}${time_format//\%/%%}"
else
_message "date format (couldn't read configuration file and extract date and time formats)"
fi
}
# }}}
# {{{ argument helper: sub-command choice
__todo_command(){
local commands=(
'cancel:Cancel one or more tasks'
'copy:Copy tasks to another list'
'delete:Delete tasks'
'done:Mark one or more tasks as done'
'edit:Edit the task with id ID'
'flush:Delete done tasks'
'list:List tasks'
'move:Move tasks to another list'
'new:Create a new task with SUMMARY'
'show:Show details about a task'
)
_describe "command" commands
}
# }}}
# {{{ argument helper: available tasks choice
__todo_tasks(){
# checking if the command jq exists and it's version
# credit: http://stackoverflow.com/a/592649/4935114
jq_version=$(jq --version 2>/dev/null)
if [ ${${jq_version#jq\-}//./} -lt 15 ]; then
_message "we can't complete tasks unless you'll install the latest version of jq: https://stedolan.github.io/jq/"
return
fi
# $1 is a comma-seperated list of statuses to show when trying to complete this
local status_search_query="$1"
local -a tasks
IFS=$'\n'
for task_and_description in $(todo --porcelain list --status "${status_search_query}" | jq --raw-output '.[] | .id,":\"@",.list," ",.summary,"\"\\0"' | sed -e ':a' -e 'N' -e '$!ba' -e 's/\n//g' -e 's/\\0/\n/g'); do
tasks+="$(eval echo ${task_and_description})"
done
_describe tasks tasks
}
# }}}
# {{{ todo available lists cache policy
__todo_lists_cache_policy(){
# the number of seconds since 1970-01-01 the directory
local tasks_lists_dir_last_date_modified="$(date -r ${tasks_lists_dir} +%s 2>/dev/null)"
# the number of seconds since 1970-01-01 the cache file was modified
local cache_last_date_modified="$(date -r $1 +%s 2>/dev/null)"
if [[ ! -z ${cache_last_date_modified} && ! -z ${tasks_lists_dir_last_date_modified} ]]; then
# if the manifest file is newer then the cache:
if [ ${tasks_lists_dir_last_date_modified} -ge ${cache_last_date_modified} ]; then
(( 1 ))
else
(( 0 ))
fi
else
(( 1 ))
fi
}
# }}}
# {{{ option helper: available lists
__todo_lists(){
if __todo_set_conf_path; then
local update_policy
zstyle -s ":completion:${curcontext}:" cache-policy update_policy
if [[ -z "$update_policy" ]]; then
zstyle ":completion:${curcontext}:" cache-policy __todo_lists_cache_policy
fi
local -a tasks_lists
if _cache_invalid todoman_lists; then
if [[ ${tasks_lists_path} =~ '/*$' ]]; then
for dir in $(eval echo ${tasks_lists_path}); do
if grep "VTODO" -q -R "${dir}"; then
list_name="${dir##*/}"
tasks_lists+=("${list_name}")
fi
done
fi
_store_cache todoman_lists tasks_lists
else
_retrieve_cache todoman_lists
fi
if [[ "${#tasks_lists[@]}" == 1 ]]; then
_message "only one list was detected: (\"${tasks_lists[1]}\")"
return
else
_describe "available lists" tasks_lists
return
fi
else
_message -e "no 'path = ' string was found in todoman's default configuration file ($todoman_configuration_file)"
return
fi
}
# }}}
# {{{ command `cancel`
_todo_cancel(){
_arguments \
"${common_options_help[@]}" \
'*: :{__todo_tasks "IN-PROCESS,NEEDS-ACTION"}'
}
# }}}
# {{{ command `copy`
local _command_copy_options=(
"${common_options_help[@]}"
{-l,--list=}'[The list to copy the tasks to]:TEXT:__todo_lists'
)
_todo_copy(){
_arguments \
"${_command_copy_options[@]}" \
'*: :{__todo_tasks "IN-PROCESS,NEEDS-ACTION"}'
}
# }}}
# {{{ command `delete`
local _command_delete_options=(
"${common_options_help[@]}"
"--yes[Don't ask for permission before deleting]"
)
_todo_delete(){
_arguments \
"${_command_delete_options[@]}" \
'*: :{__todo_tasks "IN-PROCESS,NEEDS-ACTION"}'
}
# }}}
# {{{ command `done`
local _command_done_options=(
"${common_options_help[@]}"
)
_todo_done(){
_arguments \
"${_command_done_options[@]}" \
'*: :{__todo_tasks "IN-PROCESS,NEEDS-ACTION"}'
}
# }}}
# {{{ command `edit`
local _command_edit_options=(
"${common_options_help[@]}"
"${common_options_start[@]}"
"${common_options_due[@]}"
"${common_options_priority[@]}"
"${common_options_location[@]}"
"${common_options_interactive[@]}"
)
_todo_edit(){
_arguments \
"${_command_edit_options[@]}" \
'*: :{__todo_tasks "IN-PROCESS,NEEDS-ACTION"}'
}
# }}}
# {{{ command `flush`
_todo_flush(){
}
# }}}
# {{{ command `list`
_command_list_options=(
"${common_options_location[@]}"
'--category=[Only show tasks with category containg TEXT]:TEXT:__todo_existing_categories'
'--grep=[Only show tasks with message containg TEXT]:TEXT:'
'--sort=[Sort tasks using these fields]:TEXT:(description location status summary uid rrule percent_complete priority sequence categories completed_at created_at dtstamp start due last_modified)'
'(--reverse --no-reverse)'{--reverse,--no-reverse}'[sort tasks in reverse order (see --sort)]'
"${common_options_start[@]}"
"${common_options_due[@]}"
'--priority[Only show tasks with priority at least as high as TEXT]:TEXT:("low", "medium", "high")'
'--startable[Show only todos which should can be started today]'
{-s,--status=}'[Show only todos with the provided comma-separated statuses]:STATUS:{_values -s , "status" "NEEDS-ACTION" "CANCELLED" "COMPLETED" "IN-PROCESS" "ANY"}'
"${common_options_help[@]}"
)
_todo_list(){
_arguments \
"${_command_list_options[@]}" \
'1: :__todo_lists' \
}
# }}}
# {{{ command `move`
_todo_move(){
_todo_copy
}
# }}}
# {{{ command `new`
local _command_new_options=(
"${common_options_start[@]}"
"${common_options_due[@]}"
"${common_options_help[@]}"
{-l,--list=}'[The list to move the tasks to]:TEXT:__todo_lists'
'--location[The location where this todo takes place.]:TEXT:__todo_existing_locations'
"${common_options_priority[@]}"
"${common_options_interactive[@]}"
)
_todo_new(){
_arguments \
"${_command_new_options[@]}" \
'*: :{_message "summary"}'
}
# }}}
# {{{ command `show`
_todo_show(){
_todo_done
}
# }}}
# The real thing
_arguments -C -A "-*" \
{-v,--verbosity=}'[Set verbosity to the given level]:MODE(CRITICAL ERROR WARNING INFO DEBUG)' \
'--color=[Set colored output mode]:MODE:__color_mode' \
'--porcelain[Use a JSON format that will remain stable regadless of configuration or version]' \
{-h,--humanize}'[Format all dates and times in a human friendly way]' \
'(- :)--version[Show the version and exit]' \
"${common_options_help[@]}" \
'1: :__todo_command' \
'*::arg:->args'
case $state in
(args)
curcontext="${curcontext%:*:*}:todo_$words[1]:"
case "${words[1]}" in
cancel)
_todo_cancel
;;
copy)
_todo_copy
;;
delete)
_todo_delete
;;
done)
_todo_done
;;
edit)
_todo_edit
;;
flush)
_todo_flush
;;
list)
_todo_list
;;
move)
_todo_move
;;
new)
_todo_new
;;
show)
_todo_show
;;
esac
;;
esac