/
zshrc
231 lines (180 loc) · 6.43 KB
/
zshrc
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
#
# User configuration sourced by interactive shells
#
# Editor
# In absence of explicit zle configuration (e.g. via bindkey), Zsh sets its key bindings based on the value of $EDITOR.
# We set it first to be on the safe side.
export EDITOR='nvim'
export VISUAL='nvim'
# Fpath mangling for user functions
fpath=("${HOME}/.local/share/zsh/site-functions" $fpath)
# -----------------
# Zsh configuration
# -----------------
#
# History
#
# Remove older command from the history if a duplicate is to be added.
setopt HIST_IGNORE_ALL_DUPS
#
# Input/output
#
# Set editor default keymap to emacs (`-e`) or vi (`-v`)
#bindkey -e
bindkey -v
# Prompt for spelling correction of commands.
#setopt CORRECT
# Customize spelling correction prompt.
#SPROMPT='zsh: correct %F{red}%R%f to %F{green}%r%f [nyae]? '
# Remove path separator from WORDCHARS.
WORDCHARS=${WORDCHARS//[\/]}
# -----------------
# Zim configuration
# -----------------
# Use degit instead of git as the default tool to install and update modules.
#zstyle ':zim:zmodule' use 'degit'
# --------------------
# Module configuration
# --------------------
#
# git
#
# Set a custom prefix for the generated aliases. The default prefix is 'G'.
#zstyle ':zim:git' aliases-prefix 'g'
#
# input
#
# Append `../` to your input for each `.` you type after an initial `..`
#zstyle ':zim:input' double-dot-expand yes
#
# termtitle
#
# Set a custom terminal title format using prompt expansion escape sequences.
# See http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html#Simple-Prompt-Escapes
# If none is provided, the default '%n@%m: %~' is used.
#zstyle ':zim:termtitle' format '%1~'
#
# zsh-autosuggestions
#
# Disable automatic widget re-binding on each precmd. This can be set when
# zsh-users/zsh-autosuggestions is the last module in your ~/.zimrc.
ZSH_AUTOSUGGEST_MANUAL_REBIND=1
# Customize the style that the suggestions are shown with.
# See https://github.com/zsh-users/zsh-autosuggestions/blob/master/README.md#suggestion-highlight-style
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=242'
#
# zsh-syntax-highlighting
#
# Set what highlighters will be used.
# See https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters.md
ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets)
# Customize the main highlighter styles.
# See https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters/main.md#how-to-tweak-it
#typeset -A ZSH_HIGHLIGHT_STYLES
#ZSH_HIGHLIGHT_STYLES[comment]='fg=242'
# ------------------
# Initialize modules
# ------------------
ZIM_HOME=${ZDOTDIR:-${HOME}}/.zim
# Download zimfw plugin manager if missing.
if [[ ! -e ${ZIM_HOME}/zimfw.zsh ]]; then
if (( ${+commands[curl]} )); then
curl -fsSL --create-dirs -o ${ZIM_HOME}/zimfw.zsh \
https://github.com/zimfw/zimfw/releases/latest/download/zimfw.zsh
else
mkdir -p ${ZIM_HOME} && wget -nv -O ${ZIM_HOME}/zimfw.zsh \
https://github.com/zimfw/zimfw/releases/latest/download/zimfw.zsh
fi
fi
# Install missing modules, and update ${ZIM_HOME}/init.zsh if missing or outdated.
if [[ ! ${ZIM_HOME}/init.zsh -nt ${ZDOTDIR:-${HOME}}/.zimrc ]]; then
source ${ZIM_HOME}/zimfw.zsh init -q
fi
# Initialize modules.
source ${ZIM_HOME}/init.zsh
# ------------------------------
# Post-init module configuration
# ------------------------------
#
# zsh-history-substring-search
#
zmodload -F zsh/terminfo +p:terminfo
# Bind ^[[A/^[[B manually so up/down works both before and after zle-line-init
for key ('^[[A' '^P' ${terminfo[kcuu1]}) bindkey ${key} history-substring-search-up
for key ('^[[B' '^N' ${terminfo[kcud1]}) bindkey ${key} history-substring-search-down
for key ('k') bindkey -M vicmd ${key} history-substring-search-up
for key ('j') bindkey -M vicmd ${key} history-substring-search-down
unset key
#
# kube-ps1
#
KUBE_PS1_SEPARATOR=' '
KUBE_PS1_PREFIX=''
KUBE_PS1_SUFFIX=''
# ------------------------------
# Custom post-init configuration
# ------------------------------
# GPG
GPG_TTY="$(tty)"
export GPG_TTY
# Path mangling for user executables (Python, etc.)
path=("${HOME}/.local/bin" $path)
# Go
export GOPATH="${HOME}/go"
path=('/usr/local/go/bin' "${GOPATH}/bin" $path)
# fzf
[[ -f "${HOME}/.local/share/nvim/site/pack/packer/start/fzf/shell/key-bindings.zsh" ]] && . "${HOME}/.local/share/nvim/site/pack/packer/start/fzf/shell/key-bindings.zsh"
path=("${HOME}/.local/share/nvim/site/pack/packer/start/fzf/bin" $path)
# Prompt
_kube_ps1_to_rprompt() {
RPROMPT=$(kube_ps1)
}
autoload -U add-zsh-hook
add-zsh-hook precmd _kube_ps1_to_rprompt
# Allow command line editing in an external editor in the "vicmd" keymap.
# Zim's "input" module already enables this in the default keymap ("viins").
bindkey -M vicmd "${key_info[Control]}x${key_info[Control]}e" edit-command-line
# Commands completion
whence kubectl >/dev/null && . <(kubectl completion zsh) && compdef _kubectl kubectl
whence ko >/dev/null && . <(ko completion zsh) && compdef _ko ko
whence limactl >/dev/null && . <(limactl completion zsh) && compdef _limactl limactl
[[ -f "${HOME}/.local/share/nvim/site/pack/packer/start/fzf/shell/completion.zsh" ]] && . "${HOME}/.local/share/nvim/site/pack/packer/start/fzf/shell/completion.zsh"
# Aliases
alias K='kubectl'
alias Kn='kubectl -n'
alias Knk='kubectl -n kube-system'
alias Kni='kubectl -n istio-system'
whence kitty >/dev/null && alias ssh='kitty +kitten ssh'
if whence lima >/dev/null; then
ko.lima() { lima KO_DOCKER_REPO='kind.local' KIND_CLUSTER_NAME="${KIND_CLUSTER_NAME:-}" ko "$@" }
compdef _ko ko.lima
fi
# Shell theming
export FZF_DEFAULT_OPTS=("$FZF_DEFAULT_OPTS" '--color=bg+:0,pointer:3,marker:5,prompt:4')
# Source local environment
[[ -s ${ZDOTDIR:-${HOME}}/.zlocal ]] && . ${ZDOTDIR:-${HOME}}/.zlocal
# ensure (F)PATH entries remain unique after rc file reload
typeset -U PATH FPATH path fpath
# -----------------
# Utility functions
# -----------------
# Toggle between ssh-agent and gpg-agent (w/ SSH support)
ssh_toggle_agent() {
local a='ssh-agent'
# see 'man 1 zshexpn' Modifiers section
[[ $SSH_AUTH_SOCK:t == *.gpg-agent.* ]] && a='gpg-agent'
if [[ $a == ssh-agent ]]; then
gpg-connect-agent UPDATESTARTUPTTY /bye
_SSH_AUTH_SOCK=$SSH_AUTH_SOCK
SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)"
export SSH_AUTH_SOCK
else
SSH_AUTH_SOCK=$_SSH_AUTH_SOCK
unset _SSH_AUTH_SOCK
export SSH_AUTH_SOCK
fi
local _a='gpg-agent'
[[ $a == gpg-agent ]] && _a='ssh-agent'
print -P "%F{green})%f SSH agent is now: %F{magenta}${_a}%f"
}
# vim: ft=zsh sw=2 ts=2 et