-
Notifications
You must be signed in to change notification settings - Fork 2
/
.zshrc
313 lines (251 loc) · 7.73 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
# ███████╗███████╗██╗ ██╗██████╗ ██████╗
# ╚══███╔╝██╔════╝██║ ██║██╔══██╗██╔════╝
# ███╔╝ ███████╗███████║██████╔╝██║
# ███╔╝ ╚════██║██╔══██║██╔══██╗██║
# ███████╗███████║██║ ██║██║ ██║╚██████╗
# ╚══════╝╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝
# Plugins using Antibody
[ ! -f ~/.zsh/plugins.sh ] && antibody bundle < ~/.zsh/plugins.txt > ~/.zsh/plugins.sh
source ~/.zsh/plugins.sh
# Alias expansion
[ -f ~/.zsh/alias_expansion.zsh ] && source ~/.zsh/alias_expansion.zsh
# fzf
[ -f ~/.fzf/shell/completion.zsh ] && source ~/.fzf/shell/completion.zsh
[ -f ~/.fzf/shell/key-bindings.zsh ] && source ~/.fzf/shell/key-bindings.zsh
# asdf
[ -f ~/.asdf/asdf.sh ] && source ~/.asdf/asdf.sh
# My prompt
[ -f ~/.zsh/prompt.zsh ] && source ~/.zsh/prompt.zsh
# Profile
[ -f ~/.profile ] && source ~/.profile
[ -f /usr/share/z/z.sh ] && source /usr/share/z/z.sh
export FZF_DEFAULT_COMMAND='rg --files --hidden --follow --no-messages -g "!{.git}"'
[ -f ~/.zsh/fzf.theme.zsh ] && source ~/.zsh/fzf.theme.zsh
# zsh-autosuggestions
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#a9a9a9"
ZSH_AUTOSUGGEST_STRATEGY=(history)
bindkey '^e' autosuggest-accept
# zsh-syntax-highlighting
# (https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters.md)
ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets pattern cursor)
typeset -A ZSH_HIGHLIGHT_STYLES
ZSH_HIGHLIGHT_STYLES[command]='fg=blue,bold'
ZSH_HIGHLIGHT_STYLES[function]='fg=blue,bold'
ZSH_HIGHLIGHT_STYLES[alias]='fg=blue,bold'
ZSH_HIGHLIGHT_STYLES[single-hyphen-option]='fg=yellow,bold'
ZSH_HIGHLIGHT_STYLES[double-hyphen-option]='fg=yellow,bold'
ZSH_HIGHLIGHT_STYLES[path]='fg=cyan'
ZSH_HIGHLIGHT_STYLES[unknown-token]='fg=magenta'
# Better autocompletion
zmodload zsh/complist
zstyle ":completion:*" menu select
autoload -Uz compinit
if [ $(date +'%j') != $(date -r ~/.zcompdump '+%j') ]; then
compinit
else
compinit -C
fi
# <C-f> to edit line in editor
autoload edit-command-line
zle -N edit-command-line
bindkey '^f' edit-command-line
# cd without cd
setopt auto_cd
# Disable <C-s> for freezing the terminal
stty stop undef
export HISTFILE=$HOME/.zsh_history
export HISTSIZE=950000
export SAVEHIST=950000
########## Aliases ##########
# alias: Expand with whitespace at the end
# balias: Expand without whitespace at the end
# ialias: Don't expand
alias s="sudo"
alias sx='startx'
alias clip="xclip -selection clipboard"
alias sv="sudo $EDITOR"
alias pac="sudo pacman"
alias paci="sudo pacman -S"
alias pacs="pacman -Ss"
alias pacu="sudo pacman -Syu"
alias pacr="sudo pacman -Rsn"
alias gomi='go mod init github.com/fsmiamoto/$(basename $PWD)'
alias g="git"
alias gc="git commit"
alias gb="git branch"
alias gbd="git branch -d"
alias gbD="git branch -D"
alias gca="git commit --amend"
alias gcm="git commit -m"
alias gC="git add -A && git commit -m"
alias gck="git checkout"
alias gckb="git checkout -b"
alias gckm="git checkout master"
alias gd="git diff"
alias gr="git remote"
alias grb="git rebase"
alias grs="git reset --soft"
alias ga="git add"
alias ga.="git add ."
alias gaa="git add --all"
alias gf="git fetch"
alias gfp="git fetch --prune"
alias gfa="git fetch --all"
alias gst="git status"
alias gsh="git stash"
alias gshp="git stash pop"
alias gshl="git stash list"
alias gps="git push"
alias gpsu="git push -u origin"
alias gpl="git pull"
alias gl="git log --graph --decorate --all --oneline"
alias glo="git log --graph --decorate --all"
alias gi="gh issue"
alias gil="gh issue list"
alias gic="gh issue create"
alias giv="gh issue view"
alias gpr="gh pr"
alias gprc="gh pr create"
alias gprl="gh pr list"
alias gprv="gh pr view"
alias lg='lazygit'
alias t="tmux"
alias tt="tmux attach-session"
alias tk="tmux kill-session"
alias tls="tmux list-sessions"
alias ta="tmux attach-session -t"
alias td="tmux detach"
alias tkv="tmux kill-server"
alias tf="terraform"
alias d="docker"
alias dc="docker-compose"
alias dco="docker container"
alias dcol="docker container ls"
alias dcor="docker container run"
alias dcorm="docker container rm"
alias dn="docker network"
alias ds="sudo systemctl start docker.service"
alias kc="kubectl"
alias mk="make"
alias mki="sudo make install"
alias ka="killall"
alias chx="chmod +x"
alias rc="rclone"
balias vimc="$EDITOR ~/.dotfiles/.vimrc"
balias zshc="$EDITOR ~/.dotfiles/.zshrc"
balias tmc="$EDITOR ~/.dotfiles/.tmux.conf"
balias src="source $HOME/.zshrc"
ialias df='df -h'
ialias du='du -h'
ialias ip='ip -c'
ialias sed='sed -E'
ialias mkdir="mkdir -pv"
ialias fzf="fzf --color=16 --preview 'bat --style=numbers --color=always {}'"
ialias diff="diff --color=auto"
ialias c="clear"
ialias z="_z 2>&1"
ialias ls="exa"
ialias ll="exa -l"
ialias la="exa -la"
ialias l="exa -l"
ialias cat="bat"
ialias sctl="systemctl"
ialias psc='ps xawf -eo pid,user,cgroup,args'
ialias pls="sudo"
ialias gw="./gradlew"
ialias dot="cd ~/.dotfiles"
ialias scs="cd ~/.scripts"
########## Functions ##########
# Auto ls when cd'ing
chpwd(){
emulate -L zsh
ls --group-directories-first
}
# Creates a directory and cd's into it
mkd() {
mkdir $1 && cd $1
}
# Kill a process
k(){
pid=$(ps -exo 'user,pid,cmd' | sed '1d' | fzf --preview-window=hidden | awk '{printf $2}')
if [ "$1" != "" ]; then
kill -"$1" "$pid"
else
kill "$pid"
fi
}
# Colorizes go test output
gotest(){
go test $* | sed ''/PASS/s//$(printf "\033[32mPASS\033[0m")/'' | sed ''/FAIL/s//$(printf "\033[31mFAIL\033[0m")/''
}
# Lists my config files and opens it on $EDITOR
cfg() {
file=$( fd -t f . "$HOME/.config" | fzf ) && $EDITOR $file
}
clone(){
test -n "$1" && cd $PROJECT_DIR > /dev/null && git clone $1
echo "Missing repository URL"
}
# Credit to github.com/connermcd
pi() {
sudo pacman -S $(pacman -Ssq | fzf -m --preview="pacman -Si {}")
}
pkr() {
sudo pacman -Rsn $(pacman -Qe | awk '{print $1}' | fzf -m --preview="yay -Si {}")
}
open_with_fzf() {
fd -t f -H -I | fzf -m --preview="xdg-mime query default {}" | xargs -ro -d "\n" xdg-open 2>&-
}
cd_with_fzf() {
local exclude="go"
local dir="$(fd -t d --exclude ${exclude} | fzf --preview="tree -L 1 {}")"
cd "$dir"
}
rs() {
rsync -avzrP $@
}
todo() {
local file="todo-$(date +"%Y-%m-%d").md"
nb search "$file" > /dev/null 2>&1 || nb add "$file" -c " " > /dev/null
echo "- $@"| nb edit "$file"
}
pw() {
file=$(fd . '.password-store/' -e '.gpg' | sed 's!\.password-store/!!g; s!\.gpg!!g' | fzf)
pass show $file | tr -d '\n' |clip
echo "Copied password to clipboard"
}
prck() {
local pr_number=$(gh pr list | fzf --preview='gh pr view {1}'| awk '{print $1}')
gh pr checkout "$pr_number" --detach
}
v() {
if [ $# -eq 0 ]; then
command "$EDITOR" "."
else
command "$EDITOR" "$@"
fi
}
o() {
xdg-open $1 & disown
exit
}
n() {
$EDITOR ~/notes/"$1.md"
}
vmhost() {
local hostname="$1"
local ip=$(virsh net-dhcp-leases default | grep "$1" | awk '{print $5}' | sed -E 's/^([0-9\.]+).*/\1/')
printf "%s %s\n" "$ip" "$hostname" | sudo tee -a /etc/hosts
}
bindkey -s '^o' 'cd_with_fzf \n'
# https://github.com/slavistan/dwm-dynamicswallow-patch
bindkey '^X^m' accept-line-swallow
zle -N accept-line-swallow acceptandswallow
acceptandswallow() {
dwmswallow $WINDOWID
zle accept-line
}
[ -f ~/vars.sh ] && source ~/vars.sh
[ -f ~/.zsh/priv.zsh ] && source ~/.zsh/priv.zsh
# opam configuration
[[ ! -r /home/shigueo/.opam/opam-init/init.zsh ]] || source /home/shigueo/.opam/opam-init/init.zsh > /dev/null 2> /dev/null