-
Notifications
You must be signed in to change notification settings - Fork 2
/
custom_env.zsh
131 lines (106 loc) · 3.12 KB
/
custom_env.zsh
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
# https://stackoverflow.com/a/65142525
export VISUAL=$ZSH_CUSTOM/shells/code-wait.sh
export EDITOR=$ZSH_CUSTOM/shells/code-wait.sh
export GITHUB_NAME="Wxh16144"
# /Users/{username} => ~
export APP=$HOME/Library/Application\ Support
# chrome://apps PWA
export CHROME_APP=$HOME/Applications/Chrome\ Apps.localized
export ICLOUD=$HOME/Library/Mobile\ Documents/com~apple~CloudDocs
# local_packages
export PKG=$ICLOUD/local_packages
# Increase Bash history size. Allow 32³ entries; the default is 1000.
export HISTSIZE='32768'
export HISTFILESIZE="${HISTSIZE}"
# 配置文件, 本地 Docker 配置、Dotfiles 仓库
export CONFIG="$HOME/Config"
# 个人脚本,crontab、raycast 等
export SCRIPTS="$HOME/Scripts"
# 和代码有关
export WORKSPACE="$HOME/Code"
# 纯粹的公司项目
export COMPANY=$WORKSPACE/company
# 公司项目归档,仅归属于自己的项目(请不要放合同之内的项目,避免纠纷)
export COMPANY_ARCHIVE=$WORKSPACE/company_archive
# 开源项目
export OSS=$WORKSPACE/oss
# 纯粹的自己的项目
export MY=$WORKSPACE/self
# 演练项目
export PLAY=$WORKSPACE/playground
# 比如 VSCode 的 workspace
export IDE_WORKSPACE=$WORKSPACE/workspace
# 本地数据文件夹, 一定得记得定期备份(不放 ICloud 是因为太大了)
export ARCHIVE=$HOME/Archive
# registry
# export COMPANY_NPM_REGISTRY="https://packages.aliyun.com/616ff38165b9775dd591fcc9/npm/npm-registry/"
export SELF_NPM_REGISTRY="http://localhost:10188/"
# export COMPANY_DOCKER_REGISTRY="https://example.com"
# git 备份上游 remote
export BACKUP_REMOTE_NAME="backup"
# temp
# https://apple.stackexchange.com/a/22716
# https://iboysoft.com/wiki/tmp-folder-mac.html
export OSX_TMPDIR=$TMPDIR
export TMP=/var/tmp
# 临时日志文件, crontab 任务产生的日志
export LOGS=$TMP/$(whoami)-tmp-logs
# ====== footer ====== #
function __internal_ensure_dir() {
local dirs=(
$CONFIG
$SCRIPTS
$WORKSPACE
$IDE_WORKSPACE
$COMPANY
$COMPANY_ARCHIVE
$OSS
$MY
$PLAY
# other
$ARCHIVE
$PKG
$LOGS
)
for dir in ${dirs[@]}; do
if [ ! -d $dir ]; then
mkdir -p $dir
fi
done
local hidden_dirs=(
$CONFIG
$SCRIPTS
$WORKSPACE
$IDE_WORKSPACE
$ARCHIVE
)
for dir in ${hidden_dirs[@]}; do
chflags hidden $dir
done
}
function __internal_ensure_symlink() {
# 定义二维数组 [实际目标, 软连接]
declare -A symlinks
symlinks=(
[$TMPDIR]="${ICLOUD}/Temporary"
[$TMP]="${ICLOUD}/Private_var_tmp"
[$HOME/Desktop]="${ICLOUD}/Desktop"
[$HOME/Documents]="${ICLOUD}/Documents"
[$LOGS]="${ICLOUD}/$(whoami)-logs"
)
for target in ${(@k)symlinks}; do
link=${symlinks[$target]}
# 如果 link 存在,但是无效,则删除 link
if [ -L $link ] && [ ! -e $link ]; then
# print_yellow "Removing broken symlink: $link"
/bin/rm $link
fi
# 如果 target 存在, 但 link 不存在, 则创建 link
if [ -d $target ] && [ ! -L $link ]; then
# print_yellow "Creating symlink: $link -> $target" # 可作为调试用
ln -s $target $link
fi
done
}
__internal_ensure_dir
__internal_ensure_symlink