diff options
| author | Hsieh Chin Fan <pham@topo.tw> | 2023-02-09 13:40:10 +0800 |
|---|---|---|
| committer | Hsieh Chin Fan <pham@topo.tw> | 2023-02-09 14:26:46 +0800 |
| commit | a59bce4ea2ea26bdb57765d0b83e92d73096d6b1 (patch) | |
| tree | cb0bb0e1b023f5b1a498791e7a8f375b4c98527c | |
| parent | cda2dc0913dd77d91249afbe5f136f752f9bd7e4 (diff) | |
Apply zsh completion from on-my-zsh
| -rw-r--r-- | zsh/completion.zsh | 78 | ||||
| -rw-r--r-- | zsh/zshrc | 5 |
2 files changed, 81 insertions, 2 deletions
diff --git a/zsh/completion.zsh b/zsh/completion.zsh new file mode 100644 index 0000000..2c56954 --- /dev/null +++ b/zsh/completion.zsh | |||
| @@ -0,0 +1,78 @@ | |||
| 1 | # fixme - the load process here seems a bit bizarre | ||
| 2 | zmodload -i zsh/complist | ||
| 3 | |||
| 4 | WORDCHARS='' | ||
| 5 | |||
| 6 | unsetopt menu_complete # do not autoselect the first completion entry | ||
| 7 | unsetopt flowcontrol | ||
| 8 | setopt auto_menu # show completion menu on successive tab press | ||
| 9 | setopt complete_in_word | ||
| 10 | setopt always_to_end | ||
| 11 | |||
| 12 | # should this be in keybindings? | ||
| 13 | bindkey -M menuselect '^o' accept-and-infer-next-history | ||
| 14 | zstyle ':completion:*:*:*:*:*' menu select | ||
| 15 | |||
| 16 | # case insensitive (all), partial-word and substring completion | ||
| 17 | if [[ "$CASE_SENSITIVE" = true ]]; then | ||
| 18 | zstyle ':completion:*' matcher-list 'r:|=*' 'l:|=* r:|=*' | ||
| 19 | else | ||
| 20 | if [[ "$HYPHEN_INSENSITIVE" = true ]]; then | ||
| 21 | zstyle ':completion:*' matcher-list 'm:{a-zA-Z-_}={A-Za-z_-}' 'r:|=*' 'l:|=* r:|=*' | ||
| 22 | else | ||
| 23 | zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|=*' 'l:|=* r:|=*' | ||
| 24 | fi | ||
| 25 | fi | ||
| 26 | unset CASE_SENSITIVE HYPHEN_INSENSITIVE | ||
| 27 | |||
| 28 | # Complete . and .. special directories | ||
| 29 | zstyle ':completion:*' special-dirs true | ||
| 30 | |||
| 31 | zstyle ':completion:*' list-colors '' | ||
| 32 | zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;34=0=01' | ||
| 33 | |||
| 34 | if [[ "$OSTYPE" = solaris* ]]; then | ||
| 35 | zstyle ':completion:*:*:*:*:processes' command "ps -u $USERNAME -o pid,user,comm" | ||
| 36 | else | ||
| 37 | zstyle ':completion:*:*:*:*:processes' command "ps -u $USERNAME -o pid,user,comm -w -w" | ||
| 38 | fi | ||
| 39 | |||
| 40 | # disable named-directories autocompletion | ||
| 41 | zstyle ':completion:*:cd:*' tag-order local-directories directory-stack path-directories | ||
| 42 | |||
| 43 | # Use caching so that commands like apt and dpkg complete are useable | ||
| 44 | zstyle ':completion:*' use-cache yes | ||
| 45 | zstyle ':completion:*' cache-path $ZSH_CACHE_DIR | ||
| 46 | |||
| 47 | # Don't complete uninteresting users | ||
| 48 | zstyle ':completion:*:*:*:users' ignored-patterns \ | ||
| 49 | adm amanda apache at avahi avahi-autoipd beaglidx bin cacti canna \ | ||
| 50 | clamav daemon dbus distcache dnsmasq dovecot fax ftp games gdm \ | ||
| 51 | gkrellmd gopher hacluster haldaemon halt hsqldb ident junkbust kdm \ | ||
| 52 | ldap lp mail mailman mailnull man messagebus mldonkey mysql nagios \ | ||
| 53 | named netdump news nfsnobody nobody nscd ntp nut nx obsrun openvpn \ | ||
| 54 | operator pcap polkitd postfix postgres privoxy pulse pvm quagga radvd \ | ||
| 55 | rpc rpcuser rpm rtkit scard shutdown squid sshd statd svn sync tftp \ | ||
| 56 | usbmux uucp vcsa wwwrun xfs '_*' | ||
| 57 | |||
| 58 | # ... unless we really want to. | ||
| 59 | zstyle '*' single-ignored show | ||
| 60 | |||
| 61 | if [[ ${COMPLETION_WAITING_DOTS:-false} != false ]]; then | ||
| 62 | expand-or-complete-with-dots() { | ||
| 63 | # use $COMPLETION_WAITING_DOTS either as toggle or as the sequence to show | ||
| 64 | [[ $COMPLETION_WAITING_DOTS = true ]] && COMPLETION_WAITING_DOTS="%F{red}…%f" | ||
| 65 | # turn off line wrapping and print prompt-expanded "dot" sequence | ||
| 66 | printf '\e[?7l%s\e[?7h' "${(%)COMPLETION_WAITING_DOTS}" | ||
| 67 | zle expand-or-complete | ||
| 68 | zle redisplay | ||
| 69 | } | ||
| 70 | zle -N expand-or-complete-with-dots | ||
| 71 | # Set the function as the default tab completion widget | ||
| 72 | bindkey -M emacs "^I" expand-or-complete-with-dots | ||
| 73 | bindkey -M viins "^I" expand-or-complete-with-dots | ||
| 74 | bindkey -M vicmd "^I" expand-or-complete-with-dots | ||
| 75 | fi | ||
| 76 | |||
| 77 | # automatically load bash completion functions | ||
| 78 | autoload -U +X bashcompinit && bashcompinit | ||
| @@ -3,11 +3,12 @@ set -o emacs | |||
| 3 | 3 | ||
| 4 | # helper repo | 4 | # helper repo |
| 5 | export SETTING_DIR=$HOME/helper | 5 | export SETTING_DIR=$HOME/helper |
| 6 | source $SETTING_DIR/tools/init/load-settings.sh | ||
| 7 | fpath=($SETTING_DIR/zsh $fpath) | 6 | fpath=($SETTING_DIR/zsh $fpath) |
| 7 | source $SETTING_DIR/zsh/completion.zsh | ||
| 8 | source $SETTING_DIR/tools/init/load-settings.sh | ||
| 8 | 9 | ||
| 9 | # Reload zshrc | 10 | # Reload zshrc |
| 10 | alias .="source $0" | 11 | alias .="source $ZDOTDIR/.zshrc" |
| 11 | 12 | ||
| 12 | # Options | 13 | # Options |
| 13 | setopt extended_glob | 14 | setopt extended_glob |