#!/bin/zsh
# 检查Homebrew是否已安装
if ! command -v brew &> /dev/null; then
echo "错误:Homebrew未安装,请先手动安装Homebrew"
echo "安装命令:/bin/zsh -c \"\$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)\""
exit 1
fi
# 检查iTerm2是否已安装
if ! ls /Applications/iTerm.app &> /dev/null && ! ls /Applications/iTerm2.app &> /dev/null; then
echo "错误:iTerm2未安装,请先手动安装iTerm2"
echo "安装命令:brew install --cask iterm2"
exit 1
fi
echo "检测到Homebrew和iTerm2已安装,开始配置其他组件..."
# 检查Oh My Zsh是否已安装
if [ ! -d "$HOME/.oh-my-zsh" ]; then
echo "安装Oh My Zsh..."
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
# 备份新创建的.zshrc
cp ~/.zshrc ~/.zshrc.backup.$(date +%Y%m%d_%H%M%S)
else
echo "Oh My Zsh已安装,备份现有配置..."
cp ~/.zshrc ~/.zshrc.backup.$(date +%Y%m%d_%H%M%S) 2>/dev/null || true
fi
# 插件安装
echo "安装插件..."
brew install zsh-syntax-highlighting
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
brew install autojump
# Powerlevel10k主题安装
echo "安装Powerlevel10k主题..."
if [ ! -d "${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k" ]; then
git clone --depth=1 https://gitee.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
else
echo "Powerlevel10k主题已存在,跳过安装..."
fi
# 字体安装
echo "安装字体..."
brew tap homebrew/cask-fonts
brew install --cask font-hack-nerd-font
# Ruby和colorls安装
echo "安装Ruby和colorls..."
brew install ruby
# 使用用户安装方式,避免权限问题
gem install colorls --user-install
echo 'export PATH="$HOME/.gem/ruby/*/bin:$PATH"' >> ~/.zshrc
# 其他工具安装
echo "安装其他工具..."
brew install fzf
brew install tmux
git clone https://github.com/felixr/docker-zsh-completion ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/docker
# 配置.zshrc - 先清空现有内容,然后重新配置
echo "配置.zshrc文件..."
cat > ~/.zshrc << 'EOF'
# Path to your oh-my-zsh installation.
export ZSH="$HOME/.oh-my-zsh"
# 主题配置
ZSH_THEME="powerlevel10k/powerlevel10k"
# 插件配置
plugins=(git zsh-autosuggestions zsh-syntax-highlighting docker tmux)
# 加载Oh My Zsh
source $ZSH/oh-my-zsh.sh
# 语法高亮配置
source /opt/homebrew/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
# autojump配置
[ -f /opt/homebrew/etc/profile.d/autojump.sh ] && . /opt/homebrew/etc/profile.d/autojump.sh
# colorls配置
if command -v colorls &> /dev/null; then
source $(dirname $(gem which colorls))/tab_complete.sh
alias ll='colorls -lA --sd --gs --group-directories-first'
alias ls='colorls --group-directories-first'
alias lc='colorls'
alias l='colorls -l --sort-dirs'
alias la='colorls -la --sort-dirs'
alias lt='colorls -lt --git-status'
alias lS='colorls -lS --git-status'
alias lr='colorls --tree=5'
alias lx='colorls -lAX --git-status'
fi
# fzf配置
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
# 用户自定义配置
EOF
# 应用配置
echo "应用配置..."
source ~/.zshrc
echo "--------------------------------------------------"
echo "所有安装和配置已完成!"
echo "请手动完成以下步骤:"
echo "1. 在iTerm2中设置字体:"
echo " Preferences > Profiles > Text > Font > 选择'Hack Nerd Font'"
echo "2. 重启终端使所有更改生效"
echo "3. 运行 'exec zsh' 重新加载配置"
echo "4. 运行 'p10k configure' 配置Powerlevel10k主题"
echo "--------------------------------------------------"
留言