-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdot_zshrc
231 lines (194 loc) · 6.22 KB
/
dot_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
# ------------------------------------
# General
# ------------------------------------
# color
autoload -Uz colors
colors
# cd
setopt auto_cd
setopt auto_pushd
setopt extended_glob
setopt pushd_ignore_dups
# history
export HISTFILE=~/.zsh_history
export HISTSIZE=10000
export SAVEHIST=10000
export HISTTIMEFORMAT="[%F %T] "
HISTORY_IGNORE='(clear|cd|history|pwd|exit|[bf]g|l[asl]|rm)'
setopt INC_APPEND_HISTORY
setopt bang_hist
setopt extended_history
setopt hist_ignore_all_dups
setopt hist_ignore_dups
setopt hist_ignore_space
setopt hist_no_store
setopt hist_reduce_blanks
setopt hist_save_no_dups
setopt hist_verify
setopt share_history
# gpg
export GPG_TTY=$(tty)
# completion
zstyle ':completion:*:default' menu select=1
# ------------------------------------
# Prompt
# ------------------------------------
# install starship if not installed
if ! type starship > /dev/null; then
curl -sS https://starship.rs/install.sh | sh
fi
eval "$(starship init zsh)"
# ------------------------------------
# Plugin
# ------------------------------------
# install zinit if not installed
if [[ ! -f $HOME/.zinit/bin/zinit.zsh ]]; then
command mkdir -p "$HOME/.zinit" && command chmod g-rwX "$HOME/.zinit"
command git clone https://github.com/zdharma-continuum/zinit "$HOME/.zinit/bin"
fi
# init zinit
source "$HOME/.zinit/bin/zinit.zsh"
autoload -Uz _zinit
(( ${+_comps} )) && _comps[zinit]=_zinit
# install packages
zinit wait lucid light-mode for \
atinit"ZINIT[COMPINIT_OPTS]=-C; zicompinit; zicdreplay" zdharma-continuum/fast-syntax-highlighting \
blockf zsh-users/zsh-completions \
atload"!_zsh_autosuggest_start;export ZSH_AUTOSUGGEST_STRATEGY=(history completion)" zsh-users/zsh-autosuggestions \
atload"ZVM_NO_INSERT_MODE_BINDINGS=true" depth=1 kitagawa-hr/zsh-vi-mode \
atload"export ZSH_SYSTEM_CLIPBOARD_METHOD=pb" kutsan/zsh-system-clipboard \
dim-an/cod
zinit lucid from'gh-r' as'program' for \
mv'zoxide* -> zoxide' atload'eval "$(zoxide init zsh)"' ajeetdsouza/zoxide \
mv'mcfly* -> mcfly' atload'eval "$(mcfly init zsh)"; export MCFLY_KEY_SCHEME=vim; export MCFLY_FUZZY=true' cantino/mcfly
# ------------------------------------
# Alias
# ------------------------------------
alias v='nvim'
alias ...='cd ../..'
alias ....='cd ../../..'
alias rm='rm -i'
alias mv='mv -i'
alias rename='massren'
if which eza &> /dev/null;
then
alias ls='eza --icons=auto'
alias ll='eza -l --icons=auto'
alias la='eza -la --icons=auto'
alias tree='eza --tree --icons=auto'
else
alias la='ls -a'
alias ll='ls -l'
fi
# git commands
function cd-ghq-list() {
local repo=$(ghq list | fzf)
if [ $repo ]; then
cd $(ghq root)/$repo
fi
}
function vscode-ghq-list() {
local repo=$(ghq list | fzf)
if [ $repo ]; then
code $(ghq root)/$repo
fi
}
alias vs='vscode-ghq-list'
alias g='cd-ghq-list'
alias gs='git status'
alias gss='git status --short --branch'
alias gr="git log --graph --date=short --decorate=short --pretty=format:'%Cgreen%h %Creset%cd %Cblue%cn %Cred%d %Creset%s'"
alias ghb='gh repo view -w $(ghq list | fzf | cut -d "/" -f 2,3)'
alias gch='git checkout `git branch | fzf | sed -e "s/\* //g" | awk "{print \$1}"`'
alias gca='git checkout `git branch --all | peco | sed -e "s/\* //g" | awk "{print \$1}"`'
alias gb='git branch'
alias cm='git commit -m'
alias push='git push origin HEAD'
alias pull='git pull origin $(git rev-parse --abbrev-ref HEAD) --prune'
alias add='git add'
alias commit='git commit'
# ------------------------------------
# Linux
# ------------------------------------
if [[ "$OSTYPE" == "linux-gnu" ]]; then
# Color
if [ "$TERM" = "xterm" ]; then
export TERM="xterm-256color"
fi
# pkg-config
export PKG_CONFIG_PATH=/usr/lib64/pkgconfig
# Alias
alias pbcopy='xclip -selection clipboard'
alias pbpaste='xclip -selection clipboard -o'
fi
# ------------------------------------
# Key Bindings
# ------------------------------------
# For faster switch to vim mode
export KEYTIMEOUT=1
autoload -Uz smart-insert-last-word
zle -N insert-last-word smart-insert-last-word
zstyle :insert-last-word match '*([^[:space:]][[:alpha:]/\\]|[[:alpha:]/\\][^[:space:]])*'
bindkey -M viins '^]' insert-last-word
bindkey -M viins '^A' beginning-of-line
bindkey -M viins '^B' backward-char
bindkey -M viins '^E' end-of-line
bindkey -M viins '^F' forward-char
bindkey -M viins '^G' send-break
bindkey -M viins '^H' backward-delete-char
bindkey -M viins '^K' kill-line
bindkey -M viins '^N' down-line-or-history
bindkey -M viins '^P' up-line-or-history
bindkey -M viins '^U' backward-kill-line
bindkey -M viins '^W' vi-backward-kill-word
bindkey -M viins '^Y' yank
autoload -Uz edit-command-line
zle -N edit-command-line
bindkey -M vicmd '!' edit-command-line
# Yank to the system clipboard
function vi-yank-to-clipboard {
zle vi-yank
echo "$CUTBUFFER" | pbcopy
}
function vi-delete-to-clipboard {
zle vi-delete
echo "$CUTBUFFER" | pbcopy
}
zle -N vi-yank-to-clipboard
bindkey -M vicmd 'y' vi-yank-to-clipboard
zle -N vi-delete-to-clipboard
bindkey -M vicmd 'd' vi-delete-to-clipboard
# ------------------------------------
# Fuzzy Finder
# ------------------------------------
export FZF_DEFAULT_COMMAND='fd --exclude .git --max-depth 5 --hidden'
export FZF_DEFAULT_OPTS='--height 40% --reverse --border'
export FZF_COMPLETION_TRIGGER=','
function fzf-file() {
local find_cmd='fd --exclude .git --max-depth 5 --hidden --type f'
local add_slash="awk '{print \$0 \"/\"}'"
local preview_dir='eza --tree -L 2 {}'
local preview_file='bat --style=header,grid --color=always --line-range :100 {}'
local preview_cmd="if [[ {} == */ ]] ; then ${preview_dir}; else ${preview_file}; fi"
local fzf_cmd="fzf -0 -1 --preview '${preview_cmd}'"
local cmd="{${find_cmd} --type d | ${add_slash}; ${find_cmd} --type f} | ${fzf_cmd}"
local ret=$(eval "${cmd}")
case $ret in
"") zle reset-prompt && return;;
*/) cd $ret ;;
*) ${EDITOR} $ret ;;
esac
zle accept-line
}
zle -N fzf-file
bindkey '^O' fzf-file
# ------------------------------------
# Source machine local config
# ------------------------------------
[ -f ~/.zshrc.local ] && source ~/.zshrc.local
# ------------------------------------
# Compile
# ------------------------------------
if [ ~/.zshrc -nt ~/.zshrc.zwc ]; then
zcompile ~/.zshrc
fi