Skip to content

Commit 9ccecfd

Browse files
committed
zsh: Finished completion and input modules
1 parent 0b68b7d commit 9ccecfd

File tree

2 files changed

+149
-6
lines changed

2 files changed

+149
-6
lines changed

.zsh/modules/completion/completion.zsh

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,81 @@ setopt case_glob case_match
2828
setopt extended_glob
2929
setopt glob_star_short
3030

31-
# When Tab-completing a pattern, all matches are placed into a completion menu
32-
# instead of being inserted into the current command line
33-
#setopt glob_complete
34-
3531
### zstyles - Fine tune completion
3632

33+
# General Completer settings
34+
zstyle ':completion:*' completer _extensions _expand _complete _ignored _match _approximate
35+
zstyle ':completion:predict:*' completer _complete
36+
zstyle ':completion::approximate:*' max-errors 3 numeric
37+
zstyle ':completion::(match|approximate):*' insert-unambiguous true
38+
zstyle ':completion::expand:*' accept-exact true
39+
zstyle ':completion::expand:*' add-space file subst
40+
zstyle ':completion::expand:*' group-name ''
41+
zstyle ':completion::expand:*' group-order all-expansions expansions original
3742
zstyle ':completion:*:*:*:*:*' menu select
38-
zstyle ':completion:*:options' description yes
43+
zstyle ':completion:*:*:*:*:*' single-ignored menu
44+
zstyle ':completion::complete:*' use-cache true
45+
46+
# Matcher - Case insensitive, then partial-word completion, then substring
47+
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
48+
49+
# Formatting
50+
zstyle ':completion:*:options' description true
3951
zstyle ':completion:*:options' auto-description '%d'
52+
zstyle ':completion:*' list-separator '|'
53+
zstyle ':completion:*' format ' %F{green}> > %d%f'
54+
zstyle ':completion:*:messages' format ' %F{magenta}> > %d%f'
55+
zstyle ':completion:*:warnings' format ' %F{red}> > no matches found!%f'
56+
zstyle ':completion:*:(approximate|correct)' format ' %F{yellow}> > %d for %B%o%b (errors: %e)%f'
57+
zstyle ':completion:*:*expansions' format ' %F{cyan}> > %d for %B%o%b%f'
58+
zstyle ':completion:*:default' list-prompt '%S%m matches | line %l | %p%s'
59+
zstyle ':completion:*:default' select-prompt '%S%m matches | line %l | %p%s'
60+
61+
# Ignored Patterns
62+
zstyle ':completion:*:*:(^rm):*:*files' ignored-patterns '*?.o' '*?.zwc' 'tags'
63+
zstyle ':completion:*:functions' ignored-patterns '_*'
64+
zstyle ':completion:*:users' ignored-patterns avahi bin colord daemon dbus ftp git 'gpm(-root)?' http mail nobody polkitd sshd 'systemd-*' uuidd
65+
66+
# Ignore duplicate elements
67+
zstyle ':completion:*:(rm|kill|*diff):*' ignore-line other
68+
69+
# Behavior
70+
# Group builtins with external commands to condense
71+
zstyle ':completion:*:*:-command-:*:*' group-name ''
72+
zstyle ':completion:*:*:-command-:*:builtins' group-name 'commands'
73+
zstyle ':completion:*:*:-command-:*:*' group-order functions aliases commands
74+
75+
# Only complete parameters we're completing at a $ in a subscript
76+
zstyle ':completion:*:*:-subscript-:*' tag-order indexes parameters
77+
78+
# Directories
79+
zstyle ':completion:*' ignore-parents parent pwd
80+
zstyle ':completion:*' squeeze-slashes true
81+
zstyle ':completion:*:*:cd:*' tag-order local-directories directory-stack path-directories
82+
zstyle ':completion:*:*:-tilde-:*' group-name ''
83+
zstyle ':completion:*:*:-tilde-:*' group-order users named-directories
84+
zstyle ':completion:*:*:-tilde-:*' tag-order 'users named-directories'
85+
86+
# Use menu selection when the list of matches fits on screen, otherwise use
87+
# menu completion to prevent scrolling
88+
zstyle ':completion:*:*:cd:*:directory-stack' menu true=long select
89+
90+
# Processes
91+
zstyle ':completion:*:*:kill:*' group-name ''
92+
zstyle ':completion:*:*:kill:*' group-order processes process-groups
93+
zstyle ':completion:*:*:kill:*' tag-order 'processes process-groups'
94+
zstyle ':completion:*:jobs' list-colors 'no=34'
95+
zstyle ':completion:*:processes' list-colors "=* $USER *=32"
96+
zstyle ':completion:*:processes' command "ps -e"
97+
zstyle ':completion:*:*:kill:*:processes' command "ps -u $USER"
98+
99+
# History
100+
zstyle ':completion:history-words:*' stop true
101+
zstyle ':completion:history-words:*' list false
102+
zstyle ':completion:history-words:*' remove-all-dups true
103+
104+
# Man Pages
105+
zstyle ':completion:*:manuals.*' group-name ''
106+
zstyle ':completion:*:manuals' separate-sections true
107+
zstyle ':completion:*:manuals.(^1*)' insert-sections true
40108

