-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathterminal.sh
More file actions
executable file
·160 lines (143 loc) · 5.34 KB
/
terminal.sh
File metadata and controls
executable file
·160 lines (143 loc) · 5.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/bin/bash
# Set strict error handling
set -e
# Get the directory where the script is located
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
echo "============================================="
echo " Terminal AI Assistant Installer"
echo "============================================="
echo "Please select the tool you want to install:"
echo "1) Open Code (SST) [推荐优先使用]"
echo "2) Claude Code (Anthropic)"
echo "============================================="
read -p "Enter your choice [1-2]: " choice
case $choice in
1)
echo ""
echo "Starting installation of Open Code..."
echo "Official Website: https://opencode.ai/download"
echo "---------------------------------------------"
INSTALL_SCRIPT="$SCRIPT_DIR/terminal/open-code-install.sh"
;;
2)
echo ""
echo "Starting installation of Claude Code..."
echo "Official Website: https://claude.com/product/claude-code"
echo "---------------------------------------------"
INSTALL_SCRIPT="$SCRIPT_DIR/terminal/claude-code-install.sh"
;;
*)
echo "Invalid choice. Exiting."
exit 1
;;
esac
# Check if script exists
if [ ! -f "$INSTALL_SCRIPT" ]; then
echo "Error: Installation script not found at $INSTALL_SCRIPT"
exit 1
fi
# Make executable and run
chmod +x "$INSTALL_SCRIPT"
"$INSTALL_SCRIPT"
echo ""
echo "============================================="
echo " Post-Installation Configuration"
echo "============================================="
# Detect shell configuration file
SHELL_CONFIG=""
SHELL_NAME=$(basename "$SHELL")
if [ "$SHELL_NAME" = "zsh" ]; then
SHELL_CONFIG="$HOME/.zshrc"
elif [ "$SHELL_NAME" = "bash" ]; then
if [ "$(uname)" = "Darwin" ]; then
SHELL_CONFIG="$HOME/.bash_profile"
else
# Linux (CentOS, Ubuntu, etc.)
if [ -f "$HOME/.bashrc" ]; then
SHELL_CONFIG="$HOME/.bashrc"
elif [ -f "$HOME/.bash_profile" ]; then
SHELL_CONFIG="$HOME/.bash_profile"
fi
fi
fi
# Fallback detection
if [ -z "$SHELL_CONFIG" ] || [ ! -f "$SHELL_CONFIG" ]; then
if [ -f "$HOME/.zshrc" ]; then
SHELL_CONFIG="$HOME/.zshrc"
elif [ -f "$HOME/.bashrc" ]; then
SHELL_CONFIG="$HOME/.bashrc"
fi
fi
if [ -n "$SHELL_CONFIG" ] && [ -f "$SHELL_CONFIG" ]; then
echo "Detected shell configuration file: $SHELL_CONFIG"
# Check if we are in a subshell or sourced
# If the script is run as ./terminal.sh, source won't affect parent shell.
# We can try to exec a new shell to reload env, but that might be invasive.
# Instead, we will provide a very clear instruction.
echo "Refreshing system configuration in current script context..."
if source "$SHELL_CONFIG"; then
echo "✅ Configuration refreshed (for this script execution)."
fi
else
echo "⚠️ Could not automatically detect shell configuration file."
fi
echo ""
echo "============================================="
echo " ⚠️ IMPORTANT: ACTION REQUIRED ⚠️"
echo "============================================="
echo "To make the installed command available in your current terminal,"
echo "you MUST execute the following command manually:"
echo ""
if [ -n "$SHELL_CONFIG" ]; then
echo " source $SHELL_CONFIG"
else
echo " source ~/.bashrc # (or your shell's config file)"
fi
echo ""
echo "Alternatively, you can restart your terminal session."
echo "============================================="
echo ""
echo "============================================="
echo " Next Steps"
echo "============================================="
if [ "$choice" == "1" ]; then
echo "Open Code 安装完成!"
echo ""
echo "使用步骤:"
echo "1. 进入你的项目文件夹(任何一个都可以,也可以 mkdir 新建文件夹,进入后它负责管理这个文件夹下的内容):"
echo " cd /dev-ops"
echo ""
echo "2. 启动 Open Code:"
echo " opencode"
echo ""
echo "3. 在 Open Code 中:"
echo " - 常用命令:"
echo " • /help - 查看帮助"
echo " • /models - 选择模型(免费模型、智谱AI GLM、小米AI 等)"
echo " • /clear - 清空对话"
echo " • /exit - 退出"
echo " • /login - 登录账号"
echo " • /logout - 退出登录"
echo " • /status - 查看状态"
echo " • /config - 查看配置"
echo " • /history - 查看历史记录"
echo " • /save - 保存对话"
echo " • /load - 加载对话"
echo " • /alias - 设置别名"
echo " • /theme - 切换主题"
echo " • /debug - 调试模式"
echo ""
echo "4. 配置自定义全局模型(方便配置代理地址):"
echo " cd terminal"
echo " ./opencode.sh"
echo " 然后编辑(输入 i 之后编辑,编辑后点击 esc,之后输入 :wq 退出): vim /root/.config/opencode/opencode.json"
echo ""
echo "详细文档: https://opencode.ai/docs"
echo "配置MCP: https://opencode.ai/docs/mcp-servers/"
echo "工程代码: https://github.com/sst/opencode"
echo ""
elif [ "$choice" == "2" ]; then
echo "Please visit the official documentation to learn how to use Claude Code:"
echo "👉 https://claude.com/product/claude-code"
fi
echo "============================================="