-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.sh
More file actions
64 lines (52 loc) · 1.25 KB
/
init.sh
File metadata and controls
64 lines (52 loc) · 1.25 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
# 交互式模式的初始化脚本
# 防止被加载两次
if [ -z "$_INIT_SH_LOADED" ]; then
_INIT_SH_LOADED=1
else
return
fi
# 如果是非交互式则退出,比如 bash test.sh 这种调用 bash 运行脚本时就不是交互式
# 只有直接敲 bash 进入的等待用户输入命令的那种模式才成为交互式,才往下初始化
case "$-" in
*i*) ;;
*) return
esac
# 将个人 ~/.local/bin 目录加入 PATH
if [ -d "$HOME/.local/bin" ]; then
export PATH="$HOME/.local/bin:$PATH"
fi
# 判断文件是否存在, 若存在, 则 source 一下
source_if_exists() {
file="$1"
if [ -f "$file" ]; then
source "$file"
fi
}
DOTFILES=$HOME/.local/.Cdotfiles
# zsh
. $DOTFILES/zsh/theme.zsh
. $DOTFILES/zsh/alias.zsh
source_if_exists ~/.zsh_profile
# clash
. $DOTFILES/clash/clash.zsh
# git
. $DOTFILES/git/alias.zsh
# tmux
. $DOTFILES/tmux/alias.zsh
# ssh
. $DOTFILES/ssh/batch_cmd
# 整理 PATH,删除重复路径
if [ -n "$PATH" ]; then
old_PATH=$PATH:; PATH=
while [ -n "$old_PATH" ]; do
x=${old_PATH%%:*}
case $PATH: in
*:"$x":*) ;;
*) PATH=$PATH:$x;;
esac
old_PATH=${old_PATH#*:}
done
PATH=${PATH#:}
unset old_PATH x
fi
export PATH