1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
|
eval "$(starship init zsh)"
# Include custom aliases/functions
source "$HOME/.dotfiles/includes"
install_zplug() {
curl -sL --proto-redir -all,https https://raw.githubusercontent.com/zplug/installer/master/installer.zsh | zsh
}
rm_zplug() {
rm -rf ~/.zplug
}
# Zplug settings
# https://github.com/zplug/zplug
source ~/.zplug/init.zsh
# https://www.github.com/zsh-users/zsh-syntax-highlighting
# Fish shell-like syntax highlighting for Zsh.
zplug "zsh-users/zsh-syntax-highlighting"
# You can type the beginning of a command and then use arrow keys to filter
# previous commands in your history that share the same beginning
# https://www.github.com/zsh-users/zsh-history-substring-search
zplug "zsh-users/zsh-history-substring-search"
# https://www.github.com/zsh-users/zsh-autosuggestions
# Fish-like fast/unobtrusive autosuggestions for zsh. When you type a command a
# second time it shows up but is shaded, use the right arrow to fully complete
# the command
zplug "zsh-users/zsh-autosuggestions"
# https://www.github.com/zsh-users/zsh-completions
# Additional completions for common command line tools
zplug "zsh-users/zsh-completions"
# Quick changing directories, z is a command line tool that allows you to jump
# quickly to directories that you have visited frequently in the past, or
# recently
# https://www.github.com/agkozak/zsh-z
zplug "agkozak/zsh-z"
# Install plugins if there are plugins that have not been installed
if ! zplug check --verbose; then
printf "Install? [y/N]: "
if read -q; then
echo; zplug install
fi
fi
# Then, source plugins and add commands to $PATH
# Remove --verbose if you find the startup message annoying
zplug load --verbose
# If you see custom autocomplete files that you want to install, say from
# someones dotfiles, Well create our own autocomplete folder where we can just
# download/curl the files into and then we'll save them.
#
# For instance, what if we just wanted to use the _docker file from this repo
# https://raw.githubusercontent.com/felixr/docker-zsh-completion
install_docker_autocomplete() {
curl -fsSL 'https://raw.githubusercontent.com/felixr/docker-zsh-completion/master/_docker' -o "$HOME/.dotfiles/autocompletes/_docker"
}
rm_docker_autocomplete() {
rm ~/.dotfiles/autocompletes/_docker
}
fpath=($HOME/.dotfiles/autocompletes $fpath)
# Highlight the current autocomplete option
zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"
# Auto-complete will group matches and describe.
zstyle ':completion:*:*:*:*:*' menu select
zstyle ':completion:*:matches' group 'yes'
zstyle ':completion:*:options' description 'yes'
zstyle ':completion:*:options' auto-description '%d'
zstyle ':completion:*:corrections' format ' %F{green}-- %d (errors: %e) --%f'
zstyle ':completion:*:descriptions' format ' %F{yellow}-- %d --%f'
zstyle ':completion:*:messages' format ' %F{purple} -- %d --%f'
zstyle ':completion:*:warnings' format ' %F{red}-- no matches found --%f'
zstyle ':completion:*:default' list-prompt '%S%M matches%s'
zstyle ':completion:*' format ' %F{yellow}-- %d --%f'
zstyle ':completion:*' group-name ''
zstyle ':completion:*' verbose yes
# Simple ssh completion, don't ask how it works
zstyle -e ':completion:*:hosts' hosts 'reply=(
${=${=${=${${(f)"$(cat {/etc/ssh_,~/.ssh/known_}hosts(|2)(N) 2>/dev/null)"}%%[#| ]*}//\]:[0-9]*/ }//,/ }//\[/ }
${=${(f)"$(cat /etc/hosts(|)(N) <<(ypcat hosts 2>/dev/null))"}%%\#*}
${=${${${${(@M)${(f)"$(cat ~/.ssh/config 2>/dev/null)"}:#Host *}#Host }:#*\**}:#*\?*}}
)'
# Allow for autocomplete to be case insensitive
zstyle ':completion:*' matcher-list '' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]}' \
'+l:|?=** r:|?=**'
# Initialize autocompletes for zsh
# Needs to come after the fpath is set
autoload -Uz compinit && compinit -i
# Example of how to assign a custom function the autocompletes of an existing
# function
sls() {
ssh "$1" ls
}
compdef sls=ssh
dex() { # Enter a container
docker exec -it "$1" /bin/bash
}
# Set `dex` to use to autocompletes for `docker_containers`.
# `docker_containers` is not a real function, but zsh will still search for the
# autocomplete file `_docker_containers` on the fpath. Sometimes I use the same
# autocompletes between multiple custom functions so I just make a "general"
# autocompletes and compdef commands to in
compdef dex=docker_containers
# Extra Goodies
# Source additional options if set
if [[ -s "$HOME/.zshrc2" ]]; then
source "$HOME/.zshrc2"
fi
# Set Editor
export EDITOR='nvim'
export VISUAL='nvim'
export PAGER='less -S'
export XDG_CONFIG_HOME="$HOME/.config"
export COOKIECUTTER_CONFIG="$HOME/.config/cookiecutter/config.yml"
# Set the Language, important for NERD Fonts
export LANG=en_US.UTF-8
# Set the default Less options.
# Mouse-wheel scrolling has been disabled by -X (disable screen clearing).
# Remove -X and -F (exit if the content fits on one screen) to enable it.
export LESS='-F -g -i -M -R -S -w -X -z-4'
# Use `bindkey -v` to use vim line editing mode
bindkey -e
export KEYTIMEOUT=1
# FZF find function, ignore pyc files
export FZF_DEFAULT_COMMAND='find * -type f | grep -v ".pyc"'
# Vi mode changes a bunch on the commands that normal bash
# provides so I bind these keys back to their original functions
bindkey '^?' backward-delete-char
bindkey '^w' backward-kill-word
bindkey '^h' backward-delete-char
bindkey '^u' backward-kill-line
bindkey '^r' history-incremental-search-backward
bindkey '^S' history-incremental-search-forward
bindkey '^[[Z' reverse-menu-complete
bindkey -M viins '\C-A' beginning-of-line
bindkey -M viins '\C-E' end-of-line
bindkey -M viins '^k' vi-cmd-mode
# History Files Options
HISTFILE="${ZDOTDIR:-$HOME}/.dotfiles/history"
HISTSIZE=10000
SAVEHIST=10000
setopt INC_APPEND_HISTORY # Write to the history file immediately, not when the shell exits.
setopt HIST_IGNORE_SPACE # Do not record an event starting with a space.
setopt BANG_HIST # Treat the '!' character specially during expansion.
setopt EXTENDED_HISTORY # Write the history file in the ':start:elapsed;command' format.
setopt HIST_IGNORE_DUPS # Do not record an event that was just recorded again.
# Use vim to edit longer commands
autoload -z edit-command-line
zle -N edit-command-line
bindkey "^X^E" edit-command-line
# Alt m for easlier words.
autoload -Uz copy-earlier-word
zle -N copy-earlier-word
bindkey "^[m" copy-earlier-word
# Disable XON/XOFF flow control which causes ^-s to freeze instead of
# searching forward through history
stty -ixon
# Append custom bins
path+=("$HOME/.dotfiles/bin")
# Allow brace expansions
setopt BRACE_CCL
# Ctrl-w delete word, when it's a path only delete to the '/' and ':'
# Remove them from wordchars: A list of non-alphanumeric characters considered
# part of a word by the line editor.
my-backward-delete-word() {
local WORDCHARS=${WORDCHARS/\//}
WORDCHARS=${WORDCHARS/:/}
zle backward-delete-word
}
zle -N my-backward-delete-word
bindkey '^W' my-backward-delete-word
# Make sure SSH Agent is present
if ! pgrep -u "$USER" ssh-agent > /dev/null; then
ssh-agent > ~/.ssh-agent-cache
fi
if [[ "$SSH_AGENT_PID" == "" ]]; then
eval "$(<~/.ssh-agent-cache)"
fi
# For GPG signing commits
export GPG_TTY=$(tty)
# LS_COLORS config
local ls_colors_file="$HOME/.zsh/ls_colors"
if [[ -e "$ls_colors_file" ]]; then
eval $(dircolors -b "$ls_colors_file")
fi
# Use direnv
if [ -x "$(command -v direnv)" ]; then
eval "$(direnv hook zsh)"
fi
# Autocompletes for kubectl
if [ -x "$(command -v kubectl)" ]; then
source <(kubectl completion zsh)
fi
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
export GOPATH="$HOME/.go"
|