.zsh/modules/input/input.zsh

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,75 @@
22
# Input settings and keybinds
33
#
44

5+
# Human-friendly key names
6+
zmodload zsh/terminfo
7+
typeset -gA zsh_key_info
8+
zsh_key_info=(
9+
'Control' '\C-'
10+
'ControlLeft' '\e[1;5D \e[5D \e\e[D \eOd \eOD'
11+
'ControlRight' '\e[1;5C \e[5C \e\e[C \eOc \eOC'
12+
'Escape' '\e'
13+
'Meta' '\M-'
14+
'Backspace' "^?"
15+
'Delete' "^[[3~"
16+
'F1' "${terminfo[kf1]}"
17+
'F2' "${terminfo[kf2]}"
18+
'F3' "${terminfo[kf3]}"
19+
'F4' "${terminfo[kf4]}"
20+
'F5' "${terminfo[kf5]}"
21+
'F6' "${terminfo[kf6]}"
22+
'F7' "${terminfo[kf7]}"
23+
'F8' "${terminfo[kf8]}"
24+
'F9' "${terminfo[kf9]}"
25+
'F10' "${terminfo[kf10]}"
26+
'F11' "${terminfo[kf11]}"
27+
'F12' "${terminfo[kf12]}"
28+
'Insert' "${terminfo[kich1]}"
29+
'Home' "${terminfo[khome]}"
30+
'PageUp' "${terminfo[kpp]}"
31+
'End' "${terminfo[kend]}"
32+
'PageDown' "${terminfo[knp]}"
33+
'Up' "${terminfo[kcuu1]}"
34+
'Left' "${terminfo[kcub1]}"
35+
'Down' "${terminfo[kcud1]}"
36+
'Right' "${terminfo[kcuf1]}"
37+
'BackTab' "${terminfo[kcbt]}"
38+
)
39+
540
# Set Vi-keys
641
bindkey -v
742

43+
# Some basics
44+
bindkey "$zsh_key_info[Delete]" delete-char
45+
bindkey "$zsh_key_info[Home]" beginning-of-line
46+
bindkey "$zsh_key_info[End]" end-of-line
47+
bindkey '^Z' undo
48+
49+
# Shift+Tab to go backward in menu completion
50+
bindkey "$zsh_key_info[BackTab]" reverse-menu-complete
51+
52+
# Edit command line in $EDITOR
53+
autoload -U edit-command-line
54+
zle -N edit-command-line
55+
bindkey -a 'q:' edit-command-line
56+
57+
# Buffer stack
58+
bindkey '^Q' push-line-or-edit
59+
bindkey -a '^Q' push-line-or-edit
60+
61+
# Automatic History Expansion
62+
#bindkey ' ' magic-space
63+
64+
# Enable Prediction
65+
autoload -U predict-on
66+
zle -N predict-on
67+
zle -N predict-off
68+
bindkey '^Xp' predict-on
69+
bindkey '^XP' predict-off
70+
71+
# Go straight to menu completion if we hit <Tab> again with list-prompt
72+
bindkey -M listscroll '^I' 'send-break; self-insert'
73+
874
# Very elegant trick from Zim
975
double-dot-expand() {
1076
if [[ ${LBUFFER} == *.. ]]; then
@@ -14,7 +80,16 @@ double-dot-expand() {
1480
fi
1581
}
1682
zle -N double-dot-expand
17-
bindkey "." double-dot-expand
83+
bindkey '.' double-dot-expand
84+
85+
# Busy-indicator for completion
86+
complete-word-with-indicator() {
87+
print -Pn " %{%F{magenta}\u231B%f%}"
88+
zle complete-word
89+
zle redisplay
90+
}
91+
zle -N complete-word-with-indicator
92+
bindkey '^I' complete-word-with-indicator
1893

1994
### Options
2095

0 commit comments

Comments
 (0)