1#autoload 2 3# This tries to automatically find the rgb.txt color database. If this 4# in an unusual place on your system or you want a personal database, 5# you can use the configuration key: 6# 7# colors_path 8# Path to a file containing the names of colors you want to 9# complete. In the form of a X11 rgb.txt file. 10 11local expl 12 13if (( ! $+_color_cache )); then 14 local file 15 16 # Cache of color names doesn't exist yet, create it. 17 18 zstyle -s ":completion:${curcontext}:colors" path file 19 if [[ -n "$file" ]]; then 20 _color_cache=( "${(@)${(@f)$(< $file)}[2,-1]##* }" ) 21 else 22 file=( /usr/{lib,{{X11R6,openwin},local{,/X11{,R6}}}/lib}/X11/rgb.txt(N) ) 23 24 (( $#file )) && 25 _color_cache=( "${(@)${(@)${(@f)$(< $file[1])}[2,-1]##* }:#* *}" ) 26 fi 27 28 # Stupid default value. 29 30 (( $#_color_cache )) || _color_cache=(white black gray red blue green) 31fi 32 33_wanted colors expl 'color specification' compadd "$@" -M \ 34 'm:{a-z}={A-Z} m:-=\ r:[^ A-Z0-9]||[ A-Z0-9]=* r:|=*' -a - _color_cache 35