-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·94 lines (80 loc) · 3.08 KB
/
install.sh
File metadata and controls
executable file
·94 lines (80 loc) · 3.08 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
#!/bin/bash
# nwt Installation Script
# This script installs the nwt (New Worktree) function to your shell configuration
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Detect shell and config file
detect_shell_config() {
# Check user's default shell from SHELL environment variable
if [[ "$SHELL" == *"zsh"* ]]; then
echo "$HOME/.zshrc"
elif [[ "$SHELL" == *"bash"* ]]; then
echo "$HOME/.bashrc"
# On macOS, default to zsh (it's been the default since macOS Catalina)
elif [[ "$OSTYPE" == "darwin"* ]]; then
echo "$HOME/.zshrc"
else
# Fallback detection based on which config files exist
if [[ -f "$HOME/.zshrc" ]]; then
echo "$HOME/.zshrc"
elif [[ -f "$HOME/.bashrc" ]]; then
echo "$HOME/.bashrc"
else
echo ""
fi
fi
}
main() {
echo -e "${BLUE}🚀 Installing nwt (New Worktree) for Warp Terminal${NC}"
echo
# Detect config file
CONFIG_FILE=$(detect_shell_config)
if [[ -z "$CONFIG_FILE" ]]; then
echo -e "${RED}❌ Could not detect shell configuration file${NC}"
echo "Please manually add the contents of nwt.zsh to your shell configuration"
exit 1
fi
echo -e "${YELLOW}📝 Detected config file: $CONFIG_FILE${NC}"
# Check if already installed
if grep -q "new_worktree()" "$CONFIG_FILE" 2>/dev/null; then
echo -e "${YELLOW}⚠️ nwt appears to already be installed${NC}"
read -p "Do you want to reinstall? (y/N): " -r
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Installation cancelled"
exit 0
fi
# Remove existing installation
echo -e "${YELLOW}🔄 Removing existing installation...${NC}"
# Create a temp file without the nwt function
grep -v -A 200 "# Git worktree + Warp function" "$CONFIG_FILE" | \
grep -v -B 200 "alias nwt='new_worktree'" > "$CONFIG_FILE.tmp" || true
mv "$CONFIG_FILE.tmp" "$CONFIG_FILE"
fi
# Add the function to config file
echo -e "${YELLOW}📦 Installing nwt function...${NC}"
echo "" >> "$CONFIG_FILE"
echo "# Git worktree + Warp function (installed by nwt installer)" >> "$CONFIG_FILE"
cat nwt.zsh >> "$CONFIG_FILE"
echo "" >> "$CONFIG_FILE"
echo -e "${GREEN}✅ nwt installed successfully!${NC}"
echo
echo -e "${BLUE}📖 Usage:${NC}"
echo " nwt <branch-name> # Create worktree with auto-detected base branch"
echo " nwt <branch-name> <base-branch> # Create worktree from specific base branch"
echo
echo -e "${BLUE}Examples:${NC}"
echo " nwt feature/user-auth # Creates from main/master/develop"
echo " nwt hotfix/critical-bug main # Creates from main branch"
echo
echo -e "${YELLOW}🔄 To start using nwt, run: source $CONFIG_FILE${NC}"
echo -e "${YELLOW} Or restart your terminal${NC}"
}
# Check if script is being sourced or executed directly
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
main "$@"
fi