Skip to content

Commit 8edf0c5

Browse files
committed
feat(macos): 添加macOS环境初始化脚本
添加01install.sh用于安装homebrew和powershell等基础环境 添加02install.ps1用于通过homebrew安装应用 添加.zshrc配置文件设置环境变量和工具初始化
1 parent 2b4c90f commit 8edf0c5

3 files changed

Lines changed: 83 additions & 0 deletions

File tree

linux/macos/01install.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#! /bin/zsh
2+
# 这个脚本安装homebrew,powershell这类基础的环境
3+
# 之后可以执行powershell脚本来安装其他软件
4+
5+
command_exists() {
6+
command -v "$*" >/dev/null 2>&1
7+
}
8+
config_zshrc(){
9+
if [ -e ~/.zshrc ]; then
10+
cp ~/.zshrc ~/.zshrc.bak-"$(date +%s)"
11+
rm ~/.zshrc
12+
fi
13+
14+
script_path=$(
15+
cd $(dirname $0) || exit
16+
pwd
17+
)
18+
19+
echo "script_path:$script_path"
20+
# 使用软链接映射zhsrc文件到目标
21+
ln -s "$script_path/config/.zshrc" ~/.zshrc
22+
}
23+
install_brew(){
24+
if ! command_exists brew; then
25+
echo 'Installing brew...'
26+
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
27+
# 配置 .zshrc
28+
config_zshrc
29+
fi
30+
}
31+
32+
install_pwsh(){
33+
if ! command_exists pwsh; then
34+
echo 'Installing pwsh...'
35+
brew install --cask powershell
36+
fi
37+
}
38+
39+
install_uv(){
40+
if ! command_exists uv; then
41+
echo 'Installing uv...'
42+
# On macOS and Linux.
43+
curl -LsSf https://astral.sh/uv/install.sh | sh
44+
fi
45+
}
46+
47+
install(){
48+
install_brew
49+
config_zshrc
50+
install_pwsh
51+
# install_uv
52+
}
53+
54+
55+
56+
install

linux/macos/02install.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
$modulePath = Resolve-Path -Path (Join-Path $PSScriptRoot '../../psutils')
3+
Import-Module -Name $modulePath
4+
5+
$configPath = (Resolve-Path -Path (Join-Path $PSScriptRoot '../../profile/installer/apps-config.json')).Path
6+
Install-PackageManagerApps -PackageManager 'homebrew' -ConfigPath $configPath

linux/macos/config/.zshrc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# homebrew bin path
2+
export PATH="/opt/homebrew/bin:$PATH"
3+
# uv 目录
4+
export PATH="$HOME/.local/bin:$PATH"
5+
6+
# pyenv相关配置
7+
export PYENV_ROOT="$HOME/.pyenv"
8+
[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"
9+
eval "$(pyenv init - zsh)"
10+
11+
command_exists() {
12+
command -v "$*" >/dev/null 2>&1
13+
}
14+
15+
# fnm
16+
if command_exists fnm; then
17+
eval "$(fnm env --use-on-cd --shell zsh)"
18+
fi
19+
20+
21+

0 commit comments

Comments
 (0)