-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
270 lines (233 loc) · 9.94 KB
/
Copy pathinstall.sh
File metadata and controls
270 lines (233 loc) · 9.94 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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
#!/usr/bin/env bash
set -e # Exit on error
# Colors for output
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
INSTALL_DIR="$HOME/.local/bin"
WT_TOOLS_DIR="$INSTALL_DIR/git-wt-tools"
CTX_TOOLS_DIR="$INSTALL_DIR/dx-ctx-tools"
DX_SKILLS_TOOLS_DIR="$INSTALL_DIR/dx-skills-tools"
DX_NB_TOOLS_DIR="$INSTALL_DIR/dx-nb-tools"
REPO_RAW_URL="https://raw.githubusercontent.com/mukeshmk/devex-manager/main"
# Detect if we are running from a local clone or remotely via curl
# When piped to bash, BASH_SOURCE[0] is often empty or '-'
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd 2>/dev/null || pwd)"
IS_REMOTE=false
if [[ ! -f "$SCRIPT_DIR/git-wt" ]]; then
IS_REMOTE=true
# Check for curl if remote
if ! command -v curl &> /dev/null; then
echo -e "${RED}Error: 'curl' is required for remote installation.${NC}"
exit 1
fi
fi
# Helper to fetch files (local or remote)
fetch_file() {
local src_path="$1"
local dest_path="$2"
if [ "$IS_REMOTE" = true ]; then
curl -fsSL "$REPO_RAW_URL/$src_path" -o "$dest_path"
else
cp "$SCRIPT_DIR/$src_path" "$dest_path"
fi
}
echo -e "${BLUE}Installing DevEx Manager...${NC}"
if [ "$IS_REMOTE" = true ]; then
echo -e "${BLUE}Mode: Remote installation from GitHub${NC}"
else
echo -e "${BLUE}Mode: Local installation${NC}"
fi
# 1. Create the destination directories
mkdir -p "$INSTALL_DIR"
mkdir -p "$WT_TOOLS_DIR"
mkdir -p "$DX_SKILLS_TOOLS_DIR"
mkdir -p "$DX_NB_TOOLS_DIR"
# 2. Copy executable files
echo "Installing routers and tools to $INSTALL_DIR..."
fetch_file "git-wt" "$INSTALL_DIR/git-wt"
fetch_file "dx" "$INSTALL_DIR/dx"
echo "Installing worktree sub-commands to $WT_TOOLS_DIR..."
fetch_file "git-wt-tools/git-wt-clone" "$WT_TOOLS_DIR/git-wt-clone"
fetch_file "git-wt-tools/git-wt-add" "$WT_TOOLS_DIR/git-wt-add"
fetch_file "git-wt-tools/git-wt-rm" "$WT_TOOLS_DIR/git-wt-rm"
fetch_file "git-wt-tools/git-wt-clean" "$WT_TOOLS_DIR/git-wt-clean"
fetch_file "git-wt-tools/git-wt-status" "$WT_TOOLS_DIR/git-wt-status"
fetch_file "git-wt-tools/git-wt-sync" "$WT_TOOLS_DIR/git-wt-sync"
fetch_file "git-wt-tools/devex-lib.sh" "$WT_TOOLS_DIR/devex-lib.sh"
echo "Installing dx skills tools to $DX_SKILLS_TOOLS_DIR..."
fetch_file "dx-skills-tools/dx-skills" "$DX_SKILLS_TOOLS_DIR/dx-skills"
fetch_file "dx-skills-tools/dx-skills-lib.sh" "$DX_SKILLS_TOOLS_DIR/dx-skills-lib.sh"
fetch_file "dx-skills-tools/dx-skills-list" "$DX_SKILLS_TOOLS_DIR/dx-skills-list"
fetch_file "dx-skills-tools/dx-skills-sync" "$DX_SKILLS_TOOLS_DIR/dx-skills-sync"
fetch_file "dx-skills-tools/dx-skills-diff" "$DX_SKILLS_TOOLS_DIR/dx-skills-diff"
fetch_file "dx-skills-tools/dx-skills-edit" "$DX_SKILLS_TOOLS_DIR/dx-skills-edit"
fetch_file "dx-skills-tools/dx-skills-rm" "$DX_SKILLS_TOOLS_DIR/dx-skills-rm"
echo "Installing dx notebook tools to $DX_NB_TOOLS_DIR..."
fetch_file "dx-nb-tools/dx-nb" "$DX_NB_TOOLS_DIR/dx-nb"
fetch_file "dx-nb-tools/dx-nb-strip" "$DX_NB_TOOLS_DIR/dx-nb-strip"
fetch_file "dx-nb-tools/dx-nb-diff" "$DX_NB_TOOLS_DIR/dx-nb-diff"
fetch_file "dx-nb-tools/dx-nb-kernel" "$DX_NB_TOOLS_DIR/dx-nb-kernel"
fetch_file "dx-nb-tools/dx-nb-list" "$DX_NB_TOOLS_DIR/dx-nb-list"
# Ask if user wants to install dx-ctx
INSTALL_DX_CTX=false
echo -e "\n${YELLOW}Would you like to install the dx-ctx (Developer Context Manager) tools?${NC}"
read -p "(y/n) " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]; then
INSTALL_DX_CTX=true
fi
if [ "$INSTALL_DX_CTX" = true ]; then
mkdir -p "$CTX_TOOLS_DIR"
fetch_file "dx-ctx-tools/dx-ctx" "$CTX_TOOLS_DIR/dx-ctx"
echo "Installing context sub-commands to $CTX_TOOLS_DIR..."
fetch_file "dx-ctx-tools/dx-ctx-helper.sh" "$CTX_TOOLS_DIR/dx-ctx-helper.sh"
fetch_file "dx-ctx-tools/dx-ctx-show" "$CTX_TOOLS_DIR/dx-ctx-show"
fetch_file "dx-ctx-tools/dx-ctx-edit" "$CTX_TOOLS_DIR/dx-ctx-edit"
fetch_file "dx-ctx-tools/dx-ctx-add" "$CTX_TOOLS_DIR/dx-ctx-add"
fetch_file "dx-ctx-tools/dx-ctx-done" "$CTX_TOOLS_DIR/dx-ctx-done"
fetch_file "dx-ctx-tools/dx-ctx-undo" "$CTX_TOOLS_DIR/dx-ctx-undo"
fetch_file "dx-ctx-tools/dx-ctx-rm" "$CTX_TOOLS_DIR/dx-ctx-rm"
fetch_file "dx-ctx-tools/dx-ctx-clear" "$CTX_TOOLS_DIR/dx-ctx-clear"
fetch_file "dx-ctx-tools/dx-ctx-clean" "$CTX_TOOLS_DIR/dx-ctx-clean"
fetch_file "dx-ctx-tools/dx-ctx-todo" "$CTX_TOOLS_DIR/dx-ctx-todo"
fi
echo "Installing completion scripts to $WT_TOOLS_DIR..."
fetch_file "git-wt-completion.sh" "$WT_TOOLS_DIR/git-wt-completion.sh"
fetch_file "dx-completion.sh" "$WT_TOOLS_DIR/dx-completion.sh"
# 3. Make the scripts executable
chmod +x "$INSTALL_DIR/git-wt"
chmod +x "$INSTALL_DIR/dx"
chmod +x "$WT_TOOLS_DIR"/git-wt-*
chmod +x "$WT_TOOLS_DIR/devex-lib.sh"
chmod +x "$DX_SKILLS_TOOLS_DIR"/dx-*
chmod +x "$DX_NB_TOOLS_DIR"/dx-*
if [ "$INSTALL_DX_CTX" = true ]; then
chmod +x "$CTX_TOOLS_DIR"/dx-ctx-*
chmod +x "$CTX_TOOLS_DIR/dx-ctx"
chmod +x "$CTX_TOOLS_DIR/dx-ctx-helper.sh"
fi
# 4. Optional: Install Git Aliases
echo -e "\n${YELLOW}Would you like to install the recommended Git shortcuts (e.g., 'git s' for status)?${NC}"
read -p "(y/n) " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo "Installing Git aliases..."
if [ "$IS_REMOTE" = true ]; then
curl -fsSL "$REPO_RAW_URL/git-aliases/install-git-aliases.sh" | bash
else
bash "$SCRIPT_DIR/git-aliases/install-git-aliases.sh"
fi
else
echo "Skipping Git aliases."
fi
# 5. Optional: Install Python Auto-Venv Tools
echo -e "\n${YELLOW}Would you like to install the Python auto-venv tools (auto-activates .venv when you cd into a directory)?${NC}"
read -p "(y/n) " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo "Installing auto-venv script..."
fetch_file "auto-venv/auto-venv.sh" "$WT_TOOLS_DIR/auto-venv.sh"
INSTALL_AUTO_VENV=true
echo -e "${GREEN}✓ Auto-venv tools staged for installation!${NC}"
else
INSTALL_AUTO_VENV=false
echo "Skipping Python auto-venv tools."
fi
# 6. Detect shell and set up PATH & Auto-completion
SHELL_RC=""
if [[ "$SHELL" == */zsh ]]; then
SHELL_RC="$HOME/.zshrc"
elif [[ "$SHELL" == */bash ]]; then
if [ -f "$HOME/.bash_profile" ]; then
SHELL_RC="$HOME/.bash_profile"
else
SHELL_RC="$HOME/.bashrc"
fi
fi
if [ -n "$SHELL_RC" ]; then
# Create the DevEx Manager block if it doesn't exist
if ! grep -q '# >>> DevEx Manager >>>' "$SHELL_RC"; then
echo -e "\n${BLUE}Initializing DevEx Manager block in $(basename "$SHELL_RC")...${NC}"
echo "" >> "$SHELL_RC"
echo '# >>> DevEx Manager >>>' >> "$SHELL_RC"
echo '# <<< DevEx Manager <<<' >> "$SHELL_RC"
fi
# Function to add a line inside the block if it's missing
add_to_devex_block() {
local line="$1"
if ! grep -Fq "$line" "$SHELL_RC"; then
# Insert before the closing marker using awk (portable on macOS/Darwin)
awk -v line="$line" '/# <<< DevEx Manager <<</ { print line } { print }' "$SHELL_RC" > "${SHELL_RC}.tmp" && \
mv "${SHELL_RC}.tmp" "$SHELL_RC"
return 0
fi
return 0
}
# Setup PATH
if [[ ":$PATH:" != *":$HOME/.local/bin:"* ]] && ! grep -q '.local/bin' "$SHELL_RC"; then
echo -e "\n${YELLOW}Adding $INSTALL_DIR to your PATH in $(basename "$SHELL_RC")...${NC}"
add_to_devex_block 'export PATH="$HOME/.local/bin:$PATH"'
else
echo -e "\nPATH already configured in $(basename "$SHELL_RC")."
fi
# Setup Auto-completion
if ! grep -q "git-wt-completion.sh" "$SHELL_RC"; then
echo -e "${YELLOW}Adding auto-completion to $(basename "$SHELL_RC")...${NC}"
# Zsh needs bashcompinit to run bash completion scripts properly
if [[ "$SHELL" == */zsh ]]; then
add_to_devex_block 'autoload -Uz compinit && compinit'
add_to_devex_block 'autoload -Uz bashcompinit && bashcompinit'
fi
add_to_devex_block "source \"$WT_TOOLS_DIR/git-wt-completion.sh\""
add_to_devex_block "source \"$WT_TOOLS_DIR/dx-completion.sh\""
else
# Make sure dx-completion is loaded if others were already configured
add_to_devex_block "source \"$WT_TOOLS_DIR/dx-completion.sh\""
echo -e "Auto-completion already configured in $(basename "$SHELL_RC")."
fi
# Setup Auto-Venv (if the user said yes)
if [ "$INSTALL_AUTO_VENV" = true ]; then
if ! grep -q "auto-venv.sh" "$SHELL_RC"; then
echo -e "${YELLOW}Adding auto-venv to $(basename "$SHELL_RC")...${NC}"
add_to_devex_block "source \"$WT_TOOLS_DIR/auto-venv.sh\""
else
echo -e "Auto-venv already configured in $(basename "$SHELL_RC")."
fi
fi
else
echo -e "\n${YELLOW}Warning: Could not detect bash or zsh configuration file.${NC}"
echo -e "Please ensure '$INSTALL_DIR' is in your PATH manually."
fi
# 6. Initialize global ~/.devex.conf file with template values if needed
DEVEX_CONF="$HOME/.devex.conf"
if [ ! -f "$DEVEX_CONF" ]; then
echo -e "\n${BLUE}Creating template config file at $DEVEX_CONF...${NC}"
cat <<EOF > "$DEVEX_CONF"
[skills]
# Central directory where all your master skills and backups live
master_dir = <path_to_master_skills_dir>
# Active tools list, comma-separated
tools = <tool_1>, <tool_2>
# Custom skill directories for configured tools (optional, delete or customize)
<tool_1>_dir = ~/<tool_1>/skills
<tool_2>_dir = ~/<tool_2>/skills
EOF
elif ! grep -q '\[skills\]' "$DEVEX_CONF"; then
echo -e "\n${BLUE}Adding [skills] template to existing $DEVEX_CONF...${NC}"
cat <<EOF >> "$DEVEX_CONF"
[skills]
# Central directory where all your master skills and backups live
master_dir = <path_to_master_skills_dir>
# Active tools list, comma-separated
tools = <tool_1>, <tool_2>
# Custom skill directories for configured tools (optional, delete or customize)
<tool_1>_dir = ~/<tool_1>/skills
<tool_2>_dir = ~/<tool_2>/skills
EOF
fi
echo -e "\n${GREEN}✓ Installation complete!${NC}"
echo -e "To start using your new commands, open a new terminal tab, or run:"
echo -e " ${BLUE}source $SHELL_RC${NC}"