-
Notifications
You must be signed in to change notification settings - Fork 0
/
zshrc
206 lines (174 loc) · 5.8 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
if [ "$CHINA_MAINLAND" != '0' ]; then
export GITHUB=mirror.ghproxy.com/https://github.com
export GITHUB_RAW=mirror.ghproxy.com/https://raw.githubusercontent.com
else
export GITHUB=github.com
export GITHUB_RAW=raw.githubusercontent.com
fi
# PATH
export PATH=$HOME/.local/bin:$HOME/.bin:$PATH
# Node.js related
if [ -d "$HOME/.n" ]; then
export N_PREFIX=$HOME/.n
export PATH=$N_PREFIX/bin:$PATH
if [ "$CHINA_MAINLAND" != '0' ]; then
export N_NODE_MIRROR=https://mirrors.ustc.edu.cn/node/
fi
fi
# zsh-vi-mode (zvm)
function zvm_config() {
ZVM_READKEY_ENGINE=$ZVM_READKEY_ENGINE_ZLE
ZVM_KEYTIMEOUT=0.2
ZVM_ESCAPE_KEYTIMEOUT=0.2 # so that EscEsc sudo will work
}
function zvm_after_init() {
# Fix key conflicts
bindkey -v '^[[A' up-line-or-beginning-search
bindkey -v '^[[B' down-line-or-beginning-search
# fzf & Nord theme
source $ZSH_CUSTOM/plugins/fzf-zsh-plugin/fzf-zsh-plugin.plugin.zsh
export FZF_DEFAULT_OPTS=$FZF_DEFAULT_OPTS'
--color fg:#D8DEE9,bg:#2E3440,hl:#A3BE8C,fg+:#D8DEE9,bg+:#434C5E,hl+:#A3BE8C
--color pointer:#BF616A,info:#4C566A,spinner:#4C566A,header:#4C566A,prompt:#81A1C1,marker:#EBCB8B'
}
# oh-my-zsh config
export ZSH="$HOME/.oh-my-zsh"
ZSH_THEME="agkozak"
DISABLE_AUTO_UPDATE="true"
plugins=(git sudo node npm macos extract zsh-vi-mode fast-syntax-highlighting zsh-autosuggestions fzf-tab zsh-z zsh-docker-aliases)
source $ZSH/oh-my-zsh.sh
# zsh config
setopt HIST_IGNORE_SPACE
# Customization for the theme agkozak
AGKOZAK_CUSTOM_PROMPT=$'%(!.%S%B.%B%F{green})%n%1v%(!.%b%s.%f%b) '
AGKOZAK_CUSTOM_PROMPT+='%B%F{blue}%2v%f%b'
AGKOZAK_CUSTOM_PROMPT+=$'%(3V.%F{243}%3v%f.)\n'
AGKOZAK_CUSTOM_PROMPT+='%(4V.:.%(!.#.$)) '
AGKOZAK_CUSTOM_RPROMPT=$'%{\e[1A%}%(?..%B%F{red}(%?%)%f%b )%F{243}%*%f%{\e[1B%}'
AGKOZAK_PROMPT_DIRTRIM=4
AGKOZAK_BLANK_LINES=1
AGKOZAK_CUSTOM_SYMBOLS=( '↓↑' '↓' '↑' '+' 'x' '*' '>' '?' 'S')
AGKOZAK_FORCE_ASYNC_METHOD=none
# bat
export BAT_THEME=Nord
alias cat="bat -pp"
# broot
if [ -f "$HOME/.config/broot/launcher/bash/br" ]; then
source $HOME/.config/broot/launcher/bash/br
fi
# Rust cargo
if [ -f "$HOME/.cargo/env" ]; then
. "$HOME/.cargo/env"
fi
# z
alias zl="z -l"
alias zc="z -c"
# eza
alias ls="eza"
alias l="eza -lF --time-style=long-iso"
alias la="eza -lF --time-style=long-iso -a"
alias ll="eza -lhF --time-style=long-iso --git"
alias lla="eza -lhF --time-style=long-iso --git -a"
alias laa="eza -lhHigUmuSa --time-style=long-iso --git --color-scale"
alias tree="eza --tree --level=2"
# npm
alias npmc="npm --registry=https://registry.npmmirror.com"
alias yarnc="yarn --registry=https://registry.npmmirror.com"
alias ni="npm i"
alias nid="npm i -D"
alias nig="npm i -g"
alias nr="npm run"
alias np="npm publish"
alias nu="npm uninstall"
alias nrb="npm run build"
alias nrd="npm run dev"
alias nrl="npm run lint"
alias nrlf="npm run lint -- --fix"
alias nrt="npm run test"
alias nrtc="npm run test -- --coverage"
alias nrtw="npm run test -- --watch"
alias pi="pnpm i"
alias pid="pnpm i -D"
alias pig="pnpm i -g"
alias piw="pnpm i -w"
alias piwd="pnpm i -w -D"
function npm-link() {
module="./node_modules/$1"
rm -r $module
ln -s $2 $module
}
# TypeScript
alias tscp="tsc -p ."
alias tscpw="tsc -p . -w"
alias tscpp="tsc -p tsconfig.prod.json"
alias tscppw="tsc -p tsconfig.prod.json -w"
# Jest
alias jest="npx jest"
alias jestb="npx jest --runInBand"
alias jestc="npx jest --coverage"
alias jestp="npx jest --testPathPattern"
alias jestbp="npx jest --runInBand --testPathPattern"
# adb
alias adb-scr="adb exec-out screencap -p"
alias adb-scrcpy="adb exec-out screencap -p | impbcopy -"
alias adb-deeplink="adb shell am start -W -a android.intent.action.VIEW -d"
alias adb-paste="adb shell am broadcast -a clipper.get"
alias adb-copy="adb shell am broadcast -a clipper.set -e text"
alias adb-kill="adb shell am force-stop"
# Helix
if which hx > /dev/null 2>&1; then
export EDITOR="hx"
export VISUAL="hx"
elif which helix > /dev/null 2>&1; then
export EDITOR="helix"
export VISUAL="helix"
alias hx="helix"
fi
# Docker
alias dkcdu="docker-compose down && docker-compose up"
alias dkcdU="docker-compose down && docker-compose up -d"
alias dkclf="docker-compose logs -f --tail 100"
# Haskell Stack
if type "stack" > /dev/null; then
alias sr="stack run"
alias sb="stack build"
alias srs="stack run --silent"
alias sghci="stack ghci"
autoload -U +X compinit && compinit
autoload -U +X bashcompinit && bashcompinit
eval "$(stack --bash-completion-script stack)"
fi
# Flutter
if type "flutter" > /dev/null; then
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
fi
# Proxies
alias unset-proxy="unset http_proxy && unset https_proxy"
alias ioa-proxy="export http_proxy=http://127.0.0.1:12639 && export https_proxy=http://127.0.0.1:12639"
alias ss-proxy="export http_proxy=http://127.0.0.1:1080 && export https_proxy=http://127.0.0.1:1080"
alias clash-proxy="export http_proxy=http://127.0.0.1:7890 && export https_proxy=http://127.0.0.1:7890"
# MacOS
alias jitouch="killall Jitouch; open $HOME/Library/PreferencePanes/Jitouch.prefPane/Contents/Resources/Jitouch.app"
alias show-hidden="chflags nohidden"
alias hide-hidden="chflags hidden"
# Other
alias ports-usage="lsof -i -P -sTCP:LISTEN"
alias hs="http-server"
alias sudo="sudo " # sudo magic: https://askubuntu.com/questions/22037/aliases-not-available-when-using-sudo
alias env="/usr/bin/env -0 | sort -z | tr '\0' '\n' | sd '(^|\n)([A-Za-z0-9_]+)=' \$(printf '\$1\033[1;32m\$2\033[0m=')"
function tm() {
tmux new-session -A -s ${1:-main}
}
# Ctrl-L clears buffer
function clear-scrollback-and-screen() {
echo -n -e '\e[2J\e[3J\e[1;1H'
zle clear-screen
tmux clear-history 2>/dev/null || true
}
zle -N clear-scrollback-and-screen
bindkey -v '^L' clear-scrollback-and-screen
# Private
if [ -f "$HOME/.zshrc-private" ]; then
source "$HOME/.zshrc-private"
fi