-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon_shell_setup.sh
More file actions
392 lines (332 loc) · 11.3 KB
/
Copy pathcommon_shell_setup.sh
File metadata and controls
392 lines (332 loc) · 11.3 KB
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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
# useful alias
alias dirs="dirs -v"
alias rsy="rsync -avzP"
# lsd - modern ls replacement
if command -v lsd &> /dev/null; then
alias ls='lsd'
alias la='lsd -la'
alias ll='lsd -l'
alias lt='lsd --tree'
fi
# proxy
# function pc() {
# https_proxy=http://127.0.0.1:7890 \
# http_proxy=http://127.0.0.1:7890 \
# all_proxy=socks5://127.0.0.1:7891 \
# "$@"
# }
# alias pc="https_proxy=http://127.0.0.1:7890 http_proxy=http://127.0.0.1:7890 all_proxy=socks5://127.0.0.1:7891"
# The fuck
# command -v thefuck >/dev/null 2>&1 && eval $(thefuck --alias)
# cargo
export RUSTUP_DIST_SERVER="https://rsproxy.cn"
export RUSTUP_UPDATE_ROOT="https://rsproxy.cn/rustup"
[ -f ~/.cargo/env ] && source ~/.cargo/env
# hugo Proxy
export HUGO_MODULE_PROXY=https://goproxy.cn/,direct
# Preferred editor for local
if command -v nvim &> /dev/null; then
export EDITOR='nvim'
else
export EDITOR='vim'
fi
# cheat.sh
cheat(){
curl cheat.sh/$1;
}
# ranger
rr() {
ranger --choosedir="$HOME/.rangerdir"
cd "$(cat "$HOME/.rangerdir")"
}
# joshuto
jj() {
local output_file="$(mktemp)"
joshuto --output-file="$output_file" "$@"
local exit_code=$?
case "$exit_code" in
101)
local joshuto_cwd="$(cat "$output_file")"
[ -n "$joshuto_cwd" ] && [ "$joshuto_cwd" != "$(pwd)" ] && cd "$joshuto_cwd"
;;
esac
\rm -f "$output_file"
}
# yazi - exit to cwd
yy() {
local tmp="$(mktemp -t "yazi-cwd.XXXXXX")"
yazi "$@" --cwd-file="$tmp"
if cwd="$(command cat -- "$tmp")" && [ -n "$cwd" ] && [ "$cwd" != "$PWD" ]; then
builtin cd -- "$cwd"
fi
\rm -f -- "$tmp"
}
# iTerm2 shell integration
test -e "${HOME}/.iterm2_shell_integration.zsh" && source "${HOME}/.iterm2_shell_integration.zsh"
# Golang Proxy
if command -v go &> /dev/null; then
go env -w GO111MODULE=on
go env -w GOPROXY=https://mirrors.aliyun.com/goproxy/,direct
fi
# julia
export JULIA_PKG_SERVER=https://mirrors.tuna.tsinghua.edu.cn/julia
# docker
# rootless docker
# Reference
# - See NVIDIA CUDA container from https://hub.docker.com/r/nvidia/cuda/tags
docker-run(){
local volume_dir="$HOME/docker-volumes"
if [ $# -ne 2 ] && [ $# -ne 3 ]; then
echo "No Arguments specified.\nUsage:\n docker-run <image name> <container name> [number of gpus (1|2|all)]\n">&2;
return 1;
fi;
local container_name=$2
local mounted_home=$volume_dir/$container_name
mkdir -p $mounted_home
if [ $# -eq 2 ]; then
set -x
docker run -itd --restart=always --name $2 --network host -e TERM=$TERM \
-v $HOME:/host_data -v $mounted_home:/root -v /etc/localtime:/etc/localtime:ro \
--privileged \
$1 /bin/bash;
set +x
else
local gpus=$3
set -x
sudo docker run -itd --restart=always --name $2 --network host -e TERM=$TERM \
-v $HOME:/host_data -v $mounted_home:/root -v /etc/localtime:/etc/localtime:ro \
--privileged \
--gpus $gpus \
$1 /bin/bash;
set +x
fi;
}
docker-slave(){
if [ $# -ne 1 ]; then
echo "No Arguments specified.\nUsage:\n docker-slave <container name>\n">&2;
return 1;
fi;
docker exec -it $1 /bin/bash;
}
sudo-docker-slave(){
if [ $# -ne 1 ]; then
echo "No Arguments specified.\nUsage:\n docker-slave <container name>\n">&2;
return 1;
fi;
sudo docker exec -it $1 /bin/bash;
}
# docker with X11 forwarding support
# Reference: setup-gui-docker.md
docker-run-gui(){
local volume_dir="$HOME/docker-volumes"
if [ $# -ne 2 ] && [ $# -ne 3 ]; then
echo "No Arguments specified.\nUsage:\n docker-run-gui <image name> <container name> [number of gpus (1|2|all)]\n">&2;
return 1;
fi;
local container_name=$2
local mounted_home=$volume_dir/$container_name
mkdir -p $mounted_home
# Setup X11 forwarding
local XSOCK=/tmp/.X11-unix
local XAUTH=/tmp/.docker.xauth
xauth nlist $DISPLAY | sed -e 's/^..../ffff/' | xauth -f $XAUTH nmerge -
chmod 777 $XAUTH
if [ $# -eq 2 ]; then
set -x
docker run -itd --restart=always --name $2 --network host -e TERM=$TERM \
-e DISPLAY=$DISPLAY \
-e XAUTHORITY=$XAUTH \
-v $HOME:/host_data -v $mounted_home:/root -v /etc/localtime:/etc/localtime:ro \
-v $XSOCK:$XSOCK:ro \
-v $XAUTH:$XAUTH:ro \
--privileged \
$1 /bin/bash;
set +x
else
local gpus=$3
set -x
sudo docker run -itd --restart=always --name $2 --network host -e TERM=$TERM \
-e DISPLAY=$DISPLAY \
-e XAUTHORITY=$XAUTH \
-v $HOME:/host_data -v $mounted_home:/root -v /etc/localtime:/etc/localtime:ro \
-v $XSOCK:$XSOCK \
-v $XAUTH:$XAUTH \
--privileged \
--gpus $gpus \
$1 /bin/bash;
set +x
fi;
}
# Make mv and cp safer
OS=$(uname -s)
if [[ $OS == "Darwin" ]]; then
# Modified from https://apple.stackexchange.com/questions/17622/how-can-i-make-rm-move-files-to-the-trash-can
# - Correcting bad habits
alias rm='echo -e "Use rem for reversible delete, \\\\rm for regular delete"'
rem () {
setopt sh_word_split # handle filenames with properly escaped spaces
echo "Removing $*"
read "rem_resp?OK?(y/n) "
if [[ ${rem_resp} == "y" ]]; then
trash $*
else
echo "No action taken"
fi
}
elif [[ $OS == "Linux" ]]; then
# Use a safe deletion command instead of rm
# Credit to https://web.physics.wustl.edu/alford/linux/precautions.html
alias rm='echo -e "Use rem for reversible delete, \\\\rm for regular delete, wipe or srm for secure delete"'
rem () {
setopt sh_word_split # handle filenames with properly escaped spaces
echo "Removing $*"
read "rem_resp?OK?(y/n) "
if [[ ${rem_resp} == "y" ]]; then
mv --backup=numbered -t ~/.wastebasket $*
else
echo "No action taken"
fi
}
fi
if [[ $OS == "Darwin" ]]; then
alias mv='mv -i'
alias cp='cp -i'
elif [[ $OS == "Linux" ]]; then
alias mv='mv -i -b'
alias cp='cp -i -b'
fi
# vscode
[ -f ~/.vscoderc ] && source ~/.vscoderc
# setup path
export PATH=$HOME/.local/bin:$PATH
# add all private keys to ssh agent
if find "${HOME}/.ssh" -name "id_*" -print -quit | grep -q .; then
for possiblekey in ${HOME}/.ssh/id_*; do
if grep -q PRIVATE "$possiblekey" 2>/dev/null; then
ssh-add "$possiblekey" 2>/dev/null
fi
done
fi
export PATH="/opt/homebrew/opt/ruby/bin:$PATH"
# chatgpt.sh
export PATH="$PATH:$HOME/.chatgpt"
# lazygit
alias lg='lazygit'
# rg + fzf interactive search
rgf() {
local pattern="${1:?Usage: rgf <pattern>}"
rg -l "$pattern" | fzf --preview "rg -n --color=always -C 3 '$pattern' {}"
}
# zellij
alias zj="zellij"
# flutter
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
# cursor
alias cs='cursor'
# native claude code
cc() {
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1 \
CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1 \
API_TIMEOUT_MS=600000 \
claude --dangerously-skip-permissions "$@"
}
# cc-gateway claude code
ccg() {
local ccg_bin
ccg_bin=$(find "$HOME/.cc-gateway/clients" -maxdepth 1 -type f -name "cc-*" | head -n 1)
if [[ -n "$ccg_bin" ]]; then
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1 \
CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1 \
API_TIMEOUT_MS=600000 \
"$ccg_bin" --dangerously-skip-permissions "$@"
else
echo "No ccg client found in $HOME/.cc-gateway/clients/" >&2
return 1
fi
}
# opencode
oc() {
opencode "$@"
}
export PATH="$PATH:$HOME/.opencode/bin"
# google gemini cli (override oh-my-zsh git plugin's gm='git merge')
unalias gm 2>/dev/null
gm() {
gemini --yolo "$@"
}
# claude code with deepseek API
# Reference: https://api-docs.deepseek.com/guides/anthropic_api
_claude_with_api() {
local model="$1" base_url="$2" api_key="$3" binary="${4:-claude}"
shift 4
env -u ANTHROPIC_API_KEY \
ANTHROPIC_BASE_URL="$base_url" \
ANTHROPIC_AUTH_TOKEN="$api_key" \
API_TIMEOUT_MS=600000 \
ANTHROPIC_MODEL="$model" \
ANTHROPIC_DEFAULT_SONNET_MODEL="$model" \
ANTHROPIC_DEFAULT_OPUS_MODEL="$model" \
ANTHROPIC_DEFAULT_HAIKU_MODEL="$model" \
ANTHROPIC_SMALL_FAST_MODEL="$model" \
CLAUDE_CODE_SUBAGENT_MODEL="$model" \
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1 \
CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1 \
"$binary" "$@" --dangerously-skip-permissions
}
dscc() { _claude_with_api "deepseek-v4-flash[1m]" "https://api.deepseek.com/anthropic" "${DEEPSEEK_API_KEY}" claude "$@"; }
dsccpro() { _claude_with_api "deepseek-v4-pro[1m]" "https://api.deepseek.com/anthropic" "${DEEPSEEK_API_KEY}" claude "$@"; }
dsccpro2() { _claude_with_api "deepseek-v4-pro[1m]" "https://ark.cn-beijing.volces.com/api/coding" "${VE_CODE_API_KEY}" claude "$@"; }
autocc() { _claude_with_api "ark-code-latest" "https://ark.cn-beijing.volces.com/api/coding" "${VE_CODE_API_KEY}" claude "$@"; }
sdcc() { _claude_with_api "doubao-seed-2.0-lite" "https://ark.cn-beijing.volces.com/api/coding" "${VE_CODE_API_KEY}" claude "$@"; }
sdccmini(){ _claude_with_api "doubao-seed-2-0-mini-260215" "https://ark.cn-beijing.volces.com/api/compatible" "${SD2MINI_API_KEY}" claude "$@"; }
sdccpro() { _claude_with_api "doubao-seed-2.0-pro" "https://ark.cn-beijing.volces.com/api/coding" "${VE_CODE_API_KEY}" claude "$@"; }
kmcc() { _claude_with_api "kimi-for-coding" "https://api.kimi.com/coding/" "${KIMI_CODE_API_KEY}" claude "$@"; }
kmcc2() { _claude_with_api "kimi-k2.6" "https://api.moonshot.cn/anthropic" "${KIMI_API_KEY}" claude "$@"; }
kmcc3() { _claude_with_api "kimi-k2.6" "https://ark.cn-beijing.volces.com/api/coding" "${VE_CODE_API_KEY}" claude "$@"; }
mxcc() { _claude_with_api "MiniMax-M2.7" "https://api.minimaxi.com/anthropic" "${MM_CODE_API_KEY}" claude "$@"; }
mmcc() { _claude_with_api "mimo-v2-pro" "https://token-plan-cn.xiaomimimo.com/anthropic" "${MIMO_CODE_API_KEY}" claude "$@"; }
glmcc() { _claude_with_api "glm-5.1" "https://ark.cn-beijing.volces.com/api/coding" "${VE_CODE_API_KEY}" claude "$@"; }
glmcc2() { _claude_with_api "Pro/zai-org/GLM-5.1" "https://api.siliconflow.cn/" "${SLFLOW_API_KEY}" claude "$@"; }
hglmcc() { _claude_with_api "glm-5.1" "https://ark.cn-beijing.volces.com/api/coding" "${VE_CODE_API_KEY}" happy "$@"; }
hglmcc2() { _claude_with_api "Pro/zai-org/GLM-5.1" "https://api.siliconflow.cn/" "${SLFLOW_API_KEY}" happy "$@"; }
# uv - Python package manager
# uv installs to ~/.local/bin by default
export PATH="$HOME/.local/bin:$PATH"
# uv Python mirror for China
export UV_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple
# Activate global uv venv at ~/.venv
if [ -d "$HOME/.venv" ]; then
source "$HOME/.venv/bin/activate"
fi
# codex environment setup
[ -f ~/.codex/codex_env.sh ] && source ~/.codex/codex_env.sh
# zoxide - smart cd
if command -v zoxide &> /dev/null; then
if [ -n "$ZSH_VERSION" ]; then
eval "$(zoxide init zsh)"
elif [ -n "$BASH_VERSION" ]; then
eval "$(zoxide init bash)"
fi
fi
# starship - cross-shell prompt
if command -v starship &> /dev/null; then
export STARSHIP_CONFIG=~/.config/starship.toml
if [ -n "$ZSH_VERSION" ]; then
eval "$(starship init zsh)"
elif [ -n "$BASH_VERSION" ]; then
eval "$(starship init bash)"
fi
fi
# bat - cat with syntax highlighting
if command -v bat &> /dev/null; then
alias cat='bat'
elif command -v batcat &> /dev/null; then
alias cat='batcat'
alias bat='batcat'
fi
# better color for claude code
export COLORTERM=truecolor
[ -f ~/.common_shell_setup_local.sh ] && source ~/.common_shell_setup_local.sh
# Added by Antigravity
[ -f ~/.antigravity/antigravity/bin/antigravity ] && export PATH="$PATH:$HOME/.antigravity/antigravity/bin"