-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·272 lines (223 loc) · 6.89 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·272 lines (223 loc) · 6.89 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
#!/bin/bash
# CommandHelper Installation Script
# Installiert cmdhelper und erstellt notwendige Konfiguration
set -e # Exit bei Fehler
# Farben für Output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Variablen
BINARY_NAME="cmdhelper"
INSTALL_PATH="/usr/local/bin"
CONFIG_DIR="$HOME/.config/cmdhelper"
DATA_DIR="$HOME/.local/share/cmdhelper"
CACHE_DIR="$HOME/.cache/cmdhelper"
# Funktionen
print_info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
check_requirements() {
print_info "Checking requirements..."
# Prüfe Rust/Cargo
if ! command -v cargo &> /dev/null; then
print_error "Cargo not found. Please install Rust first:"
echo " curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh"
exit 1
fi
# Prüfe Betriebssystem
OS="$(uname -s)"
case "$OS" in
Darwin*)
print_info "Detected macOS"
;;
Linux*)
print_info "Detected Linux"
;;
*)
print_warning "Unknown OS: $OS (continuing anyway)"
;;
esac
print_success "Requirements check passed"
}
build_binary() {
print_info "Building $BINARY_NAME (release mode)..."
if cargo build --release; then
print_success "Build completed"
else
print_error "Build failed"
exit 1
fi
}
install_binary() {
print_info "Installing binary to $INSTALL_PATH..."
# Prüfe Schreibrechte
if [ ! -w "$INSTALL_PATH" ]; then
print_warning "$INSTALL_PATH is not writable"
print_info "Trying with sudo..."
sudo install -m 755 "target/release/$BINARY_NAME" "$INSTALL_PATH/$BINARY_NAME"
else
install -m 755 "target/release/$BINARY_NAME" "$INSTALL_PATH/$BINARY_NAME"
fi
print_success "Binary installed"
}
create_directories() {
print_info "Creating configuration directories..."
# Config Directory
if [ ! -d "$CONFIG_DIR" ]; then
mkdir -p "$CONFIG_DIR"
print_success "Created $CONFIG_DIR"
else
print_info "$CONFIG_DIR already exists"
fi
# Data Directory
if [ ! -d "$DATA_DIR" ]; then
mkdir -p "$DATA_DIR"
print_success "Created $DATA_DIR"
else
print_info "$DATA_DIR already exists"
fi
# Cache Directory
if [ ! -d "$CACHE_DIR" ]; then
mkdir -p "$CACHE_DIR"
print_success "Created $CACHE_DIR"
else
print_info "$CACHE_DIR already exists"
fi
}
create_default_config() {
print_info "Creating default configuration..."
CONFIG_FILE="$CONFIG_DIR/config.toml"
if [ ! -f "$CONFIG_FILE" ]; then
cat > "$CONFIG_FILE" << 'EOF'
# CommandHelper Configuration
[scan]
# Directories to scan for CLI tools
directories = ["/usr/local/bin"]
# Commands to exclude from listing
exclude = []
# Scan on startup (false = faster startup, manual refresh needed)
scan_on_startup = true
[ui]
# Theme: "dark", "light", "custom"
theme = "dark"
# Show line numbers in command list
show_line_numbers = false
# Commands per page for pagination
page_size = 20
[behavior]
# Ask for confirmation before executing commands
confirm_execution = false
# Cache help text for faster loading
cache_help = true
# Cache duration in seconds (0 = never expire)
cache_duration = 3600
# Default execution mode: "current" or "new_terminal"
default_execution = "current"
[favorites]
# Auto-save favorites
auto_save = true
# Sort favorites by usage count
sort_by_usage = true
[terminal]
# Terminal emulator for new terminal execution (auto-detect if empty)
# macOS: "Terminal", "iTerm"
# Linux: "gnome-terminal", "konsole", "xterm"
emulator = ""
# Keep terminal open after command execution
keep_open = true
EOF
print_success "Created default config: $CONFIG_FILE"
else
print_info "Config file already exists: $CONFIG_FILE"
fi
}
create_favorites_file() {
print_info "Creating favorites file..."
FAVORITES_FILE="$DATA_DIR/favorites.json"
if [ ! -f "$FAVORITES_FILE" ]; then
cat > "$FAVORITES_FILE" << 'EOF'
{
"commands": [],
"last_used": {},
"usage_count": {}
}
EOF
print_success "Created favorites file: $FAVORITES_FILE"
else
print_info "Favorites file already exists: $FAVORITES_FILE"
fi
}
verify_installation() {
print_info "Verifying installation..."
if command -v "$BINARY_NAME" &> /dev/null; then
VERSION=$("$BINARY_NAME" --version 2>/dev/null || echo "unknown")
print_success "Installation verified: $VERSION"
return 0
else
print_error "Installation verification failed"
print_info "Binary not found in PATH"
print_info "You may need to add $INSTALL_PATH to your PATH"
return 1
fi
}
print_summary() {
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
print_success "CommandHelper Installation Complete!"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo "Installation Details:"
echo " Binary: $INSTALL_PATH/$BINARY_NAME"
echo " Config: $CONFIG_DIR/config.toml"
echo " Favorites: $DATA_DIR/favorites.json"
echo " Cache: $CACHE_DIR/"
echo ""
echo "Quick Start:"
echo " 1. Run: $BINARY_NAME"
echo " 2. Navigate with ↑/↓ or j/k"
echo " 3. Press Enter to execute"
echo " 4. Press 'f' to add to favorites"
echo " 5. Press Ctrl+T to execute in new terminal"
echo " 6. Press 'q' to quit"
echo ""
echo "For more information:"
echo " • Documentation: doc/ARCHITECTURE.md"
echo " • Configuration: $CONFIG_FILE"
echo " • Help: $BINARY_NAME --help"
echo ""
}
# Main Installation
main() {
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo " CommandHelper Installation"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
check_requirements
build_binary
install_binary
create_directories
create_default_config
create_favorites_file
if verify_installation; then
print_summary
exit 0
else
print_error "Installation completed with warnings"
exit 1
fi
}
# Run installation
main
# Made with Bob