1 # This is a function to dump the definitions for new-style
2 # completion defined by 'compinit' in the same directory. The output
3 # should be directed into the "compinit.dump" in the same directory as
4 # compinit. If you rename init, just stick .dump onto the end of whatever
5 # you have called it and put it in the same directory. This is handled
6 # automatically if you invoke compinit with the option -d.
8 # You will need to update the dump every time you add a new completion.
9 # To do this, simply remove the .dump file, start a new shell, and
10 # create the .dump file as before. Again, compinit -d handles this
13 # Print the number of files used for completion. This is used in compinit
14 # to see if auto-dump should re-dump the dump-file.
17 setopt extendedglob noshglob
19 typeset _d_file _d_f _d_bks _d_line _d_als _d_files _d_name _d_tmp
21 _d_file=${_comp_dumpfile-${0:h}/compinit.dump}.$HOST.$$
22 [[ $_d_file = //* ]] && _d_file=${_d_file[2,-1]}
24 [[ -w ${_d_file:h} ]] || return 1
26 _d_files=( ${^~fpath:/.}/^([^_]*|*~|*.zwc)(N) )
28 if [[ -n "$_comp_secure" ]]; then
29 _d_wdirs=( ${^fpath}(Nf:g+w:,f:o+w:,^u0u${EUID}) )
30 _d_wfiles=( ${^~fpath:/.}/^([^_]*|*~|*.zwc)(N^u0u${EUID}) )
32 (( $#_d_wfiles )) && _d_files=( "${(@)_d_files:#(${(j:|:)_d_wfiles})}" )
33 (( $#_d_wdirs )) && _d_files=( "${(@)_d_files:#(${(j:|:)_d_wdirs})/*}" )
36 print "#files: $#_d_files\tversion: $ZSH_VERSION" > $_d_file
38 # Dump the arrays _comps, _services and _patcomps. The quoting
39 # hieroglyphics ensure that a single quote inside a variable is itself
42 print "\n_comps=(" >> $_d_file
43 for _d_f in ${(ok)_comps}; do
44 print -r - "${(qq)_d_f}" "${(qq)_comps[$_d_f]}"
48 print "\n_services=(" >> $_d_file
49 for _d_f in ${(ok)_services}; do
50 print -r - "${(qq)_d_f}" "${(qq)_services[$_d_f]}"
54 print "\n_patcomps=(" >> $_d_file
55 for _d_f in ${(ok)_patcomps}; do
56 print -r - "${(qq)_d_f}" "${(qq)_patcomps[$_d_f]}"
60 _d_tmp="_postpatcomps"
61 print "\n_postpatcomps=(" >> $_d_file
62 for _d_f in ${(ok)_postpatcomps}; do
63 print -r - "${(qq)_d_f}" "${(qq)_postpatcomps[$_d_f]}"
67 print "\n_compautos=(" >> $_d_file
68 for _d_f in "${(ok@)_compautos}"; do
69 print -r - "${(qq)_d_f}" "${(qq)_compautos[$_d_f]}"
75 # Now dump the key bindings. We dump all bindings for zle widgets
76 # whose names start with a underscore.
77 # We need both the zle -C's and the bindkey's to recreate.
78 # We can ignore any zle -C which rebinds a standard widget (second
79 # argument to zle does not begin with a `_').
84 while read -rA _d_line; do
85 if [[ ${_d_line[3]} = _* && ${_d_line[5]} = _* ]]; then
86 if [[ -z "$_d_complist" && ${_d_line[4]} = .menu-select ]]; then
87 print 'zmodload -i zsh/complist'
91 _d_bks+=(${_d_line[3]})
95 while read -rA _d_line; do
96 if [[ ${_d_line[2]} = (${(j.|.)~_d_bks}) ]]; then
97 print -r "bindkey '${_d_line[1][2,-2]}' ${_d_line[2]}"
104 # Autoloads: look for all functions beginning with `_'.
106 _d_als=(${(o)$(typeset +fm '_*')})
108 # print them out: about five to a line looks neat
111 print -n autoload -Uz >> $_d_file
112 while (( $#_d_als )); do
113 if (( ! $+_compautos[$_d_als[1]] )); then
114 print -n " $_d_als[1]"
115 if (( ! --_i && $#_d_als > 1 )); then
126 for _c in "${(ok@)_compautos}"; do
127 print "autoload -Uz $_compautos[$_c] $_c" >> $_d_file
132 print "typeset -gUa _comp_assocs" >> $_d_file
133 print "_comp_assocs=( ${(qq)_comp_assocs} )" >> $_d_file
135 mv -f $_d_file ${_d_file%.$HOST.$$}
138 autoload -Uz compdump