107 lines
3.8 KiB
Bash
107 lines
3.8 KiB
Bash
# ===== init completion
|
|
autoload -Uz compinit && compinit -d ~/.zsh/cache/zcompdump
|
|
zmodload -i zsh/complist
|
|
|
|
# ===== setopts
|
|
# allow completion from within a word or phrase
|
|
setopt complete_in_word
|
|
# always complete and display matches immediately after pressing <Tab>
|
|
setopt no_list_ambiguous
|
|
# when completing from the middle of a word, move the cursor to the end.
|
|
setopt always_to_end
|
|
# always show completion menu on successive tab press.
|
|
# (needs unsetopt menu_complete to work)
|
|
setopt auto_menu
|
|
# do not autoselect the first completion entry
|
|
unsetopt menu_complete
|
|
|
|
# ===== completion options
|
|
# Enable completion caching, use rehash to clear
|
|
zstyle ':completion:*' use-cache on
|
|
zstyle ':completion:*' cache-path ~/.zsh/cache
|
|
|
|
# List all files in the current directory when pressing tab on a empty input,
|
|
# behave like complete-word otherwise.
|
|
complete-word-or-complete-list-of-files() {
|
|
if [[ $#BUFFER == 0 ]]; then
|
|
BUFFER='ls '
|
|
CURSOR=3
|
|
zle list-choices
|
|
zle backward-kill-word
|
|
else
|
|
zle complete-word
|
|
fi
|
|
}
|
|
zle -N complete-word-or-complete-list-of-files
|
|
bindkey '^I' complete-word-or-complete-list-of-files
|
|
|
|
# Force a reload of the completion system if nothing matched; this fixes
|
|
# installing a program and then trying to tab-completing its name.
|
|
_force_rehash() {
|
|
if (( CURRENT == 1 )); then
|
|
rehash
|
|
fi
|
|
# we didn't really complete anything.
|
|
return 1
|
|
}
|
|
|
|
# list of completers to use
|
|
zstyle ':completion:::::' completer \
|
|
_force_rehash _expand _complete _prefix _ignored _approximate
|
|
#TODO: keep _prefix or not?
|
|
|
|
# ignore case when trying to match typed characters
|
|
zstyle ':completion:*:(^approximate):*' matcher-list 'm:{a-z}={A-Z}'
|
|
|
|
# allow one mistake per three characters
|
|
zstyle -e ':completion:*:approximate:*' max-errors \
|
|
'reply=( $(( ($#PREFIX + $#SUFFIX) / 3 )) )'
|
|
|
|
# ===== completion appearance
|
|
# use ls colors for completion
|
|
zstyle ':completion:*' list-colors "${(@s.:.)LS_COLORS}"
|
|
|
|
# Make the list prompt friendly
|
|
zstyle ':completion:*:default' list-prompt '%SAt %p: Hit <TAB> for more, or the character to insert%s'
|
|
# Make the selection prompt friendly when there are a lot of choices
|
|
zstyle ':completion:*:default' select-prompt '%SScrolling active: current selection at %p%s'
|
|
|
|
# Display group (category) name (%d) (like 'external command', 'alias', etc.) in
|
|
# bold. Also display a message if _approximate found errors and no matches
|
|
# were found.
|
|
zstyle ':completion:*' format ' %B%d%b:'
|
|
zstyle ':completion:*:corrections' format ' %B%d%b (errors: %e)'
|
|
zstyle ':completion:*:warnings' format ' %BNo matches for: %d%b'
|
|
|
|
# display matches sorted into categories
|
|
zstyle ':completion:*' group-name ''
|
|
|
|
# always show menu and preselect the first option
|
|
zstyle ':completion:*' menu select=1 _complete _ignored _approximate
|
|
#TODO: keep?
|
|
|
|
# make completion functions use the verbose style and form
|
|
#zstyle ':completion:*' verbose yes
|
|
|
|
# ===== completion commands
|
|
# Add simple colors to kill
|
|
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;34=0=01'
|
|
|
|
# insert all expansions for expand completer
|
|
# zstyle ':completion:*:expand:*' tag-order all-expansions
|
|
|
|
# offer indexes before parameters in subscripts
|
|
zstyle ':completion:*:*:-subscript-:*' tag-order indexes parameters
|
|
|
|
# ignore completion functions (until the _ignored completer)
|
|
zstyle ':completion:*:functions' ignored-patterns '_*'
|
|
zstyle ':completion:*:scp:*' tag-order files users 'hosts:-host hosts:-domain:domain hosts:-ipaddr"IP\ Address *'
|
|
zstyle ':completion:*:scp:*' group-order files all-files users hosts-domain hosts-host hosts-ipaddr
|
|
zstyle ':completion:*:ssh:*' tag-order users 'hosts:-host hosts:-domain:domain hosts:-ipaddr"IP\ Address *'
|
|
zstyle ':completion:*:ssh:*' group-order hosts-domain hosts-host users hosts-ipaddr
|
|
zstyle '*' single-ignored show
|
|
|
|
# apt-get recommendations
|
|
#if [[ $HAS_APT -eq 1 ]]; then
|
|
# source /etc/zsh_command_not_found
|
|
#fi
|