Skip to content

Commit

Permalink
zsh: Finished completion and input modules
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeroKnight committed Oct 24, 2016
1 parent 0b68b7d commit 9ccecfd
Show file tree
Hide file tree
Showing 2 changed files with 149 additions and 6 deletions.
78 changes: 73 additions & 5 deletions .zsh/modules/completion/completion.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,81 @@ setopt case_glob case_match
setopt extended_glob
setopt glob_star_short

# When Tab-completing a pattern, all matches are placed into a completion menu
# instead of being inserted into the current command line
#setopt glob_complete

### zstyles - Fine tune completion

# General Completer settings
zstyle ':completion:*' completer _extensions _expand _complete _ignored _match _approximate
zstyle ':completion:predict:*' completer _complete
zstyle ':completion::approximate:*' max-errors 3 numeric
zstyle ':completion::(match|approximate):*' insert-unambiguous true
zstyle ':completion::expand:*' accept-exact true
zstyle ':completion::expand:*' add-space file subst
zstyle ':completion::expand:*' group-name ''
zstyle ':completion::expand:*' group-order all-expansions expansions original
zstyle ':completion:*:*:*:*:*' menu select
zstyle ':completion:*:options' description yes
zstyle ':completion:*:*:*:*:*' single-ignored menu
zstyle ':completion::complete:*' use-cache true

# Matcher - Case insensitive, then partial-word completion, then substring
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'

# Formatting
zstyle ':completion:*:options' description true
zstyle ':completion:*:options' auto-description '%d'
zstyle ':completion:*' list-separator '|'
zstyle ':completion:*' format ' %F{green}> > %d%f'
zstyle ':completion:*:messages' format ' %F{magenta}> > %d%f'
zstyle ':completion:*:warnings' format ' %F{red}> > no matches found!%f'
zstyle ':completion:*:(approximate|correct)' format ' %F{yellow}> > %d for %B%o%b (errors: %e)%f'
zstyle ':completion:*:*expansions' format ' %F{cyan}> > %d for %B%o%b%f'
zstyle ':completion:*:default' list-prompt '%S%m matches | line %l | %p%s'
zstyle ':completion:*:default' select-prompt '%S%m matches | line %l | %p%s'

# Ignored Patterns
zstyle ':completion:*:*:(^rm):*:*files' ignored-patterns '*?.o' '*?.zwc' 'tags'
zstyle ':completion:*:functions' ignored-patterns '_*'
zstyle ':completion:*:users' ignored-patterns avahi bin colord daemon dbus ftp git 'gpm(-root)?' http mail nobody polkitd sshd 'systemd-*' uuidd

# Ignore duplicate elements
zstyle ':completion:*:(rm|kill|*diff):*' ignore-line other

# Behavior
# Group builtins with external commands to condense
zstyle ':completion:*:*:-command-:*:*' group-name ''
zstyle ':completion:*:*:-command-:*:builtins' group-name 'commands'
zstyle ':completion:*:*:-command-:*:*' group-order functions aliases commands

# Only complete parameters we're completing at a $ in a subscript
zstyle ':completion:*:*:-subscript-:*' tag-order indexes parameters

# Directories
zstyle ':completion:*' ignore-parents parent pwd
zstyle ':completion:*' squeeze-slashes true
zstyle ':completion:*:*:cd:*' tag-order local-directories directory-stack path-directories
zstyle ':completion:*:*:-tilde-:*' group-name ''
zstyle ':completion:*:*:-tilde-:*' group-order users named-directories
zstyle ':completion:*:*:-tilde-:*' tag-order 'users named-directories'

# Use menu selection when the list of matches fits on screen, otherwise use
# menu completion to prevent scrolling
zstyle ':completion:*:*:cd:*:directory-stack' menu true=long select

