Repository navigation
Expand file tree
/
Copy pathget.sh
More file actions
executable file
·157 lines (127 loc) · 3.82 KB
/
Copy pathget.sh
File metadata and controls
executable file
·157 lines (127 loc) · 3.82 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
#!/bin/sh
# Download and install script for wt - Git Worktree Manager
# This script detects the OS/architecture, downloads the appropriate release,
# and runs the setup process.
#
# Usage: curl -fsSL https://raw.githubusercontent.com/tobiase/worktree-utils/main/get.sh | sh
set -e
# Colors for output (using printf for better compatibility)
if [ -t 1 ]; then
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
else
RED=''
GREEN=''
YELLOW=''
NC=''
fi
# Helper functions
info() {
printf "${GREEN}▶${NC} %s\n" "$1"
}
error() {
printf "${RED}✗${NC} %s\n" "$1" >&2
exit 1
}
warn() {
printf "${YELLOW}⚠${NC} %s\n" "$1"
}
# Check for required tools
check_requirements() {
if ! command -v curl >/dev/null 2>&1; then
error "curl is required but not installed"
fi
if ! command -v tar >/dev/null 2>&1; then
error "tar is required but not installed"
fi
}
# Detect OS and architecture
detect_platform() {
OS=$(uname -s)
ARCH=$(uname -m)
case "$OS" in
Darwin)
PLATFORM="Darwin_all"
;;
Linux)
case "$ARCH" in
x86_64)
PLATFORM="Linux_x86_64"
;;
aarch64|arm64)
PLATFORM="Linux_arm64"
;;
*)
error "Unsupported Linux architecture: $ARCH"
;;
esac
;;
*)
error "Unsupported operating system: $OS"
;;
esac
info "Detected platform: $PLATFORM"
}
# Download and install
install_wt() {
# Create a temporary directory
TEMP_DIR=$(mktemp -d 2>/dev/null || mktemp -d -t 'wt-install')
# Ensure cleanup on exit
trap 'rm -rf "$TEMP_DIR"' EXIT INT TERM
info "Downloading wt..."
# Get latest version from GitHub API
VERSION=$(curl -fsSL https://api.github.com/repos/tobiase/worktree-utils/releases/latest | grep '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/')
if [ -z "$VERSION" ]; then
error "Failed to determine latest version"
fi
info "Latest version: $VERSION"
# Construct download URL with version (strip 'v' prefix for asset name)
VERSION_NO_V=${VERSION#v}
URL="https://github.com/tobiase/worktree-utils/releases/download/${VERSION}/wt_${VERSION_NO_V}_${PLATFORM}.tar.gz"
cd "$TEMP_DIR"
# Download with progress indicator
if ! curl -fL# "$URL" -o wt.tar.gz; then
error "Failed to download wt from: $URL"
fi
info "Extracting..."
# List what will be extracted to get the directory name
EXTRACT_DIR=$(tar tzf wt.tar.gz | head -1 | cut -d'/' -f1)
if [ -z "$EXTRACT_DIR" ]; then
error "Could not determine archive structure"
fi
if ! tar xzf wt.tar.gz; then
error "Failed to extract archive"
fi
if [ ! -d "$EXTRACT_DIR" ]; then
error "Expected directory '$EXTRACT_DIR' not found after extraction"
fi
info "Running setup..."
# The binary might be named 'worktree-utils' or 'wt-bin'
if [ -f "$EXTRACT_DIR/wt-bin" ]; then
BINARY="$EXTRACT_DIR/wt-bin"
elif [ -f "$EXTRACT_DIR/worktree-utils" ]; then
BINARY="$EXTRACT_DIR/worktree-utils"
else
error "Could not find binary in $EXTRACT_DIR"
fi
if ! "$BINARY" setup; then
error "Setup failed"
fi
cd - >/dev/null 2>&1 || true
printf "\n${GREEN}✓${NC} wt has been successfully installed!\n\n"
printf "To get started, either:\n"
printf " • Restart your shell, or\n"
printf " • Run: ${GREEN}source ~/.config/wt/init.sh${NC}\n\n"
printf "Then try: ${GREEN}wt${NC}\n\n"
}
# Main
main() {
printf "\n${GREEN}wt${NC} - Git Worktree Manager installer\n\n"
check_requirements
detect_platform
install_wt
}
# Run main function
main "$@"