diff options
Diffstat (limited to 'Completion')
-rw-r--r-- | Completion/Zsh/Context/.distfiles | 19 | ||||
-rw-r--r-- | Completion/Zsh/Context/_zcalc_line | 83 |
2 files changed, 98 insertions, 4 deletions
diff --git a/Completion/Zsh/Context/.distfiles b/Completion/Zsh/Context/.distfiles index 59777c30d..8b4acfc7a 100644 --- a/Completion/Zsh/Context/.distfiles +++ b/Completion/Zsh/Context/.distfiles @@ -1,7 +1,18 @@ DISTFILES_SRC=' .distfiles -_assign _autocd -_brace_parameter _equal _math _subscript -_condition _first _parameter _tilde -_default _in_vared _redirect _value +_assign +_autocd +_brace_parameter +_condition +_default +_equal +_first +_in_vared +_math +_parameter +_redirect +_subscript +_tilde +_value +_zcalc_line ' diff --git a/Completion/Zsh/Context/_zcalc_line b/Completion/Zsh/Context/_zcalc_line new file mode 100644 index 000000000..6ce3d82bf --- /dev/null +++ b/Completion/Zsh/Context/_zcalc_line @@ -0,0 +1,83 @@ +#compdef -zcalc-line- + +# This handles completion of a zcalc command line read via vared. + +_zcalc_line_escapes() { + local -a cmds + cmds=( + "!:shell escape" + "q:quit" + "norm:normal output format" + "sci:scientific output format" + "fix:fixed point output format" + "eng:engineering (power of 1000) output format" + "raw:raw output format" + "local:make variables local" + "function:define math function" + ) + cmds=("\:"${^cmds}) + _describe -t command-escapes "command escapes" cmds -Q +} + +_zcalc_line() { + local expl + + if [[ CURRENT -eq 1 && $words[1] != ":!"* ]]; then + local -a alts + if [[ $words[1] = (|:*) ]]; then + alts=("command-escapes:command escape:_zcalc_line_escapes") + fi + if [[ $words[1] = (|[^:]*) ]]; then + alts+=("math:math formula:_math") + fi + _alternative $alts + return + fi + + case $words[1] in + (":!"*) + if [[ $words[1] = ":!" ]]; then + shift words + (( CURRENT >1 && CURRENT-- )) + else + words[1]=${words[1]##:\!} + if (( CURRENT == 1 )); then + compset -P ":\!" + fi + fi + _normal + ;; + + (:function) + # completing already defined user math functions is in fact exactly + # the wrong thing to do since currently zmathfuncdef won't overwrite, + # but it may jog the user's memory... + if (( CURRENT == 2 )); then + _wanted math-functions expl 'math function' \ + compadd -- ${${(k)functions:#^zsh_math_func_*}##zsh_math_func_} + else + _math + fi + ;; + + (:local) + _parameter + ;; + + (:(fix|sci|eng)) + if (( CURRENT == 2 )); then + _message "precision" + fi + ;& + + (:*) + _message "no more arguments" + ;; + + ([^:]*) + _math + ;; + esac +} + +_zcalc_line "$@" |