# Processes
zstyle ':completion:*:*:kill:*' group-name ''
zstyle ':completion:*:*:kill:*' group-order processes process-groups
zstyle ':completion:*:*:kill:*' tag-order 'processes process-groups'
zstyle ':completion:*:jobs' list-colors 'no=34'
zstyle ':completion:*:processes' list-colors "=* $USER *=32"
zstyle ':completion:*:processes' command "ps -e"
zstyle ':completion:*:*:kill:*:processes' command "ps -u $USER"

# History
zstyle ':completion:history-words:*' stop true
zstyle ':completion:history-words:*' list false
zstyle ':completion:history-words:*' remove-all-dups true

# Man Pages
zstyle ':completion:*:manuals.*' group-name ''
zstyle ':completion:*:manuals' separate-sections true
zstyle ':completion:*:manuals.(^1*)' insert-sections true

77 changes: 76 additions & 1 deletion .zsh/modules/input/input.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,75 @@
# Input settings and keybinds
#

# Human-friendly key names
zmodload zsh/terminfo
typeset -gA zsh_key_info
zsh_key_info=(
'Control' '\C-'
'ControlLeft' '\e[1;5D \e[5D \e\e[D \eOd \eOD'
'ControlRight' '\e[1;5C \e[5C \e\e[C \eOc \eOC'
'Escape' '\e'
'Meta' '\M-'
'Backspace' "^?"
'Delete' "^[[3~"
'F1' "${terminfo[kf1]}"
'F2' "${terminfo[kf2]}"
'F3' "${terminfo[kf3]}"
'F4' "${terminfo[kf4]}"
'F5' "${terminfo[kf5]}"
'F6' "${terminfo[kf6]}"
'F7' "${terminfo[kf7]}"
'F8' "${terminfo[kf8]}"
'F9' "${terminfo[kf9]}"
'F10' "${terminfo[kf10]}"
'F11' "${terminfo[kf11]}"
'F12' "${terminfo[kf12]}"
'Insert' "${terminfo[kich1]}"
'Home' "${terminfo[khome]}"
'PageUp' "${terminfo[kpp]}"
'End' "${terminfo[kend]}"
'PageDown' "${terminfo[knp]}"
'Up' "${terminfo[kcuu1]}"
'Left' "${terminfo[kcub1]}"
'Down' "${terminfo[kcud1]}"
'Right' "${terminfo[kcuf1]}"
'BackTab' "${terminfo[kcbt]}"
)

# Set Vi-keys
bindkey -v

# Some basics
bindkey "$zsh_key_info[Delete]" delete-char
bindkey "$zsh_key_info[Home]" beginning-of-line
bindkey "$zsh_key_info[End]" end-of-line
bindkey '^Z' undo

# Shift+Tab to go backward in menu completion
bindkey "$zsh_key_info[BackTab]" reverse-menu-complete

# Edit command line in $EDITOR
autoload -U edit-command-line
zle -N edit-command-line
bindkey -a 'q:' edit-command-line

# Buffer stack
bindkey '^Q' push-line-or-edit
bindkey -a '^Q' push-line-or-edit

# Automatic History Expansion
#bindkey ' ' magic-space

# Enable Prediction
autoload -U predict-on
zle -N predict-on
zle -N predict-off
bindkey '^Xp' predict-on
bindkey '^XP' predict-off

# Go straight to menu completion if we hit <Tab> again with list-prompt
bindkey -M listscroll '^I' 'send-break; self-insert'

# Very elegant trick from Zim
double-dot-expand() {
if [[ ${LBUFFER} == *.. ]]; then
Expand All @@ -14,7 +80,16 @@ double-dot-expand() {
fi
}
zle -N double-dot-expand
bindkey "." double-dot-expand
bindkey '.' double-dot-expand

# Busy-indicator for completion
complete-word-with-indicator() {
print -Pn " %{%F{magenta}\u231B%f%}"
zle complete-word
zle redisplay
}
zle -N complete-word-with-indicator
bindkey '^I' complete-word-with-indicator

### Options

Expand Down

0 comments on commit 9ccecfd

Please sign in to comment.