-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzshrc2
271 lines (231 loc) · 7.62 KB
/
zshrc2
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
# 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
# pyenv
if [ -d $HOME/.pyenv ]; then
export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
fi
# Variables
export EDITOR=nvim
# PATH
export PATH="$HOME/.local/bin/:/usr/sbin/:$PATH"
# DISPLAY
export DISPLAY=:0
# History
export HISTFILE=~/.zsh_history
export HISTSIZE=100000000
export SAVEHIST=$HISTSIZE
setopt SHARE_HISTORY
setopt HIST_IGNORE_ALL_DUPS
setopt HIST_FIND_NO_DUPS
setopt HIST_IGNORE_SPACE
setopt EXTENDED_HISTORY
# misc
export WORDCHARS="*?_-[]~=&;!#$%^(){}<>"
setopt EXTENDEDGLOB NOTIFY
export FZF_BASE="~/.local/share/fzf"
export FZF_BASE="/home/nsemmler/.cargo/bin/fzf"
# end of line aliases
alias -g C='| wc -l'
alias -g N='2>/dev/null'
alias -g LL='2>&1 | less'
alias -g G='| grep -i'
alias -g PS='ps -ef | grep'
alias -g L='| less'
alias -g M='| more'
alias -g S='| sort'
alias -g SU='| sort -u'
alias -g H='| head'
alias -g HELP='--help | less -R'
alias -g T='| tail'
alias -g h="top10_history"
alias -g j='jobs'
alias vim=nvim
alias vsp='nvim -O'
alias ezsh='nvim ~/.zshrc'
alias egit='nvim ~/.gitconfig'
alias v=nvim
alias szsh='. ~/.zshrc'
#alias cat='bat -pp'
alias k='kubectl'
alias d='docker'
alias cont='git rebase --continue'
if exa &> /dev/null; then
alias ls='exa'
alias ll='exa -l'
fi
# configure fzf
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
# git
alias g='git'
# Up/down arrow.
# I want shared history for ^R, but I don't want another shell's activity to
# mess with up/down. This does that.
# copied from https://github.com/cosmicexplorer/.zsh/blob/master/.zshrc
down-line-or-local-history() {
zle set-local-history 1
zle down-line-or-history
zle set-local-history 0
}
zle -N down-line-or-local-history
up-line-or-local-history() {
zle set-local-history 1
zle up-line-or-history
zle set-local-history 0
}
zle -N up-line-or-local-history
#function gitsth {
# print -z git $(fc -lrinm '*git*' -10000 | grep -E '^*[^a-zA-Z]*git' | sort -r | cut -d' ' -f5- | uniq | fzf --height=20)
#}
function _gitsth {
zle push-input
CMD="$(fc -lrinm '*git*' -10000 | grep -E '^*[^a-zA-Z]*git' | sort -r | cut -d' ' -f5- | uniq | fzf --height=20)"
if [ $? -eq 0 ]; then
BUFFER="git $CMD"
zle reset-prompt
zle accept-line
else
zle reset-prompt
zle send-break
fi
}
zle -N _gitsth
bindkey "\e[A" up-line-or-local-history
bindkey "\eOA" up-line-or-local-history
bindkey "\e[B" down-line-or-local-history
bindkey "\eOB" down-line-or-local-history
bindkey '^g' _gitsth
# scripts
function title {
echo -ne "\033]0;"$*"\007"
}
function cs () {
cd "$@" && ls -A
}
function mkcd () {
mkdir -pv "$@" && cd "$@"
}
function vimcd () {
cd "${@:h}" && vim "${@:t}"
}
function search () {
find ./ -iname "*$@*" 2> /dev/null
}
function insert_date () {
echo -n "$(date '+%Y_%m_%d')"
}
zle -N insert_date
function sudo_call () {
BUFFER="sudo $BUFFER"
CURSOR=$#BUFFER
}
zle -N sudo_call
function hl () {
sed -E "s/$1/$(tput setaf 5)\1$(tput sgr0)/"
}
# edit command
autoload -U edit-command-line
zle -N edit-command-line
#### Bind key ####
bindkey '^[o' insert_date
bindkey '^[s' sudo_call
bindkey '^[e' edit-command-line
bindkey '^[^[[D' backward-word
bindkey '^[^[[C' forward-word
bindkey -e # use emacs bindings
bindkey "^[[1;5C" forward-word
bindkey "^[[1;5D" backward-word
#### Completion ####
# first test of completion
autoload -Uz compinit
compinit
setopt AUTO_LIST AUTO_MENU
zstyle ':completion:*' use-cache on
zstyle ':completion:*' cache-path ~/.zsh/cache
zstyle ':completion:*' list-colors ''
zstyle ':completion:*' menu select=10
zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
zstyle ':completion:*' completer _complete _approximate
zstyle ':completion:*' group-name ''
zstyle ':completion:*:descriptions' format '-- %d --'
zstyle ':completion:*:cd:*' ignore-parents parent pwd # never autocomplete parent dir
zstyle ':completion:*:kill:*' verbose yes # show description for kill
## directories
# https://unix.stackexchange.com/questions/157763/do-we-have-more-history-for-cd
setopt AUTO_PUSHD # pushes the old directory onto the stack
setopt PUSHD_MINUS # exchange the meanings of '+' and '-'
setopt CDABLE_VARS # expand the expression (allows 'cd -2/tmp')
autoload -U compinit && compinit # load + start completion
zstyle ':completion:*:directory-stack' list-colors '=(#b) #([0-9]#)*( *)==95=38;5;12'
### Added by Zinit's installer
if [[ ! -f $HOME/.local/share/zinit/zinit.git/zinit.zsh ]]; then
print -P "%F{33} %F{220}Installing %F{33}ZDHARMA-CONTINUUM%F{220} Initiative Plugin Manager (%F{33}zdharma-continuum/zinit%F{220})…%f"
command mkdir -p "$HOME/.local/share/zinit" && command chmod g-rwX "$HOME/.local/share/zinit"
command git clone https://github.com/zdharma-continuum/zinit "$HOME/.local/share/zinit/zinit.git" && \
print -P "%F{33} %F{34}Installation successful.%f%b" || \
print -P "%F{160} The clone has failed.%f%b"
fi
source "$HOME/.local/share/zinit/zinit.git/zinit.zsh"
autoload -Uz _zinit
(( ${+_comps} )) && _comps[zinit]=_zinit
# Load a few important annexes, without Turbo
# (this is currently required for annexes)
zinit light-mode for \
zdharma-continuum/zinit-annex-as-monitor \
zdharma-continuum/zinit-annex-bin-gem-node \
zdharma-continuum/zinit-annex-patch-dl \
zdharma-continuum/zinit-annex-rust
### End of Zinit's installer chunk
#### More functions
function kns {
kubectl config set-context --current --namespace=$1
}
# Workaround to make git auto complete in ZSH faster
# https://stackoverflow.com/questions/9810327/zsh-auto-completion-for-git-takes-significant-amount-of-time-can-i-turn-it-off/9810485#9810485
__git_files () {
_wanted files expl 'local files' _files }
#####
# zinit
zinit snippet OMZ::plugins/bgnotify/bgnotify.plugin.zsh
zinit snippet OMZ::plugins/colorize/colorize.plugin.zsh
zinit snippet OMZ::plugins/command-not-found/command-not-found.plugin.zsh
# zinit snippet OMZ::plugins/docker/_docker
zinit snippet OMZ::plugins/aliases/aliases.plugin.zsh
zinit snippet OMZ::plugins/fancy-ctrl-z/fancy-ctrl-z.plugin.zsh
zinit snippet OMZ::plugins/fzf/fzf.plugin.zsh
zinit light zsh-users/zsh-syntax-highlighting.git
zinit light zsh-users/zsh-autosuggestions
zinit ice depth=1; zinit light romkatv/powerlevel10k
# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
#iterm
if ! [ -z $ITERM_SESSION_ID ]; then
export DISABLE_AUTO_TITLE="true"
precmd() {
# sets the tab title to current dir
echo -ne "\e]1;${PWD##*/}\a"
}
fi
bindkey \^U backward-kill-line
# Load a few important annexes, without Turbo
# (this is currently required for annexes)
zinit light-mode for \
zdharma-continuum/zinit-annex-as-monitor \
zdharma-continuum/zinit-annex-bin-gem-node \
zdharma-continuum/zinit-annex-patch-dl \
zdharma-continuum/zinit-annex-rust
### End of Zinit's installer chunk
# Load a few important annexes, without Turbo
# (this is currently required for annexes)
zinit light-mode for \
zdharma-continuum/zinit-annex-as-monitor \
zdharma-continuum/zinit-annex-bin-gem-node \
zdharma-continuum/zinit-annex-patch-dl \
zdharma-continuum/zinit-annex-rust
### End of Zinit's installer chunk