-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall
More file actions
executable file
·1514 lines (1265 loc) · 52.1 KB
/
install
File metadata and controls
executable file
·1514 lines (1265 loc) · 52.1 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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh
#================================================================#
# GitSSH v0.1.0 INSTALLER - Updated for New Structure
# Enhanced installer for modular POSIX Compliant CLI tool
#================================================================#
set -e # Exit on any error
SCRIPT_NAME="gitssh"
INSTALL_DIR="$HOME/.local/bin/gitssh-libs"
MAIN_SCRIPT="$INSTALL_DIR/gitssh"
MODULES_DIR="$INSTALL_DIR/modules"
SYMLINK_PATH="$HOME/.local/bin/gitssh"
TEMP_DIR="${TMPDIR:-/tmp}/gitssh-installer-$$"
# Required module files for the modular system
REQUIRED_MODULES="gitssh-utils.sh gitssh-users.sh gitssh-sessions.sh gitssh-remotes.sh gitssh-commands.sh gitssh-init.sh gitssh-setup.sh"
# Colors for output (POSIX Compliant)
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
MAGENTA='\033[0;35m'
BOLD='\033[1m'
NC='\033[0m' # No Color
# Box drawing characters
BOX_H="─"
BOX_V="│"
BOX_TL="┌"
BOX_TR="┐"
BOX_BL="└"
BOX_BR="┘"
# Create temp directory
mkdir -p "$TEMP_DIR"
# Logging functions with enhanced visuals
log_info() { printf "${BLUE}${BOLD}[INFO]${NC} %s\n" "$1"; }
log_success() { printf "${GREEN}${BOLD}[SUCCESS]${NC} %s\n" "$1"; }
log_warning() { printf "${YELLOW}${BOLD}[WARNING]${NC} %s\n" "$1"; }
log_error() { printf "${RED}${BOLD}[ERROR]${NC} %s\n" "$1"; }
log_step() { printf "${CYAN}${BOLD}[STEP %s]${NC} %s\n" "$1" "$2"; }
# String length function (POSIX Compliant)
str_length() {
printf "%s" "$1" | wc -c | tr -d ' '
}
# Repeat character function
repeat_char() {
_char="$1"
_count="$2"
_result=""
_i=0
while [ $_i -lt $_count ]; do
_result="${_result}$_char"
_i=$((_i + 1))
done
printf "%s" "$_result"
}
# Interactive prompt functions
draw_box() {
_title="$1"
_content="$2"
_width="${3:-70}"
# Top border
printf "${CYAN}${BOX_TL}"
repeat_char "$BOX_H" $((_width - 2))
printf "${BOX_TR}${NC}\n"
# Title
if [ -n "$_title" ]; then
_title_len=$(str_length "$_title")
_padding=$(((_width - _title_len - 4) / 2))
printf "${CYAN}${BOX_V}${NC}${BOLD}"
repeat_char " " $_padding
printf "%s" "$_title"
repeat_char " " $((_width - _title_len - _padding - 4))
printf "${CYAN}${BOX_V}${NC}\n"
printf "${CYAN}├"
repeat_char "$BOX_H" $((_width - 2))
printf "┤${NC}\n"
fi
# Content - handle line by line
printf "%s\n" "$_content" | while IFS= read -r line; do
_line_len=$(str_length "$line")
_content_padding=$((_width - _line_len - 4))
[ $_content_padding -lt 0 ] && _content_padding=0
printf "${CYAN}${BOX_V}${NC} %s" "$line"
repeat_char " " $_content_padding
printf "${CYAN}${BOX_V}${NC}\n"
done
# Bottom border
printf "${CYAN}${BOX_BL}"
repeat_char "$BOX_H" $((_width - 2))
printf "${BOX_BR}${NC}\n"
}
progress_bar() {
_current="$1"
_total="$2"
_description="$3"
_width=40
_percentage=$((_current * 100 / _total))
_filled=$((_current * _width / _total))
_empty=$((_width - _filled))
printf "\r${CYAN}["
repeat_char '█' $_filled
repeat_char '░' $_empty
printf "${CYAN}]${NC} ${BOLD}%d%%${NC} - %s" $_percentage "$_description"
if [ $_current -eq $_total ]; then
printf "\n"
fi
}
interactive_prompt() {
_prompt="$1"
_default="$2"
_instruction="$3"
# Print instruction and prompt to stderr so they don't get captured
if [ -n "$_instruction" ]; then
printf "${BLUE}%s${NC}\n" "$_instruction" >&2
fi
if [ -n "$_default" ]; then
printf "${YELLOW}${BOLD}?${NC} %s ${CYAN}[%s]${NC}: " "$_prompt" "$_default" >&2
else
printf "${YELLOW}${BOLD}?${NC} %s: " "$_prompt" >&2
fi
# Read user input properly
IFS= read -r response
# Clean the response by removing whitespace and converting to lowercase
response=$(printf "%s" "$response" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//' | tr '[:upper:]' '[:lower:]')
# Use default if response is empty after cleaning
if [ -z "$response" ]; then
response="$_default"
fi
# Return ONLY the cleaned response to stdout
printf "%s" "$response"
}
show_welcome() {
clear
printf "${MAGENTA}${BOLD}"
cat << 'EOF'
╔═══════════════════════════════════════════════════════════════╗
║ ║
║ ██████╗ ███████╗███████╗██╗ ██╗ ║
║ ██╔════╝ ██╗ ██╗ ██╔════╝██╔════╝██║ ██║ ║
║ ██║ ███╗══╝████║███████╗███████╗███████║ ║
║ ██║ ██║██║ ██║ ╚════██║╚════██║██╔══██║ ║
║ ██████╔╝██║ ██║ ███████║███████║██║ ██║ ║
║ ╚═════╝ ╚═╝ ╚═╝ ╚══════╝╚══════╝╚═╝ ╚═╝v0.1.0-Oz ║
║ <-POSIX Compliant-> ║
║ ║
╚═══════════════════════════════════════════════════════════════╝
Manage Multiple SSH Git and GitHub Account Sessions With Ease!
EOF
printf "${NC}\n"
printf "${CYAN}${BOLD}Modern CLI tool for effortless workflow${NC}\n"
printf "\n"
printf "${GREEN}✨ v0.1.0 Features:${NC}\n"
printf " • Clean CLI interface (gitssh <command>)\n"
printf " • Common git command with extra features of GitSSH \n"
printf " • Session-based user switching per repository\n"
printf " • Global account switching with one command\n"
printf " • Automatic HTTPS to SSH git remote conversion\n"
printf " • Interactive SSH key, GitHub and GitLab setup wizards\n"
printf " • Persistent user preferences across sessions and repos\n"
printf " • Full POSIX shell compatibility\n"
printf " • Enhanced diagnostics and repair tools\n"
printf " • Tab completion support for built-in gitssh commands\n"
printf " • And many more!\n"
printf "\n"
}
#================================================================#
# MODULE DETECTION AND VALIDATION
#================================================================#
count_words() {
set -- $1
printf "%d" "$#"
}
detect_modules() {
log_step "1" "Detecting GitSSH v01.0 system files"
found_modules=""
missing_modules=""
printf " ${CYAN}Scanning current directory structure...${NC}\n"
# Check main executable
if [ -f "gitssh" ]; then
printf " ${GREEN}✓${NC} Found: ${CYAN}gitssh${NC} (main executable)\n"
else
printf " ${RED}✗${NC} Missing: ${RED}gitssh${NC} (main executable)\n"
missing_modules="$missing_modules gitssh"
fi
# Check modules directory
if [ -d "modules" ]; then
printf " ${GREEN}✓${NC} Found: ${CYAN}modules/${NC} (modules directory)\n"
# Check each required module
for module in $REQUIRED_MODULES; do
if [ -f "modules/$module" ]; then
found_modules="$found_modules $module"
printf " ${GREEN}✓${NC} Found: ${CYAN}modules/%s${NC}\n" "$module"
else
missing_modules="$missing_modules $module"
printf " ${RED}✗${NC} Missing: ${RED}modules/%s${NC}\n" "$module"
fi
done
else
printf " ${RED}✗${NC} Missing: ${RED}modules/${NC} (modules directory)\n"
printf " ${YELLOW}⚠${NC} All module files should be in a 'modules/' subdirectory\n"
missing_modules="$missing_modules modules_directory"
fi
printf "\n"
missing_count=$(count_words "$missing_modules")
if [ $missing_count -gt 0 ]; then
_missing_list=$(printf "%s" "$missing_modules" | tr ' ' '\n')
draw_box "MISSING REQUIRED FILES" "The following files are required but not found:
$_missing_list
Expected project structure:
gitssh (main CLI executable)
install (this installer)
modules/ (modules directory)
├── gitssh-utils.sh
├── gitssh-users.sh
├── gitssh-sessions.sh
├── gitssh-remotes.sh
├── gitssh-commands.sh
├── gitssh-init.sh
└── gitssh-setup.sh
Please ensure all files are present and run installer from project root."
printf "\n"
log_error "Cannot proceed without required files"
return 1
fi
found_count=$(count_words "$found_modules")
required_count=$(count_words "$REQUIRED_MODULES")
log_success "File detection complete (1 executable + $found_count/$required_count modules found)"
printf "\n"
return 0
}
validate_module_structure() {
log_info "Validating GitSSH v0.1.0 structure and dependencies"
# Check main executable is the new CLI dispatcher
if ! grep -q "GITSSH.*CLI.*v0.1.0\|GitSSH.*v0.1.0.*CLI" "gitssh" 2>/dev/null; then
log_warning "Main executable may not be the v0.1.0 CLI dispatcher"
printf " ${YELLOW}⚠${NC} Expected GitSSH v0.1.0 CLI dispatcher\n"
else
printf " ${GREEN}✓${NC} Main executable appears to be GitSSH v0.1.0 CLI\n"
fi
# Check for module loading in main file
if grep -q "gitssh-.*\.sh" "gitssh" 2>/dev/null; then
printf " ${GREEN}✓${NC} Module loading configuration found\n"
else
log_warning "Module loading configuration not detected"
printf " ${YELLOW}⚠${NC} Main script may not load modules correctly\n"
fi
# Check if modules have proper structure
missing_functions=""
for module in $REQUIRED_MODULES; do
[ ! -f "modules/$module" ] && continue
case "$module" in
gitssh-users.sh)
if ! grep -q "user_add\|user_list\|user_switch" "modules/$module" 2>/dev/null; then
missing_functions="$missing_functions $module:user_functions"
fi
;;
gitssh-sessions.sh)
if ! grep -q "session_set\|session_show\|session_clear" "modules/$module" 2>/dev/null; then
missing_functions="$missing_functions $module:session_functions"
fi
;;
gitssh-init.sh)
if ! grep -q "system_init\|system_onboard\|system_validate" "modules/$module" 2>/dev/null; then
missing_functions="$missing_functions $module:system_functions"
fi
;;
esac
done
missing_func_count=$(count_words "$missing_functions")
if [ $missing_func_count -gt 0 ]; then
log_warning "Some modules may not have v0.1.0 CLI functions"
printf " ${YELLOW}⚠${NC} Missing functions: %s\n" "$missing_functions"
printf " ${BLUE}ℹ${NC} This may be normal if modules are in transition\n"
else
printf " ${GREEN}✓${NC} All modules appear to have v0.1.0 CLI functions\n"
fi
printf " ${GREEN}✓${NC} Module structure validation complete\n"
printf "\n"
return 0
}
#================================================================#
# DEPENDENCY CHECKS
#================================================================#
check_dependencies() {
log_step "2" "Checking system dependencies"
missing_deps=""
dep_status=""
# Check for jq
if command -v jq >/dev/null 2>&1; then
jq_version=$(jq --version 2>/dev/null)
dep_status="${dep_status}${GREEN}✓ jq (${jq_version})${NC} "
else
missing_deps="$missing_deps jq"
dep_status="${dep_status}${RED}✗ jq${NC} "
fi
# Check for git
if command -v git >/dev/null 2>&1; then
git_version=$(git --version 2>/dev/null | cut -d' ' -f3)
dep_status="${dep_status}${GREEN}✓ git (${git_version})${NC} "
else
missing_deps="$missing_deps git"
dep_status="${dep_status}${RED}✗ git${NC} "
fi
# Check for ssh
if command -v ssh >/dev/null 2>&1; then
ssh_version=$(ssh -V 2>&1 | head -1 | cut -d' ' -f1)
dep_status="${dep_status}${GREEN}✓ ssh (${ssh_version})${NC}"
else
missing_deps="$missing_deps openssh-client"
dep_status="${dep_status}${RED}✗ ssh${NC}"
fi
printf " Dependencies: %b\n" "$dep_status"
missing_count=$(count_words "$missing_deps")
if [ $missing_count -gt 0 ]; then
printf "\n"
_deps_list=$(printf "%s" "$missing_deps" | tr ' ' '\n')
draw_box "MISSING DEPENDENCIES" "The following packages are required:
$_deps_list
Install them using your package manager:"
printf "\n"
printf "${YELLOW}${BOLD}Installation Commands:${NC}\n"
printf " ${CYAN}Ubuntu/Debian:${NC} sudo apt update && sudo apt install %s\n" "$missing_deps"
printf " ${CYAN}CentOS/RHEL:${NC} sudo yum install %s\n" "$missing_deps"
printf " ${CYAN}Fedora:${NC} sudo dnf install %s\n" "$missing_deps"
printf " ${CYAN}macOS:${NC} brew install %s\n" "$missing_deps"
printf " ${CYAN}Arch Linux:${NC} sudo pacman -S %s\n" "$missing_deps"
printf "\n"
log_error "Please install missing dependencies and run installer again"
return 1
fi
log_success "All dependencies satisfied"
printf "\n"
return 0
}
#================================================================#
# PREDEFINED INTEGRATION TEMPLATES
#================================================================#
# Base integration block (without completion)
BASE_INTEGRATION='# GitSSH v0.1.0 CLI Integration
# Add ~/.local/bin to PATH if not already present
if [ -d "$HOME/.local/bin" ]; then
case ":$PATH:" in
*":$HOME/.local/bin:"*) ;;
*) export PATH="$PATH:$HOME/.local/bin" ;;
esac
fi'
# Extended integration block (with completion)
EXTENDED_INTEGRATION='# GitSSH v0.1.0 CLI Integration
# Add ~/.local/bin to PATH if not already present
if [ -d "$HOME/.local/bin" ]; then
case ":$PATH:" in
*":$HOME/.local/bin:"*) ;;
*) export PATH="$PATH:$HOME/.local/bin" ;;
esac
fi
# GitSSH CLI completion (if available)
if [ -f "$HOME/.local/bin/gitssh-libs/completion.sh" ]; then
. "$HOME/.local/bin/gitssh-libs/completion.sh"
fi'
#================================================================#
# INSTALLATION FUNCTIONS
#================================================================#
install_gitssh_system() {
log_step "3" "Installing GitSSH v0.1.0 CLI system"
# Create main installation directory
mkdir -p "$INSTALL_DIR"
printf " ${GREEN}✓${NC} Created installation directory: ${CYAN}%s${NC}\n" "$INSTALL_DIR"
# Create modules subdirectory
mkdir -p "$MODULES_DIR"
printf " ${GREEN}✓${NC} Created modules directory: ${CYAN}%s${NC}\n" "$MODULES_DIR"
# Copy main executable
printf " ${CYAN}⚡${NC} Installing main executable...\n"
cp "gitssh" "$MAIN_SCRIPT"
chmod +x "$MAIN_SCRIPT"
printf " ${GREEN}✓${NC} Installed: ${CYAN}gitssh${NC}\n"
# Copy installer for future use
cp "install" "$INSTALL_DIR/"
chmod +x "$INSTALL_DIR/install"
printf " ${GREEN}✓${NC} Installed: ${CYAN}install${NC}\n"
# Copy all module files
printf " ${CYAN}⚡${NC} Installing modules...\n"
installed_modules=""
failed_modules=""
for module in $REQUIRED_MODULES; do
if [ -f "modules/$module" ]; then
cp "modules/$module" "$MODULES_DIR/"
chmod +x "$MODULES_DIR/$module"
installed_modules="$installed_modules $module"
printf " ${GREEN}✓${NC} Installed: ${CYAN}%s${NC}\n" "$module"
else
failed_modules="$failed_modules $module"
printf " ${RED}✗${NC} Failed: ${RED}%s${NC} (file not found)\n" "$module"
fi
done
failed_count=$(count_words "$failed_modules")
if [ $failed_count -gt 0 ]; then
log_error "Failed to install required modules: $failed_modules"
return 1
fi
# Create symlink for easy access
printf " ${CYAN}⚡${NC} Creating symlink...\n"
# Remove existing symlink if present
if [ -L "$SYMLINK_PATH" ]; then
rm "$SYMLINK_PATH"
fi
# Create symlink
ln -s "$MAIN_SCRIPT" "$SYMLINK_PATH"
if [ -L "$SYMLINK_PATH" ]; then
printf " ${GREEN}✓${NC} Created symlink: ${CYAN}%s${NC} → ${CYAN}%s${NC}\n" "$SYMLINK_PATH" "$MAIN_SCRIPT"
else
log_error "Failed to create symlink"
return 1
fi
installed_count=$(count_words "$installed_modules")
log_success "GitSSH v0.1.0 installation complete (1 executable + $installed_count modules + symlink)"
printf "\n"
return 0
}
setup_shell_integration() {
log_step "4" "Setting up shell integration"
shell_configs=""
# Detect available shell configs
[ -f "$HOME/.bashrc" ] && shell_configs="$shell_configs $HOME/.bashrc"
[ -f "$HOME/.zshrc" ] && shell_configs="$shell_configs $HOME/.zshrc"
[ -f "$HOME/.profile" ] && shell_configs="$shell_configs $HOME/.profile"
config_count=$(count_words "$shell_configs")
if [ $config_count -eq 0 ]; then
log_warning "No shell configuration files found"
printf " ${YELLOW}⚡${NC} Creating ~/.bashrc for shell integration\n"
touch "$HOME/.bashrc"
shell_configs="$HOME/.bashrc"
fi
# Determine which integration block to use
integration_block="$BASE_INTEGRATION"
# This will be set later when create_completion_support() runs
# For now, we always use base integration, then update if completion is enabled
for config_file in $shell_configs; do
config_name=$(basename "$config_file")
# Remove any existing GitSSH integration first
remove_gitssh_integration "$config_file"
# Add the base integration block
printf "\n%s\n" "$integration_block" >> "$config_file"
printf " ${GREEN}✓${NC} Added integration to ${CYAN}%s${NC}\n" "$config_name"
done
log_success "Shell integration complete"
printf "\n"
}
# Update integration when completion is enabled
update_integration_for_completion() {
shell_configs=""
[ -f "$HOME/.bashrc" ] && shell_configs="$shell_configs $HOME/.bashrc"
[ -f "$HOME/.zshrc" ] && shell_configs="$shell_configs $HOME/.zshrc"
[ -f "$HOME/.profile" ] && shell_configs="$shell_configs $HOME/.profile"
for config_file in $shell_configs; do
if [ -f "$config_file" ]; then
# Remove existing integration
remove_gitssh_integration "$config_file"
# Add extended integration with completion
printf "\n%s\n" "$EXTENDED_INTEGRATION" >> "$config_file"
fi
done
}
initialize_system() {
log_step "5" "Initializing GitSSH v0.1.0 configuration"
# Test that the main executable works
printf " ${CYAN}⚡${NC} Testing GitSSH CLI...\n"
if "$MAIN_SCRIPT" version >/dev/null 2>&1; then
printf " ${GREEN}✓${NC} GitSSH CLI responds correctly\n"
else
log_error "GitSSH CLI failed to respond"
return 1
fi
# Run initialization
printf " ${CYAN}⚡${NC} Initializing system configuration...\n"
if "$MAIN_SCRIPT" init >/dev/null 2>&1; then
printf " ${GREEN}✓${NC} System initialized successfully\n"
else
log_warning "System initialization had issues"
printf " ${YELLOW}⚠${NC} You can run 'gitssh init' manually later\n"
fi
# Test basic CLI functionality
printf " ${CYAN}⚡${NC} Testing CLI commands...\n"
if "$MAIN_SCRIPT" help >/dev/null 2>&1; then
printf " ${GREEN}✓${NC} Help system working\n"
else
log_warning "Help system may not be working properly"
fi
log_success "System initialization complete"
printf "\n"
}
create_completion_support() {
printf "\n${CYAN}${BOLD}TAB COMPLETION${NC}\n"
printf "GitSSH v0.1.0 supports tab completion for enhanced usability.\n\n"
create_completion=$(interactive_prompt "Enable tab completion?" "yes" "Type 'yes' to enable, or 'no' to skip")
case "$create_completion" in
yes|y)
log_step "6" "Setting up tab completion"
completion_file="$INSTALL_DIR/completion.sh"
cat > "$completion_file" << 'EOF'
#!/bin/bash
# GitSSH v0.1.0 Tab Completion
_gitssh_completion() {
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
case $COMP_CWORD in
1)
opts="user session ssh remote clone commit push status info switch init onboard validate setup config help version"
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
;;
2)
case "${COMP_WORDS[1]}" in
user)
opts="add remove list status switch"
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
;;
session)
opts="set show clear forget list"
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
;;
ssh)
opts="status doctor repair test backup restore"
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
;;
remote)
opts="convert add check list recommendations"
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
;;
setup)
opts="github gitlab"
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
;;
config)
opts="show reset backup restore migrate"
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
;;
switch)
# Complete with available usernames if possible
if command -v gitssh >/dev/null 2>&1; then
local users=$(gitssh user list --simple 2>/dev/null)
COMPREPLY=( $(compgen -W "${users}" -- ${cur}) )
fi
;;
esac
;;
esac
}
# Register completion for gitssh command
complete -F _gitssh_completion gitssh
EOF
chmod +x "$completion_file"
printf " ${GREEN}✓${NC} Created completion script: ${CYAN}%s${NC}\n" "$completion_file"
# Update shell integration to include completion
update_integration_for_completion
printf " ${GREEN}✓${NC} Updated shell integration with completion support\n"
printf " ${BLUE}ℹ${NC} Will be loaded automatically in new shell sessions\n"
log_success "Tab completion setup complete"
printf "\n"
;;
*)
printf "${BLUE}Skipping tab completion setup${NC}\n\n"
;;
esac
}
#================================================================#
# ENHANCED FUNCTION REFERENCE
#================================================================#
show_function_reference() {
printf "${BOLD}${MAGENTA}📚 GitSSH v0.1.0 CLI REFERENCE${NC}\n"
printf "${MAGENTA}"
repeat_char '=' 80
printf "${NC}\n\n"
# Setup & Initialization
draw_box "SETUP & INITIALIZATION" "gitssh init Initialize GitSSH configuration
gitssh onboard Interactive first-time setup wizard
gitssh validate Validate system configuration
gitssh version Show version information
gitssh help Show comprehensive help"
printf "\n"
# User Management
draw_box "USER MANAGEMENT" "gitssh user add Add new user account
gitssh user remove <user> Remove user account
gitssh user list List all configured users
gitssh switch <user> Switch to user for current session
gitssh user switch <user> Switch to user locally
gitssh user switch -g <user> Switch to user globally
gitssh user status Show current user status"
printf "\n"
# Session Management
draw_box "SESSION MANAGEMENT" "gitssh session set Set user for current repository
gitssh session show Show current session status
gitssh session clear Clear session data
gitssh session forget Remove persistent config for repo
gitssh session list List all session repositories"
printf "\n"
# SSH Management
draw_box "SSH MANAGEMENT" "gitssh ssh status Show SSH configuration status
gitssh ssh doctor Diagnose SSH connection issues
gitssh ssh repair Fix common SSH problems
gitssh ssh test <host> Test SSH connection to host"
printf "\n"
# Setup Wizards
draw_box "SETUP WIZARDS" "gitssh setup github Setup GitHub SSH authentication
gitssh setup gitlab Setup GitLab SSH authentication"
printf "\n"
# Git Operations
draw_box "GIT OPERATIONS" "gitssh clone <url> Enhanced git clone with auto-setup
gitssh status Enhanced git status with user info
gitssh info Show detailed repository information
gitssh commit [opts] Enhanced git commit with verification
gitssh push [opts] Enhanced git push with verification"
printf "\n"
# Remote Management
draw_box "REMOTE MANAGEMENT" "gitssh remote convert Convert HTTPS remote to SSH
gitssh remote add <name> <url> Add remote with SSH conversion
gitssh remote check Check remote configuration
gitssh remote list List all remotes with details"
printf "\n"
# Configuration
draw_box "CONFIGURATION" "gitssh config show Show current configuration
gitssh config reset Reset configuration to defaults
gitssh config backup Backup configuration files
gitssh config restore Restore configuration from backup"
printf "\n"
# Global Commands (shortcuts)
draw_box "GLOBAL SHORTCUTS" "gitssh switch <user> Quick global user switch
gitssh <user> Direct user switch (if user exists)"
printf "\n"
}
show_usage_examples() {
printf "${BOLD}${BLUE}💡 USAGE EXAMPLES${NC}\n"
printf "${BLUE}"
repeat_char '=' 80
printf "${NC}\n\n"
draw_box "TYPICAL WORKFLOW" "# First time setup
gitssh onboard
# Add users
gitssh user add
# Follow prompts to configure 'work' and 'personal' accounts
# Switch globally to work account
gitssh switch work
# Clone a repository (auto-configures for current user)
gitssh clone git@github.com:company/project.git
# Work in repository with enhanced commands
cd project
gitssh status # Shows user info and SSH status
gitssh commit -m 'msg' # Verifies user before committing
gitssh push # Tests SSH before pushing
# Switch context for personal project
gitssh switch personal
cd ~/personal-project
gitssh session set # Set specific user for this repo"
printf "\n"
draw_box "ADVANCED FEATURES" "# Convert existing HTTPS repo to SSH
cd existing-repo
gitssh remote convert
# SSH management
gitssh ssh status # Check all SSH connections
gitssh ssh doctor # Diagnose issues
gitssh ssh test github-work # Test specific connection
# Session management
gitssh session show # Show current mappings
gitssh session list # List all managed repositories
gitssh session clear # Clear temporary session data
# System maintenance
gitssh validate # Check system health
gitssh config backup # Backup all configurations"
printf "\n"
}
#================================================================#
# INSTALLATION FLOW
#================================================================#
installation_summary() {
printf "${BOLD}${GREEN}🎉 GitSSH v0.1.0 INSTALLATION COMPLETE${NC}\n"
printf "${GREEN}"
repeat_char '=' 80
printf "${NC}\n\n"
module_count=$(find "$MODULES_DIR" -name "gitssh-*.sh" 2>/dev/null | wc -l)
draw_box "INSTALLATION SUMMARY" "Installation Location: $INSTALL_DIR/
Main Executable: $MAIN_SCRIPT
Modules Directory: $MODULES_DIR/
Symlink: $SYMLINK_PATH → $MAIN_SCRIPT
Configuration: ~/.gitssh-sessions.json & ~/.gitssh-users.json
Shell Integration: Added to detected shell config files
Module Count: $module_count modules installed
Tab Completion: $([ -f "$INSTALL_DIR/completion.sh" ] && echo "Enabled" || echo "Disabled")"
printf "\n"
draw_box "NEXT STEPS" "1. Restart terminal or run: source ~/.bashrc
2. Run first-time setup: gitssh onboard
3. Or initialize manually: gitssh init
4. Add users: gitssh user add
5. Get help anytime: gitssh help
6. Test installation: gitssh version"
printf "\n"
printf "${BOLD}${CYAN}🔧 QUICK ACCESS COMMANDS:${NC}\n"
printf " ${GREEN}•${NC} ${CYAN}gitssh help${NC} - Complete command reference\n"
printf " ${GREEN}•${NC} ${CYAN}gitssh onboard${NC} - First-time setup wizard\n"
printf " ${GREEN}•${NC} ${CYAN}gitssh user status${NC} - Check current status\n"
printf " ${GREEN}•${NC} ${CYAN}gitssh validate${NC} - Verify installation\n"
printf " ${GREEN}•${NC} ${CYAN}gitssh version${NC} - Show version info\n"
printf "\n"
}
interactive_install() {
show_welcome
printf "${BOLD}This installer will set up GitSSH v0.1.0 CLI tool${NC}\n"
printf "Follow along each step as the installer prompts\n"
printf "\n"
# Show what will be done
draw_box "WHAT WILL THE INSTALLER DO ?" "1. Detect and validate GitSSH v0.1.0 files
2. Check system dependencies (jq, git, ssh)
3. Install to ~/.local/bin/gitssh/ with modules/ subdirectory
4. Create symlink ~/.local/bin/gitssh for easy access
5. Add shell integration with PATH updates
6. Initialize configuration files
7. Optional: Set up tab completion
8. Test CLI functionality"
printf "\n"
continue_install=$(interactive_prompt "Do you want to continue?" "yes" "Type 'yes' to proceed with installation, or 'no' to cancel")
case "$continue_install" in
yes|y)
# Continue with installation
;;
*)
printf "${YELLOW}Installation cancelled by user${NC}\n"
return 0
;;
esac
printf "\n"
printf "${BOLD}${BLUE}Starting GitSSH v0.1.0 installation...${NC}\n"
printf "\n"
# Progress tracking
total_steps=5
current_step=0
# Step 1: File detection
current_step=$((current_step + 1))
progress_bar $current_step $total_steps "Detecting files"
if ! detect_modules; then
return 1
fi
# Structure validation
if ! validate_module_structure; then
log_warning "Structure validation had issues, continuing..."
fi
# Step 2: Dependencies
current_step=$((current_step + 1))
progress_bar $current_step $total_steps "Checking dependencies"
if ! check_dependencies; then
return 1
fi
# Step 3: System installation
current_step=$((current_step + 1))
progress_bar $current_step $total_steps "Installing CLI system"
if ! install_gitssh_system; then
log_error "CLI system installation failed"
return 1
fi
# Step 4: Shell integration
current_step=$((current_step + 1))
progress_bar $current_step $total_steps "Setting up shell integration"
setup_shell_integration
# Step 5: System initialization
current_step=$((current_step + 1))
progress_bar $current_step $total_steps "Initializing system"
if ! initialize_system; then
log_warning "System initialization had issues, but installation completed"
printf "You can run 'gitssh init' manually later\n"
fi
printf "\n"
# Optional tab completion
create_completion_support
log_success "Installation completed successfully!"
printf "\n"
# Show CLI reference
printf "\n${CYAN}${BOLD}DOCUMENTATION OPTIONS${NC}\n"
printf "GitSSH v0.1.0 includes comprehensive CLI documentation and examples.\n\n"
show_functions=$(interactive_prompt "Show complete CLI reference?" "yes" "Type 'yes' to see all available commands, or 'no' to skip")
case "$show_functions" in
yes|y)
printf "\n"
show_function_reference
;;
*)
printf "${BLUE}CLI reference skipped (run 'gitssh help' anytime)${NC}\n"
;;
esac
# Show usage examples
show_examples=$(interactive_prompt "Show usage examples?" "yes" "Type 'yes' to see practical examples, or 'no' to skip")
case "$show_examples" in
yes|y)
printf "\n"
show_usage_examples
;;
*)
printf "${BLUE}Usage examples skipped (run 'gitssh help' for examples)${NC}\n"
;;
esac
installation_summary
printf "${BOLD}${GREEN}Ready to use! Restart your terminal and run 'gitssh onboard' to get started.${NC}\n"
}
#================================================================#
# SYSTEM VERIFICATION
#================================================================#
verify_installation() {
log_info "Verifying GitSSH v0.1.0 installation integrity"
verification_passed=true
# Check main installation directory
if [ -d "$INSTALL_DIR" ]; then
printf " ${GREEN}✓${NC} Installation directory: ${CYAN}%s${NC}\n" "$INSTALL_DIR"
else
printf " ${RED}✗${NC} Installation directory missing: ${RED}%s${NC}\n" "$INSTALL_DIR"
verification_passed=false
fi
# Check modules directory
if [ -d "$MODULES_DIR" ]; then
printf " ${GREEN}✓${NC} Modules directory: ${CYAN}%s${NC}\n" "$MODULES_DIR"
else
printf " ${RED}✗${NC} Modules directory missing: ${RED}%s${NC}\n" "$MODULES_DIR"
verification_passed=false
fi
# Check main executable
if [ -f "$MAIN_SCRIPT" ] && [ -x "$MAIN_SCRIPT" ]; then
printf " ${GREEN}✓${NC} Main executable: ${CYAN}%s${NC}\n" "$MAIN_SCRIPT"
else
printf " ${RED}✗${NC} Main executable missing or not executable: ${RED}%s${NC}\n" "$MAIN_SCRIPT"
verification_passed=false
fi
# Check modules
module_count=0
for module in $REQUIRED_MODULES; do
if [ -f "$MODULES_DIR/$module" ]; then
module_count=$((module_count + 1))
fi
done