diff --git a/README.org b/README.org index 43bb936..56878ad 100644 --- a/README.org +++ b/README.org @@ -142,3 +142,9 @@ Commands: И не забудте сделать симлинк (например) =/usr/local/bin/timer= на =worktimer.scm=. +** Автодополнение для bash +Автодополнение в bash включается так: + +#+begin_src sh + $ . bash-completion/timer +#+end_src diff --git a/bash-completion/timer b/bash-completion/timer new file mode 100644 index 0000000..253e7dc --- /dev/null +++ b/bash-completion/timer @@ -0,0 +1,72 @@ +_timer() +{ + local uncomplete=${COMP_WORDS[COMP_CWORD]} + + case "$COMP_CWORD" in + 1) + # Commands + COMPREPLY=( $(compgen -W "start stop report deadline refresh help" -- $uncomplete) ) + ;; + 2) + # Command argument 1 + case "${COMP_WORDS[1]}" in + start) + local tasklist=$(timer tasklist) + COMPREPLY=( $(compgen -W "$tasklist" -- $uncomplete)) + ;; + report) + local tasklist=$(timer tasklist) + COMPREPLY=( $(compgen -W "day week month $tasklist" -- $uncomplete)) + ;; + deadline) + local deadlist=$(timer deadlist) + COMPREPLY=( $(compgen -W "set clear all $deadlist" -- $uncomplete)) + ;; + esac + ;; + 3) + # Command argument 2 + case "${COMP_WORDS[1]}" in + report) + case "${COMP_WORDS[2]}" in + day) + local d=$(date +"%Y-%m-%d") + COMPREPLY=( $(compgen -W "$d" -- $uncomplete)) + ;; + week) + local d=$(date +"%Y-%m-%d") + COMPREPLY=( $(compgen -W "$d" -- $uncomplete)) + ;; + month) + local d=$(date +"%Y-%m-%d") + COMPREPLY=( $(compgen -W "$d" -- $uncomplete)) + ;; + esac + ;; + deadline) + case "${COMP_WORDS[2]}" in + set) + local tasklist=$(timer tasklist) + local d=$(date +"%Y-%m-%d") + COMPREPLY=( $(compgen -W "$tasklist $d" -- $uncomplete)) + ;; + clear) + local deadlist=$(timer deadlist) + COMPREPLY=( $(compgen -W "$deadlist" -- $uncomplete)) + ;; + esac + ;; + esac + ;; + 4) + # Command argument 3 + if [ "${COMP_WORDS[1]}" = "deadline" ] + then + local d=$(date +"%Y-%m-%d") + COMPREPLY=( $(compgen -W "$d" -- $uncomplete)) + fi + ;; + esac +} + +complete -F _timer timer diff --git a/zsh-completion/_timer b/zsh-completion/_timer index e7bd8a6..188cdf4 100644 --- a/zsh-completion/_timer +++ b/zsh-completion/_timer @@ -2,68 +2,72 @@ _timer() { - typeset -A opt_args - - _arguments \ - '1: :->command' \ - '2: :->arg1' \ - '3: :->arg2' \ - '4: :->arg3' - - case "$state" in - (command) - _arguments '1:commands:(start stop report deadline refresh help)' - ;; + typeset -A opt_args + + _arguments \ + '1: :->command' \ + '2: :->arg1' \ + '3: :->arg2' \ + '4: :->arg3' + + case "$state" in + (command) + # Commands + _arguments '1:commands:(start stop report deadline refresh help)' + ;; - (arg1) - case $words[2] in - (start) - compadd $(timer tasklist) - ;; - (report) - compadd day week month $(timer tasklist) - ;; - (deadline) - compadd set clear all $(timer deadlist) - ;; - esac - ;; + (arg1) + # Command argument 1 + case $words[2] in + (start) + compadd $(timer tasklist) + ;; + (report) + compadd day week month $(timer tasklist) + ;; + (deadline) + compadd set clear all $(timer deadlist) + ;; + esac + ;; - (arg2) - case $words[2] in - (report) - case $words[3] in - (day) - compadd $(date +"%Y-%m-%d") + (arg2) + # Command argument 2 + case $words[2] in + (report) + case $words[3] in + (day) + compadd $(date +"%Y-%m-%d") + ;; + (week) + compadd $(date +"%Y-%m-%d") + ;; + (month) + compadd $(date +"%Y-%m-%d") + ;; + esac + ;; + (deadline) + case $words[3] in + (set) + compadd $(timer tasklist) $(date +"%Y-%m-%d") + ;; + (clear) + compadd $(timer deadlist) + ;; + esac + ;; + esac ;; - (week) - compadd $(date +"%Y-%m-%d") - ;; - (month) - compadd $(date +"%Y-%m-%d") - ;; - esac - ;; - (deadline) - case $words[3] in - (set) - compadd $(timer tasklist) $(date +"%Y-%m-%d") - ;; - (clear) - compadd $(timer deadlist) - ;; - esac - ;; - esac - ;; - (arg3) - if [ "$words[2]" = "deadline" ] - then - compadd $(date +"%Y-%m-%d") - fi - ;; - esac + (arg3) + # Command argument 3 + if [ "$words[2]" = "deadline" ] + then + compadd $(date +"%Y-%m-%d") + fi + ;; + esac } _timer "$@"