Add 1Password SSH Agent setup prompt before nvim config

- Add prompt_1password_setup() function to guide SSH Agent configuration
- Interactive mode: detailed setup instructions and wait for user confirmation
- Non-interactive mode: automatic SSH connection testing
- Test SSH connectivity to git.nas.astrian.moe before nvim config clone
- Enhanced error messaging in setup_neovim() with troubleshooting tips
- Integrated into both full_install() and dev_only() workflows
- Ensures proper SSH setup for private repository access

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Astrian Zheng 2025-06-28 11:44:44 +10:00
parent 777ee67eea
commit c46bc69bf4
Signed by: Astrian
SSH Key Fingerprint: SHA256:rVnhx3DAKjujCwWE13aDl7uV6+9U1MvydLkNRXJrBiA

View File

@ -317,6 +317,54 @@ setup_aliases() {
print_message "✅ 别名配置完成" "$GREEN" print_message "✅ 别名配置完成" "$GREEN"
} }
# 提示配置 1Password SSH Agent
prompt_1password_setup() {
print_message "🔐 配置 1Password SSH Agent..." "$BLUE"
# 检查 1Password 是否已安装
if [[ -d "/Applications/1Password 7 - Password Manager.app" ]] || [[ -d "/Applications/1Password.app" ]]; then
print_message "📱 检测到 1Password 已安装" "$GREEN"
# 检测是否为交互式执行
if [[ -t 0 ]]; then
# 交互式执行 - 提示用户配置
print_message "⚠️ 为了克隆 nvim 配置,需要先设置 1Password SSH Agent" "$YELLOW"
print_message "" "$NC"
print_message "📋 请按以下步骤配置:" "$YELLOW"
print_message " 1. 打开 1Password 应用并登录" "$YELLOW"
print_message " 2. 进入 Settings > Developer" "$YELLOW"
print_message " 3. 启用 'Use the SSH agent'" "$YELLOW"
print_message " 4. 将你的 SSH 私钥添加到 1Password" "$YELLOW"
print_message " 5. 确保 SSH 密钥可以访问 git.nas.astrian.moe" "$YELLOW"
print_message "" "$NC"
# 等待用户确认配置完成
read -p "⚡ 1Password SSH Agent 配置完成后请按回车键继续..." -r
echo ""
# 测试 SSH 连接
print_message "🔍 测试 SSH 连接..." "$BLUE"
if ssh -T git@git.nas.astrian.moe -o ConnectTimeout=10 -o BatchMode=yes 2>/dev/null; then
print_message "✅ SSH 连接测试成功!" "$GREEN"
return 0
else
print_message "⚠️ SSH 连接测试失败,但将继续执行" "$YELLOW"
print_message " 如果 nvim 配置克隆失败,请检查 SSH 配置" "$YELLOW"
fi
else
# 非交互式执行 - 自动尝试
print_message "🔍 自动检测 SSH 连接状态..." "$YELLOW"
if ssh -T git@git.nas.astrian.moe -o ConnectTimeout=10 -o BatchMode=yes 2>/dev/null; then
print_message "✅ SSH 连接可用" "$GREEN"
else
print_message "⚠️ SSH 连接不可用nvim 配置可能无法克隆" "$YELLOW"
fi
fi
else
print_message "⚠️ 未检测到 1Password跳过 SSH Agent 配置" "$YELLOW"
fi
}
# 配置 Neovim # 配置 Neovim
setup_neovim() { setup_neovim() {
print_message "⚙️ 配置 Neovim..." "$BLUE" print_message "⚙️ 配置 Neovim..." "$BLUE"
@ -332,7 +380,9 @@ setup_neovim() {
if git clone git@git.nas.astrian.moe:Astrian/nvim-config.git ~/.config/nvim 2>/dev/null; then if git clone git@git.nas.astrian.moe:Astrian/nvim-config.git ~/.config/nvim 2>/dev/null; then
print_message "✅ Neovim 配置已应用!" "$GREEN" print_message "✅ Neovim 配置已应用!" "$GREEN"
else else
print_message "⚠️ 无法克隆 nvim 配置SSH 密钥未配置)" "$YELLOW" print_message "⚠️ 无法克隆 nvim 配置" "$YELLOW"
print_message " 请确保已正确配置 1Password SSH Agent" "$YELLOW"
print_message " 或手动执行git clone git@git.nas.astrian.moe:Astrian/nvim-config.git ~/.config/nvim" "$YELLOW"
fi fi
fi fi
} }
@ -368,6 +418,7 @@ full_install() {
install_node install_node
install_claude_code install_claude_code
setup_aliases setup_aliases
prompt_1password_setup
setup_neovim setup_neovim
echo "" echo ""
@ -401,6 +452,7 @@ dev_only() {
install_oh_my_zsh install_oh_my_zsh
install_node install_node
install_claude_code install_claude_code
prompt_1password_setup
setup_neovim setup_neovim
print_message "✅ 开发环境配置完成!" "$GREEN" print_message "✅ 开发环境配置完成!" "$GREEN"
} }