Repository navigation
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·185 lines (160 loc) · 5.31 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·185 lines (160 loc) · 5.31 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/bin/bash
# setup.sh — Install cc-tmux-menu
set -e
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
RED='\033[0;31m'
CYAN='\033[0;36m'
BOLD='\033[1m'
DIM='\033[2m'
NC='\033[0m'
INSTALL_DIR="${HOME}/.local/bin"
CONFIG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/cc-tmux-menu"
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
echo ""
echo -e "${BOLD}cc-tmux-menu${NC} — Interactive tmux session manager with AI previews"
echo ""
# === Check dependencies ===
echo -e "${BOLD}Checking dependencies...${NC}"
missing=()
for cmd in tmux; do
if command -v "$cmd" &>/dev/null; then
echo -e " ${GREEN}✓${NC} $cmd"
else
echo -e " ${RED}✗${NC} $cmd (required)"
missing+=("$cmd")
fi
done
if [[ ${#missing[@]} -gt 0 ]]; then
echo ""
echo -e "${RED}Missing: ${missing[*]}${NC}"
echo "Install them and try again."
exit 1
fi
echo ""
# === Build or use pre-built binary ===
echo -e "${BOLD}Installing...${NC}"
mkdir -p "$INSTALL_DIR"
if [[ -f "$SCRIPT_DIR/cc-tmux-menu" ]]; then
# Pre-built binary exists
cp "$SCRIPT_DIR/cc-tmux-menu" "$INSTALL_DIR/cc-tmux-menu"
chmod +x "$INSTALL_DIR/cc-tmux-menu"
echo -e " ${GREEN}✓${NC} Copied pre-built binary to ${CYAN}${INSTALL_DIR}/cc-tmux-menu${NC}"
elif command -v go &>/dev/null; then
# Build from source
echo -e " Building from source..."
(cd "$SCRIPT_DIR" && go build -o "$INSTALL_DIR/cc-tmux-menu" ./cmd/cc-tmux-menu)
echo -e " ${GREEN}✓${NC} Built and installed to ${CYAN}${INSTALL_DIR}/cc-tmux-menu${NC}"
else
echo -e " ${RED}✗${NC} No pre-built binary found and Go is not installed."
echo " Install Go (https://go.dev/dl/) or place a pre-built binary in this directory."
exit 1
fi
if ! echo "$PATH" | tr ':' '\n' | grep -qx "$INSTALL_DIR"; then
echo -e " ${YELLOW}!${NC} ${INSTALL_DIR} is not in PATH. Add to your shell profile:"
echo -e " ${CYAN}export PATH=\"\$HOME/.local/bin:\$PATH\"${NC}"
fi
echo ""
# === Configuration ===
echo -e "${BOLD}Configuration${NC}"
mkdir -p "$CONFIG_DIR"
existing_config=""
if [[ -f "$CONFIG_DIR/config.toml" ]]; then
existing_config="$CONFIG_DIR/config.toml"
elif [[ -f "$CONFIG_DIR/config" ]]; then
existing_config="$CONFIG_DIR/config"
fi
if [[ -n "$existing_config" ]]; then
echo -e " Config exists: ${CYAN}${existing_config}${NC}"
read -p " Overwrite? [y/N] " overwrite
if [[ "$overwrite" != "y" && "$overwrite" != "Y" ]]; then
echo -e " Keeping existing config.\n"
echo -e "${GREEN}${BOLD}Done!${NC} Run ${CYAN}cc-tmux-menu${NC} to start."
exit 0
fi
echo ""
fi
# OpenRouter API key
echo -e " ${BOLD}OpenRouter API Key${NC} ${DIM}(for AI session summaries)${NC}"
echo -e " Get one at: ${CYAN}https://openrouter.ai/keys${NC}"
echo -e " Leave empty to skip — summaries will be disabled."
read -p " API Key: " api_key
echo ""
# Model
default_model="google/gemini-2.0-flash-001"
echo -e " ${BOLD}AI Model${NC} ${DIM}(for summaries, cheap & fast recommended)${NC}"
echo -e " Default: ${CYAN}${default_model}${NC}"
read -p " Model [${default_model}]: " model
model="${model:-$default_model}"
echo ""
# Work directory
echo -e " ${BOLD}Work Directory${NC} ${DIM}(for new Claude Code sessions)${NC}"
read -p " Directory [~]: " work_dir
work_dir="${work_dir:-~}"
echo ""
# Language
echo -e " ${BOLD}Summary Language${NC} ${DIM}(en, zh-TW, ja, ko, ...)${NC}"
read -p " Language [en]: " lang
lang="${lang:-en}"
echo ""
# Remote host
echo -e " ${BOLD}Remote SSH Host${NC} ${DIM}(optional, adds SSH option to menu)${NC}"
read -p " Host (empty to skip): " remote_host
remote_user=""
if [[ -n "$remote_host" ]]; then
read -p " User [$(whoami)]: " remote_user
remote_user="${remote_user:-$(whoami)}"
fi
echo ""
# Write config (TOML format)
cat > "$CONFIG_DIR/config.toml" << EOF
# cc-tmux-menu configuration
# Generated by setup.sh on $(date +%Y-%m-%d)
openrouter_api_key = "${api_key}"
openrouter_model = "${model}"
work_dir = "${work_dir}"
summary_lang = "${lang}"
claude_cmd = "claude"
remote_host = "${remote_host}"
remote_user = "${remote_user}"
preview_cache_ttl = 1800
EOF
chmod 600 "$CONFIG_DIR/config.toml"
echo -e " ${GREEN}✓${NC} Config saved to ${CYAN}${CONFIG_DIR}/config.toml${NC}"
echo ""
# === Shell integration ===
echo -e "${BOLD}Shell Integration${NC}"
echo " Auto-launch cc-tmux-menu when you open a terminal?"
read -p " Add to shell profile? [y/N] " add_shell
if [[ "$add_shell" == "y" || "$add_shell" == "Y" ]]; then
shell_rc=""
if [[ -f "$HOME/.zshrc" ]]; then
shell_rc="$HOME/.zshrc"
elif [[ -f "$HOME/.bashrc" ]]; then
shell_rc="$HOME/.bashrc"
fi
if [[ -n "$shell_rc" ]]; then
if ! grep -q 'cc-tmux-menu' "$shell_rc" 2>/dev/null; then
cat >> "$shell_rc" << 'SHELL_RC'
# cc-tmux-menu: auto-launch (only outside tmux, interactive shell)
if [[ -z "$TMUX" && $- == *i* ]] && command -v cc-tmux-menu &>/dev/null; then
cc-tmux-menu
fi
SHELL_RC
echo -e " ${GREEN}✓${NC} Added to ${CYAN}${shell_rc}${NC}"
else
echo -e " ${YELLOW}!${NC} Already in ${shell_rc}"
fi
else
echo -e " ${YELLOW}!${NC} Shell profile not found. Add manually:"
echo -e ' if [[ -z "$TMUX" && $- == *i* ]] && command -v cc-tmux-menu &>/dev/null; then'
echo -e ' cc-tmux-menu'
echo -e ' fi'
fi
fi
echo ""
echo -e "${GREEN}${BOLD}Setup complete!${NC}"
echo ""
echo -e " Run: ${CYAN}cc-tmux-menu${NC}"
echo -e " Config: ${CYAN}${CONFIG_DIR}/config.toml${NC}"
echo ""