completion.zsh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # fixme - the load process here seems a bit bizarre
  2. unsetopt menu_complete # do not autoselect the first completion entry
  3. unsetopt flowcontrol
  4. setopt auto_menu # show completion menu on succesive tab press
  5. setopt complete_in_word
  6. setopt always_to_end
  7. WORDCHARS=''
  8. zmodload -i zsh/complist
  9. ## case-insensitive (all),partial-word and then substring completion
  10. if [ "x$CASE_SENSITIVE" = "xtrue" ]; then
  11. zstyle ':completion:*' matcher-list 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
  12. unset CASE_SENSITIVE
  13. else
  14. zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
  15. fi
  16. zstyle ':completion:*' list-colors ''
  17. # should this be in keybindings?
  18. bindkey -M menuselect '^o' accept-and-infer-next-history
  19. zstyle ':completion:*:*:*:*:*' menu select
  20. zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;34=0=01'
  21. zstyle ':completion:*:*:*:*:processes' command "ps -u `whoami` -o pid,user,comm -w -w"
  22. # disable named-directories autocompletion
  23. zstyle ':completion:*:cd:*' tag-order local-directories directory-stack path-directories
  24. cdpath=(.)
  25. # use /etc/hosts and known_hosts for hostname completion
  26. [ -r /etc/ssh/ssh_known_hosts ] && _global_ssh_hosts=(${${${${(f)"$(</etc/ssh/ssh_known_hosts)"}:#[\|]*}%%\ *}%%,*}) || _global_ssh_hosts=()
  27. [ -r ~/.ssh/known_hosts ] && _ssh_hosts=(${${${${(f)"$(<$HOME/.ssh/known_hosts)"}:#[\|]*}%%\ *}%%,*}) || _ssh_hosts=()
  28. [ -r ~/.ssh/config ] && _ssh_config=($(cat ~/.ssh/config | sed -ne 's/Host[=\t ]//p')) || _ssh_config=()
  29. [ -r /etc/hosts ] && : ${(A)_etc_hosts:=${(s: :)${(ps:\t:)${${(f)~~"$(</etc/hosts)"}%%\#*}##[:blank:]#[^[:blank:]]#}}} || _etc_hosts=()
  30. hosts=(
  31. "$_ssh_config[@]"
  32. "$_global_ssh_hosts[@]"
  33. "$_ssh_hosts[@]"
  34. "$_etc_hosts[@]"
  35. "$HOST"
  36. localhost
  37. )
  38. zstyle ':completion:*:hosts' hosts $hosts
  39. zstyle ':completion:*' users off
  40. # Use caching so that commands like apt and dpkg complete are useable
  41. zstyle ':completion::complete:*' use-cache 1
  42. zstyle ':completion::complete:*' cache-path $ZSH/cache/
  43. # Don't complete uninteresting users
  44. zstyle ':completion:*:*:*:users' ignored-patterns \
  45. adm amanda apache avahi beaglidx bin cacti canna clamav daemon \
  46. dbus distcache dovecot fax ftp games gdm gkrellmd gopher \
  47. hacluster haldaemon halt hsqldb ident junkbust ldap lp mail \
  48. mailman mailnull mldonkey mysql nagios \
  49. named netdump news nfsnobody nobody nscd ntp nut nx openvpn \
  50. operator pcap postfix postgres privoxy pulse pvm quagga radvd \
  51. rpc rpcuser rpm shutdown squid sshd sync uucp vcsa xfs
  52. # ... unless we really want to.
  53. zstyle '*' single-ignored show
  54. if [ "x$COMPLETION_WAITING_DOTS" = "xtrue" ]; then
  55. expand-or-complete-with-dots() {
  56. echo -n "\e[31m......\e[0m"
  57. zle expand-or-complete
  58. zle redisplay
  59. }
  60. zle -N expand-or-complete-with-dots
  61. bindkey "^I" expand-or-complete-with-dots
  62. fi