-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·351 lines (310 loc) · 9.8 KB
/
setup.sh
File metadata and controls
executable file
·351 lines (310 loc) · 9.8 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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
#!/bin/bash
# ============================================================================
# Type Copy - Automatic Python Setup Script (Linux/macOS)
# ============================================================================
# This script will:
# 1. Check if Python is installed
# 2. If not, provide instructions to install Python
# 3. Install required packages (pyperclip)
# 4. Install clipboard utilities (Linux only)
# 5. Verify installation
# ============================================================================
set -e
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
GRAY='\033[0;90m'
NC='\033[0m' # No Color
# ============================================================================
# Helper Functions
# ============================================================================
print_header() {
echo ""
echo -e "${CYAN}============================================================================${NC}"
echo -e "${CYAN} $1${NC}"
echo -e "${CYAN}============================================================================${NC}"
echo ""
}
print_step() {
echo -e "${YELLOW}[$1]${NC} $2"
}
print_success() {
echo -e "${GREEN}[OK]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
check_command() {
command -v "$1" >/dev/null 2>&1
}
detect_os() {
if [[ "$OSTYPE" == "darwin"* ]]; then
echo "macos"
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
echo "linux"
else
echo "unknown"
fi
}
get_package_manager() {
if check_command apt-get; then
echo "apt"
elif check_command dnf; then
echo "dnf"
elif check_command yum; then
echo "yum"
elif check_command pacman; then
echo "pacman"
elif check_command brew; then
echo "brew"
else
echo "unknown"
fi
}
# ============================================================================
# Main Script
# ============================================================================
print_header "Type Copy - Auto Setup"
OS=$(detect_os)
PKG_MANAGER=$(get_package_manager)
echo -e "${GRAY}Operating System: $OS${NC}"
echo -e "${GRAY}Package Manager: $PKG_MANAGER${NC}"
echo ""
# Step 1: Check Python
print_step "1/5" "Checking Python installation..."
PYTHON_CMD=""
if check_command python3; then
PYTHON_CMD="python3"
elif check_command python; then
# Check if it's Python 3
PYTHON_VERSION=$(python --version 2>&1 | grep -oP '\d+\.\d+' | head -1)
MAJOR_VERSION=$(echo "$PYTHON_VERSION" | cut -d. -f1)
if [ "$MAJOR_VERSION" -ge 3 ]; then
PYTHON_CMD="python"
fi
fi
if [ -n "$PYTHON_CMD" ]; then
VERSION=$($PYTHON_CMD --version 2>&1)
print_success "Python is installed: $VERSION"
echo ""
else
print_warning "Python 3 is not installed"
echo ""
echo -e "${CYAN}Installing Python...${NC}"
echo ""
case "$OS" in
macos)
if check_command brew; then
echo "Installing Python via Homebrew..."
brew install python3
PYTHON_CMD="python3"
else
print_error "Homebrew not found"
echo ""
echo "Please install Homebrew first:"
echo " /bin/bash -c \"\$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)\""
echo ""
echo "Or install Python manually:"
echo " Download from: https://www.python.org/downloads/"
exit 1
fi
;;
linux)
case "$PKG_MANAGER" in
apt)
echo "Installing Python via apt..."
sudo apt-get update
sudo apt-get install -y python3 python3-pip
PYTHON_CMD="python3"
;;
dnf)
echo "Installing Python via dnf..."
sudo dnf install -y python3 python3-pip
PYTHON_CMD="python3"
;;
yum)
echo "Installing Python via yum..."
sudo yum install -y python3 python3-pip
PYTHON_CMD="python3"
;;
pacman)
echo "Installing Python via pacman..."
sudo pacman -S --noconfirm python python-pip
PYTHON_CMD="python3"
;;
*)
print_error "Could not determine package manager"
echo ""
echo "Please install Python 3 manually:"
echo " Ubuntu/Debian: sudo apt install python3 python3-pip"
echo " Fedora: sudo dnf install python3 python3-pip"
echo " Arch: sudo pacman -S python python-pip"
exit 1
;;
esac
;;
*)
print_error "Unsupported operating system"
exit 1
;;
esac
# Verify installation
if check_command "$PYTHON_CMD"; then
VERSION=$($PYTHON_CMD --version 2>&1)
print_success "Python installed: $VERSION"
else
print_error "Python installation failed"
exit 1
fi
echo ""
fi
# Step 2: Check pip
print_step "2/5" "Checking pip installation..."
PIP_CMD=""
if check_command pip3; then
PIP_CMD="pip3"
elif check_command pip; then
PIP_CMD="pip"
elif check_command "$PYTHON_CMD" && $PYTHON_CMD -m pip --version >/dev/null 2>&1; then
PIP_CMD="$PYTHON_CMD -m pip"
fi
if [ -n "$PIP_CMD" ]; then
print_success "pip is installed"
else
print_warning "pip is not installed, installing..."
case "$OS" in
macos)
brew install python3
PIP_CMD="pip3"
;;
linux)
case "$PKG_MANAGER" in
apt)
sudo apt-get install -y python3-pip
;;
dnf)
sudo dnf install -y python3-pip
;;
yum)
sudo yum install -y python3-pip
;;
pacman)
sudo pacman -S --noconfirm python-pip
;;
esac
PIP_CMD="pip3"
;;
esac
if ! check_command pip3; then
print_error "Could not install pip"
exit 1
fi
print_success "pip installed"
fi
echo ""
# Step 3: Install clipboard utilities (Linux only)
if [ "$OS" = "linux" ]; then
print_step "3/5" "Checking clipboard utilities..."
if check_command xclip || check_command xsel || check_command wl-copy; then
print_success "Clipboard utility is installed"
else
print_warning "No clipboard utility found"
echo " Installing xclip..."
case "$PKG_MANAGER" in
apt)
sudo apt-get install -y xclip
;;
dnf)
sudo dnf install -y xclip
;;
yum)
sudo yum install -y xclip
;;
pacman)
sudo pacman -S --noconfirm xclip
;;
esac
if check_command xclip; then
print_success "xclip installed"
else
print_warning "Could not install xclip automatically"
echo " Please install manually: sudo apt install xclip (or equivalent)"
fi
fi
echo ""
else
print_step "3/5" "Checking clipboard support..."
print_success "macOS has built-in clipboard support (pbcopy)"
echo ""
fi
# Step 4: Install Python packages
print_step "4/5" "Installing required Python packages..."
echo ""
# Check if pyperclip is already installed
if $PYTHON_CMD -c "import pyperclip" 2>/dev/null; then
print_success "pyperclip is already installed"
else
echo " Installing pyperclip..."
# Try with --user flag first (no sudo needed)
if $PIP_CMD install --user pyperclip >/dev/null 2>&1; then
print_success "pyperclip installed successfully"
elif $PIP_CMD install pyperclip >/dev/null 2>&1; then
print_success "pyperclip installed successfully"
else
print_error "Failed to install pyperclip"
echo ""
echo "Please run manually:"
echo " $PIP_CMD install pyperclip"
exit 1
fi
fi
echo ""
# Step 5: Verify installation
print_step "5/5" "Verifying installation..."
# Test Python
if $PYTHON_CMD --version >/dev/null 2>&1; then
print_success "Python is working"
else
print_error "Python verification failed"
exit 1
fi
# Test pyperclip
if $PYTHON_CMD -c "import pyperclip" 2>/dev/null; then
print_success "pyperclip is working"
else
print_error "pyperclip verification failed"
exit 1
fi
echo ""
# Success!
print_header "Setup Complete!"
echo -e "${GREEN}Python and all dependencies are now installed and configured.${NC}"
echo ""
echo -e "${CYAN}You can now use Type Copy!${NC}"
echo ""
echo -e "${YELLOW}Usage:${NC}"
echo " $PYTHON_CMD copy.cs.md.py.py - Copy all files"
echo " $PYTHON_CMD copy.cs.md.py.py --exclude test - Exclude folders"
echo " $PYTHON_CMD copy.cs.md.py.py --help - Show help"
echo ""
# Create a convenient alias suggestion
echo -e "${YELLOW}Pro Tip:${NC}"
echo "Add this to your ~/.bashrc or ~/.zshrc for easy access:"
echo " alias typecopy='$PYTHON_CMD $(pwd)/copy.cs.md.py.py'"
echo ""
# Ask to run Type Copy
if [ -f "copy.cs.md.py.py" ]; then
echo -e "${GRAY}Press Enter to run Type Copy now, or Ctrl+C to exit...${NC}"
read -r
$PYTHON_CMD copy.cs.md.py.py "$@"
else
print_error "copy.cs.md.py.py not found in current directory"
echo "Please make sure this script is in the same folder as copy.cs.md.py.py"
exit 1
fi