mgmt/configuration/zsh/test-plugins.sh

152 lines
4.1 KiB
Bash
Executable File
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
# 测试 ZSH 插件是否正确安装
set -euo pipefail
# 颜色定义
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
log_info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
log_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
log_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
test_plugin() {
local plugin_name="$1"
local plugin_path="$2"
if [[ -d "$plugin_path" ]]; then
log_success "$plugin_name 已安装"
return 0
else
log_error "$plugin_name 未安装: $plugin_path"
return 1
fi
}
test_alias() {
local alias_name="$1"
if alias "$alias_name" &>/dev/null; then
log_success "✓ 别名 $alias_name 已加载"
return 0
else
log_warning "✗ 别名 $alias_name 未加载"
return 1
fi
}
main() {
log_info "测试 ZSH 插件和配置..."
echo ""
local failed=0
# 测试 oh-my-zsh 安装
log_info "检查 oh-my-zsh 安装..."
if [[ -d "$HOME/.oh-my-zsh" ]]; then
log_success "✓ oh-my-zsh 已安装"
else
log_error "✗ oh-my-zsh 未安装"
((failed++))
fi
echo ""
# 测试自定义插件
log_info "检查自定义插件..."
test_plugin "zsh-autosuggestions" "$HOME/.oh-my-zsh/custom/plugins/zsh-autosuggestions" || ((failed++))
test_plugin "zsh-syntax-highlighting" "$HOME/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting" || ((failed++))
test_plugin "zsh-completions" "$HOME/.oh-my-zsh/custom/plugins/zsh-completions" || ((failed++))
echo ""
# 测试内置插件
log_info "检查内置插件..."
test_plugin "git" "$HOME/.oh-my-zsh/plugins/git" || ((failed++))
test_plugin "docker" "$HOME/.oh-my-zsh/plugins/docker" || ((failed++))
test_plugin "ansible" "$HOME/.oh-my-zsh/plugins/ansible" || ((failed++))
test_plugin "terraform" "$HOME/.oh-my-zsh/plugins/terraform" || ((failed++))
test_plugin "kubectl" "$HOME/.oh-my-zsh/plugins/kubectl" || ((failed++))
echo ""
# 测试自定义别名文件
log_info "检查自定义别名..."
if [[ -f "$HOME/.oh-my-zsh/custom/aliases.zsh" ]]; then
log_success "✓ 自定义别名文件已安装"
else
log_warning "✗ 自定义别名文件未安装"
fi
echo ""
# 测试一些关键别名
log_info "检查关键别名..."
test_alias "mgmt" || ((failed++))
test_alias "dps" || ((failed++))
test_alias "k" || ((failed++))
test_alias "gs" || ((failed++))
echo ""
# 测试 .zshrc 文件
log_info "检查 .zshrc 配置..."
if [[ -f "$HOME/.zshrc" ]]; then
log_success "✓ .zshrc 文件存在"
# 检查关键配置
if grep -q "zsh-autosuggestions" "$HOME/.zshrc"; then
log_success "✓ zsh-autosuggestions 已配置"
else
log_warning "✗ zsh-autosuggestions 未配置"
fi
if grep -q "zsh-syntax-highlighting" "$HOME/.zshrc"; then
log_success "✓ zsh-syntax-highlighting 已配置"
else
log_warning "✗ zsh-syntax-highlighting 未配置"
fi
if grep -q "agnoster" "$HOME/.zshrc"; then
log_success "✓ agnoster 主题已配置"
else
log_warning "✗ agnoster 主题未配置"
fi
else
log_error "✗ .zshrc 文件不存在"
((failed++))
fi
echo ""
# 总结
if [[ $failed -eq 0 ]]; then
log_success "🎉 所有测试通过ZSH 配置完整。"
echo ""
log_info "使用方法:"
echo " - 重新登录或运行: source ~/.zshrc"
echo " - 测试自动建议: 输入 'docker' 然后按 → 键"
echo " - 测试别名: 运行 'mgmt-status' 或 'dps'"
else
log_error "❌ 发现 $failed 个问题,请检查安装。"
echo ""
log_info "修复建议:"
echo " 1. 重新运行安装脚本"
echo " 2. 检查网络连接"
echo " 3. 手动安装缺失的插件"
fi
}
main "$@"