-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzshrc
354 lines (298 loc) · 11.5 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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi
# Requirements
# 1. ZSH
# 2. antibody (This script will install if needed)
# 3. powerline
# 4. powerline-fonts
# 5. fzf
# 6. lsd (community exa - ls alternative needed for fzf)
# Recommended
# 1. git-delta
# 2. bat: view code
# 3. pandoc: convert any kind of file to markdown. Any generated cache file will be store in same /tmp/zsh-fzf-tab-$USER as fzf-tab
# 4. mdcat: render markdown
# 5. grc: colorize the output of some commands
# 6. less: a pager
# 7. pdftotext
# 8. osc (go install -v github.com/theimpostor/osc@latest) - OSC 52 support (copy from terminal)
# 4.1 Supported compression methods and archive formats
#
# gzip, compress requires gzip
# bzip2 requires bzip2
# lzma requires lzma
# xz requires xz
# zstd requires zstd
# brotli requires bro
# lz4 requires lz4
# tar requires optionally archive_color for coloring
# ar library requires bsdtar or ar
# zip archive requires bsdtar or unzip
# jar archive requires bsdtar or unzip
# rar archive requires bsdtar or unrar or rar
# 7-zip archive requires 7zr
# lzip archive requires lzip
# iso images requires bsdtar or isoinfo
# rpm requires rpm2cpio and cpio or bsdtar
# Debian requires bsdtar or ar
# cab requires cabextract
#
# 4.2 List of preprocessed file types
#
# directory displayed using ls -lA
# nroff(man) requires groff or mandoc
# shared library requires nm
# MS Word (doc) requires wvText or antiword or catdoc or libreoffice
# Powerpoint (ppt) requires catppt
# Excel (xls) requires in2csv (csvkit) or xls2csv
# odt requires pandoc or odt2txt or libreoffice
# odp requires libreoffice
# ods requires xlscat or libreoffice
# MS Word (docx) requires pandoc or docx2txt or libreoffice
# Powerpoint (pptx) requires pptx2md or libreoffice
# Excel (xlsx) requires in2csv or xlscat or excel2csv or libreoffice
# csv requires csvtable or csvlook or column or pandoc
# rtf requires unrtf or libreoffice
# epub requires pandoc
# html,xml requires w3m or lynx or elinks or html2text
# pdf requires pdftotext or pdftohtml
# perl pod requires pod2text or perldoc
# dvi requires dvi2tty
# djvu requires djvutxt
# ps requires ps2ascii (from the gs package)
# mp3 requires id3v2
# multimedia formats requires mediainfo or exiftools
# image formats requires mediainfo or exiftools or identify
# hdf, nc4 requires h5dump or ncdump (NetCDF format)
# crt, pem, csr, crl requires openssl
# matlab requires matdump
# Jupyter notebook requires pandoc
# markdown requires mdcat or pandoc
# log requires ccze
# java.class requires procyon
# MacOS X plist requires plistutil
# binary data requires strings
# json requires jq
# device tree blobs requires dtc (extension dtb or dts)
# Suggested
# 1. mediainfo
# 2. lsd
# 3. Chafa
# ZSH modules
# zmodload zsh/zprof
# Compdef is basically a function used by zsh for load the auto-completions.
# The completion system needs to be activated.
autoload -Uz compinit && compinit
# # The optional three formats: "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
HIST_STAMPS="yyyy-mm-dd"
# History file
export HISTFILE="$HOME/.zsh_history"
export HISTSIZE=10000
export SAVEHIST=10000
# Set options
# Set command line autocorrect
setopt correct
# Share history between terminal sessions
# setopt share_history
# Custom environmental variables
# Local environment variables should go into $ZDOTDIR/.zshenv where $ZDOTDIR is home unless specified
# Better questions
autoload -U colors && colors
export SPROMPT="Correct $fg[red]%R$reset_color to $fg[green]%r?$reset_color (Yes, No, Abort, Edit) "
# ==== Environment Variable Setup ====
# Main ZSH config directory
export ZSH_DIR="$HOME/.config/zsh"
# Customizations folder
export ZSH_CUSTOM="$ZSH_DIR/custom"
export ZCOMPLETION="$ZSH_DIR/completion"
# Cache directory
# Needed for kubectl
export ZSH_CACHE_DIR="$HOME/.cache/zsh"
# Functions folder
export ZFUNC="$ZSH_DIR/function"
export ZSCRIPTS="$ZSH_DIR/script"
export ZLOCAL="$ZSH_DIR/local"
export ZBIN="$ZSH_DIR/bin"
export GOPATH="$HOME/.go"
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:$HOME/.local/bin:$ZSH_DIR/bin:/opt/android-sdk/platform-tools:$GOPATH/bin"
# FPATH: Contains a list of directories that the z/OS shell searches to find shell functions.
export FPATH="$ZCOMPLETION:$ZSCRIPTS:$ZFUNC:$ZLOCAL:$FPATH"
# Set terminal colors
# Based on https://github.com/joshjon/bliss-dircolors
eval `dircolors $ZSH_CUSTOM/bliss.dircolors`
autoload -Uz extract
autoload -Uz sshdc
autoload -Uz mkcd
autoload -Uz zssh
autoload -Uz update_os
autoload -Uz install_rsub
autoload -Uz update_zsh
autoload -Uz zrepl_watch
autoload -Uz healthcheck_init
autoload -Uz nocorrect
# # Load source alias files
if [ "$(ls $ZSH_CUSTOM/alias)" ]; then
for file in $ZSH_CUSTOM/alias/*; do
source "$file"
done
fi
# Load any local configuration
if [ "$(ls $ZLOCAL)" ]; then
for file in $ZLOCAL/*; do
source "$file"
done
fi
# Antibody Plug Manager
# Check to see if it's installed (and in the path)
type antibody >/dev/null 2>&1 || { curl -sfL git.io/antibody | sudo sh -s - -b /usr/local/bin; }
source <(antibody init)
export ANTIBODY_HOME="$ZSH_CACHE_DIR/antibody"
antibody bundle ohmyzsh/ohmyzsh path:plugins/git
antibody bundle ohmyzsh/ohmyzsh path:plugins/pip
antibody bundle ohmyzsh/ohmyzsh path:plugins/sudo
antibody bundle ohmyzsh/ohmyzsh path:plugins/command-not-found
antibody bundle ohmyzsh/ohmyzsh path:plugins/colored-man-pages
antibody bundle ohmyzsh/ohmyzsh path:plugins/extract
antibody bundle "supercrabtree/k"
# Back directory
# https://github.com/Tarrasch/zsh-bd
# antibody bundle "Tarrasch/zsh-bd"
# antibody bundle cupricreki/zsh-bw-completion
# Open command on explain-shell.com usage: explain <command>
# antibody bundle "gmatheu/zsh-plugins explain-shell"
# Syntax highlighting bundle.
# antibody bundle "zsh-users/zsh-syntax-highlighting"
# Vi mode
antibody bundle "jeffreytse/zsh-vi-mode"
ZVM_LINE_INIT_MODE=$ZVM_MODE_INSERT
# Powerline loading
# powerline-daemon -q
# . /usr/share/powerline/bindings/zsh/powerline.zsh
# Initialize enhancd
antibody bundle "b4b4r07/enhancd"
export ENHANCD_FILTER="fzf --preview='exa --tree --group-directories-first --git-ignore --level 1 {}'"
source "$ZSH_CACHE_DIR/antibody/https-COLON--SLASH--SLASH-github.aaakk.us.kg-SLASH-b4b4r07-SLASH-enhancd/init.sh"
# Load kubectl bundle if installed
kubectl --version &> /dev/null
if [ $? -eq 0 ]; then
# Load bundle
antibody bundle "ohmyzsh/ohmyzsh path:plugins/kubectl"
fi
# Load docker completions if installed
command docker >/dev/null 2>&1 && \
source $ZCOMPLETION/_docker
# Load aws bundle if installed
aws --version &> /dev/null
if [ $? -eq 0 ]; then
antibody bundle "ohmyzsh/ohmyzsh path:plugins/aws"
fi
# Load ansible bundle if installed
ansible --version &> /dev/null
if [ $? -eq 0 ]; then
antibody bundle "ohmyzsh/ohmyzsh path:plugins/ansible"
fi
# osc install
go version &> /dev/null
if [ $? -ne 0 ]; then
antibody bundle "ohmyzsh/ohmyzsh path:plugins/golang"
fi
# install osc if missing
osc version &> /dev/null
if [ $? -ne 0 ]; then
go install -v github.com/theimpostor/osc@latest
echo "osc installed"
fi
# Load custom key bindings
# source "$ZSH_CUSTOM/keybindings.zsh"
# ================================================
# Autocomplete
# ================================================
# Add more completions
antibody bundle "zsh-users/zsh-completions"
antibody bundle "sinetoami/antibody-completion"
antibody bundle "sunlei/zsh-ssh"
command yt-dlp >/dev/null 2>&1 && antibody bundle "clavelm/yt-dlp-omz-plugin"
command tailscale >/dev/null 2>&1 && source "$ZSH_CUSTOM/tailscale_zsh_completion.zsh"
source $ZCOMPLETION/_osc
# ================================================
# Fzf configuration
# ================================================
source "$ZSH_CUSTOM/fzf_key-bindings.zsh"
source "$ZSH_CUSTOM/fzf_completion.zsh"
# export FZF_COMPLETION_TRIGGER=''
# bindkey '^I' $fzf_default_completion
# Tab completion
antibody bundle "Aloxaf/fzf-tab"
antibody bundle "Freed-Wu/fzf-tab-source" # formatttin&g for fzf-preview in fzf-tab
# Bind rebind file search to alt+t
bindkey -r '^T'
bindkey -r '^[t'
bindkey '^[t' fzf-file-widget
# Auto-completion case-insensitive
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|=*' 'l:|=* r:|=*'
# disable sort when completing `git checkout`
zstyle ':completion:*:git-checkout:*' sort false
# set descriptions format to enable group support
zstyle ':completion:*:descriptions' format '[%d]'
# set list-colors to enable filename colorizing
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
# switch group using `<` and `>`
zstyle ':fzf-tab:*' switch-group '<' '>'
# Tmux popup window
# zstyle ':fzf-tab:*' fzf-command ftb-tmux-popup
# show systemd unit status
# zstyle ':fzf-tab:complete:systemctl-*:*' fzf-preview 'SYSTEMD_COLORS=1 systemctl status $word'
# # environment variables preview
# zstyle ':fzf-tab:complete:(-command-|-parameter-|-brace-parameter-|export|unset|expand):*' \
# fzf-preview 'echo ${(P)word}'
#
# # git - requires git-delta
# zstyle ':fzf-tab:complete:git-(add|diff|restore):*' fzf-preview \
# 'git diff $word | delta'
# zstyle ':fzf-tab:complete:git-log:*' fzf-preview \
# 'git log --color=always $word'
# zstyle ':fzf-tab:complete:git-help:*' fzf-preview \
# 'git help $word | bat -plman --color=always'
# zstyle ':fzf-tab:complete:git-show:*' fzf-preview \
# 'case "$group" in
# "commit tag") git show --color=always $word ;;
# *) git show --color=always $word | delta ;;
# esac'
# zstyle ':fzf-tab:complete:git-checkout:*' fzf-preview \
# 'case "$group" in
# "modified file") git diff $word | delta ;;
# "recent commit object name") git show --color=always $word | delta ;;
# *) git log --color=always $word ;;
# esac'
# # review panel
zstyle ':fzf-tab:complete:*:*' fzf-preview 'less ${(Q)realpath}'
# export LESSOPEN='|/usr/bin/lesspipe.sh %s' # Formatting of panel
export LESS='-r -M -S -I --mouse' # raw, verbose, chop lines, ignore case, mouse scrolling
export LESSQUIET=1 # Suppress additional output not belonging to the file contents
#
# give a preview of commandline arguments when completing `kill/ps` below
zstyle ':completion:*:*:*:*:processes' command "ps -u $USER -o pid,user,comm -w -w"
zstyle ':fzf-tab:complete:(kill|ps):argument-rest' fzf-preview \
'[[ $group == "[process ID]" ]] && ps --pid=$word -o cmd --no-headers -w -w'
zstyle ':fzf-tab:complete:(kill|ps):argument-rest' fzf-flags --preview-window=down:3:wrap
### fzf-tab Keybindings
# ctrl-a to select all
zstyle ':fzf-tab:*' fzf-bindings 'ctrl-a:toggle-all'
# These have to go after most plugins as they wrap other ones
antibody bundle "zdharma-continuum/fast-syntax-highlighting"
antibody bundle "zsh-users/zsh-autosuggestions"
# Powerlevel 10k
antibody bundle "romkatv/powerlevel10k"
# Load tmux bundle if installed
tmux --version &>/dev/null
if [ $? -eq 0 ]; then
ZSH_TMUX_AUTOSTART=true \
ZSH_TMUX_AUTOCONNECT=false \
antibody bundle "ohmyzsh/ohmyzsh path:plugins/tmux"
fi
# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f $ZSH_CUSTOM/p10k.zsh ]] || source $ZSH_CUSTOM/p10k.zsh