136 lines
3.0 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 设置错误时立即退出
set -e
# 颜色定义
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# 日志函数
log_info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
log_warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# 安装zsh-autosuggestions
install_zsh_autosuggestions() {
log_info "安装zsh-autosuggestions..."
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
}
# 安装zsh-syntax-highlighting
install_zsh_syntax_highlighting() {
log_info "安装zsh-syntax-highlighting..."
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
}
# 安装zsh-completions
install_zsh_completions() {
log_info "安装zsh-completions..."
git clone https://github.com/zsh-users/zsh-completions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-completions
}
# 安装autojump
install_autojump() {
log_info "安装autojump..."
apt-get install -y autojump
}
# 安装fzf
install_fzf() {
log_info "安装fzf..."
apt-get install -y fzf
}
# 安装zsh-nvm
install_zsh_nvm() {
log_info "安装zsh-nvm..."
git clone https://github.com/lukechilds/zsh-nvm ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-nvm
}
# 安装pyenv
install_pyenv() {
log_info "安装pyenv..."
curl https://pyenv.run | bash
}
# 配置fzf
configure_fzf() {
log_info "配置fzf..."
# 安装fzf键绑定和补全
$(brew --prefix)/opt/fzf/install --all
# 添加fzf配置到.zshrc
cat >> ~/.zshrc << EOF
# fzf配置
export FZF_DEFAULT_OPTS='--height 40% --layout=reverse --border'
export FZF_DEFAULT_COMMAND='fd --type f'
export FZF_CTRL_T_COMMAND='\$FZF_DEFAULT_COMMAND'
export FZF_CTRL_T_OPTS="--preview 'bat --color=always --line-range=:500 {}'"
export FZF_CTRL_R_OPTS="--preview 'echo {}' --preview-window down:3:hidden:wrap --bind '?:toggle-preview'"
export FZF_ALT_C_OPTS="--preview 'tree -C {} | head -200'"
EOF
}
# 配置pyenv
configure_pyenv() {
log_info "配置pyenv..."
# 添加pyenv配置到.zshrc
cat >> ~/.zshrc << EOF
# pyenv配置
export PYENV_ROOT="\$HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="\$PYENV_ROOT/bin:\$PATH"
eval "\$(pyenv init -)"
EOF
}
# 配置autojump
configure_autojump() {
log_info "配置autojump..."
# 添加autojump配置到.zshrc
cat >> ~/.zshrc << EOF
# autojump配置
. /usr/share/autojump/autojump.sh
EOF
}
# 主函数
main() {
log_info "开始安装Zsh插件..."
# 安装插件
install_zsh_autosuggestions
install_zsh_syntax_highlighting
install_zsh_completions
install_autojump
install_fzf
install_zsh_nvm
install_pyenv
# 配置插件
configure_fzf
configure_pyenv
configure_autojump
log_info "Zsh插件安装完成"
log_info "请重新加载.zshrc以应用更改source ~/.zshrc"
}
# 执行主函数
main