-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.sh
More file actions
743 lines (616 loc) · 19 KB
/
config.sh
File metadata and controls
743 lines (616 loc) · 19 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
#!/bin/bash
# Interactive configuration script for li
# Enhanced directory listing tool
#
# Copyright (c) 2025 Lotus-OS Core
# Licensed under MIT License
set -e
# Colors for output
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
# Configuration variables
CONFIG_DIR="${HOME}/.config/li"
CONFIG_FILE="${CONFIG_DIR}/config.ini"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Print functions
print_header() {
echo ""
echo -e "${CYAN}${BOLD}╔════════════════════════════════════════════════════════════╗${NC}"
echo -e "${CYAN}${BOLD}║ ║${NC}"
echo -e "${CYAN}${BOLD}║ Li Configuration Script ║${NC}"
echo -e "${CYAN}${BOLD}║ ║${NC}"
echo -e "${CYAN}${BOLD}╚════════════════════════════════════════════════════════════╝${NC}"
echo ""
}
print_section() {
echo ""
echo -e "${BOLD}${MAGENTA}━━━ $1 ━━━${NC}"
echo ""
}
print_step() {
echo -e "${BLUE}[*]${NC} $1"
}
print_success() {
echo -e "${GREEN}[✓]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[!]${NC} $1"
}
print_error() {
echo -e "${RED}[✗]${NC} $1"
}
print_info() {
echo -e "${CYAN}[i]${NC} $1"
}
# Interactive prompt function
prompt_yes_no() {
local prompt="$1"
local default="${2:-n}"
if [ "$default" = "y" ]; then
local options="[Y/n]"
else
local options="[y/N]"
fi
while true; do
echo -ne "${YELLOW}${prompt} ${options}: ${NC}"
read -r response
response=${response:-${default}}
case "$response" in
[Yy])
return 0
;;
[Nn])
return 1
;;
*)
print_error "Please enter 'y' or 'n'"
;;
esac
done
}
prompt_input() {
local prompt="$1"
local default="$2"
while true; do
if [ -n "$default" ]; then
echo -ne "${YELLOW}${prompt} [${default}]: ${NC}"
else
echo -ne "${YELLOW}${prompt}: ${NC}"
fi
read -r response
if [ -z "$response" ]; then
response="$default"
fi
if [ -n "$response" ]; then
PROMPT_RESULT="$response"
echo "$PROMPT_RESULT"
return 0
fi
print_error "Value cannot be empty"
done
}
prompt_list() {
local prompt="$1"
shift
local options=("$@")
echo -e "${YELLOW}${prompt}:${NC}"
echo ""
local i=1
for option in "${options[@]}"; do
echo " $i) $option"
((i++))
done
echo ""
while true; do
echo -ne "${YELLOW}Enter choice [1-${#options[@]}]: ${NC}"
read -r response
if [[ "$response" =~ ^[0-9]+$ ]] && [ "$response" -ge 1 ] && [ "$response" -le ${#options[@]} ]; then
PROMPT_RESULT="${options[$((response-1))]}"
echo "$PROMPT_RESULT"
return 0
else
print_error "Invalid choice. Please enter a number between 1 and ${#options[@]}"
fi
done
}
prompt_color() {
local prompt="${1:-Select color}"
echo -e "${YELLOW}${prompt}:${NC}"
echo ""
echo " 1) Black"
echo " 2) Red"
echo " 3) Green"
echo " 4) Yellow"
echo " 5) Blue"
echo " 6) Magenta"
echo " 7) Cyan"
echo " 8) White"
echo " 9) Bright Black"
echo " 10) Bright Red"
echo " 11) Bright Green"
echo " 12) Bright Yellow"
echo " 13) Bright Blue"
echo " 14) Bright Magenta"
echo " 15) Bright Cyan"
echo " 16) Bright White"
echo ""
while true; do
echo -ne "${YELLOW}Enter color [1-16]: ${NC}"
read -r response
local color_name=""
case "$response" in
1) color_name="black" ;;
2) color_name="red" ;;
3) color_name="green" ;;
4) color_name="yellow" ;;
5) color_name="blue" ;;
6) color_name="magenta" ;;
7) color_name="cyan" ;;
8) color_name="white" ;;
9) color_name="bright-black" ;;
10) color_name="bright-red" ;;
11) color_name="bright-green" ;;
12) color_name="bright-yellow" ;;
13) color_name="bright-blue" ;;
14) color_name="bright-magenta" ;;
15) color_name="bright-cyan" ;;
16) color_name="bright-white" ;;
*)
print_error "Invalid choice"
continue
;;
esac
if [ -n "$color_name" ]; then
PROMPT_RESULT="$color_name"
echo "$PROMPT_RESULT"
return 0
fi
done
}
# Create config directory
ensure_config_dir() {
print_step "Ensuring configuration directory exists..."
if [ ! -d "$CONFIG_DIR" ]; then
mkdir -p "$CONFIG_DIR"
print_success "Created $CONFIG_DIR"
else
print_info "Configuration directory already exists"
fi
}
# Load current configuration
load_config() {
print_step "Loading current configuration..."
if [ -f "$CONFIG_FILE" ]; then
print_success "Loaded existing configuration"
# Export current values
source <(grep -E '^[a-z_]+=' "$CONFIG_FILE" | sed 's/=/="/;s/$/"/' 2>/dev/null || true)
else
print_info "No existing configuration found, creating new one"
fi
}
# Save configuration
save_config() {
print_step "Saving configuration..."
cat > "$CONFIG_FILE" << EOF
# Li Configuration File
# Generated by config script
# Created: $(date '+%Y-%m-%d %H:%M:%S')
[general]
# Theme: dark, light, or auto
theme=${THEME:-dark}
# Show hidden files by default
show_hidden=${SHOW_HIDDEN:-false}
# Show inode numbers
show_inode=${SHOW_INODE:-false}
# Use long listing format by default
long_format=${LONG_FORMAT:-false}
# Recursively list directories
recursive=${RECURSIVE:-false}
# Use human readable sizes
human_readable=${HUMAN_READABLE:-true}
# List directories before files
dirs_first=${DIRS_FIRST:-true}
# Show file type icons
show_icons=${SHOW_ICONS:-true}
# Enable colors
show_colors=${SHOW_COLORS:-true}
# Default sort method: name, size, time, extension, type
sort_by=${SORT_BY:-name}
# Reverse sort order
reverse_sort=${REVERSE_SORT:-false}
# Time format: full-iso, long-iso, iso, relative
time_style=${TIME_STYLE:-long-iso}
# Enable git integration
enable_git=${ENABLE_GIT:-true}
# Default block size (for size formatting)
block_size=${BLOCK_SIZE:-1024}
[colors]
# Color scheme for file types
# Available colors: black, red, green, yellow, blue, magenta, cyan, white
# Bright variants: bright-black, bright-red, etc.
dir_color=${DIR_COLOR:-blue}
file_color=${FILE_COLOR:-white}
exec_color=${EXEC_COLOR:-green}
link_color=${LINK_COLOR:-cyan}
special_color=${SPECIAL_COLOR:-yellow}
[display]
# Terminal width override (0 = auto-detect)
width=${WIDTH:-0}
# Quoting style: literal, shell, shell-always, shell-escape, escape, locale, clocale
quoting_style=${QUOTING_STYLE:-literal}
# Hyperlink mode: always, auto, never
hyperlink_mode=${HYPERLINK_MODE:-auto}
# Indicator style: none, slash, file-type, classify
indicator_style=${INDICATOR_STYLE:-none}
[git]
# Show git status in directory listing
show_status=${SHOW_STATUS:-true}
# Show branch name
show_branch=${SHOW_BRANCH:-true}
# Show modified indicator
show_modified=${SHOW_MODIFIED:-true}
# Show untracked indicator
show_untracked=${SHOW_UNTRACKED:-true}
[custom]
# Custom file type associations (uncomment and modify as needed)
# .cpp=C++:blue
# .py=🐍:yellow
# .js=📜:yellow
# .md=📖:blue
# .json=📋:yellow
# .zip=📦:red
# Custom ignore patterns (similar to .gitignore)
# ignore=*.bak,*.tmp,*.log,*.swp
EOF
print_success "Configuration saved to $CONFIG_FILE"
}
# Configure general settings
configure_general() {
print_section "General Settings"
# Theme
prompt_list "Select theme" \
"Dark (for dark terminal backgrounds)" \
"Light (for light terminal backgrounds)" \
"Auto (detect from terminal)"
THEME="$PROMPT_RESULT"
case "$THEME" in
"Dark"*) THEME="dark" ;;
"Light"*) THEME="light" ;;
*) THEME="auto" ;;
esac
print_info "Theme: $THEME"
# Show hidden files
if prompt_yes_no "Show hidden files by default?" "${SHOW_HIDDEN:-n}"; then
SHOW_HIDDEN="true"
else
SHOW_HIDDEN="false"
fi
# Show inode numbers
if prompt_yes_no "Show inode numbers?" "${SHOW_INODE:-n}"; then
SHOW_INODE="true"
else
SHOW_INODE="false"
fi
# Long format
if prompt_yes_no "Use long listing format by default?" "${LONG_FORMAT:-n}"; then
LONG_FORMAT="true"
else
LONG_FORMAT="false"
fi
# Recursive listing
if prompt_yes_no "Recursively list directories by default?" "${RECURSIVE:-n}"; then
RECURSIVE="true"
else
RECURSIVE="false"
fi
# Human readable sizes
if prompt_yes_no "Use human readable sizes?" "${HUMAN_READABLE:-y}"; then
HUMAN_READABLE="true"
else
HUMAN_READABLE="false"
fi
# Directories first
if prompt_yes_no "List directories before files?" "${DIRS_FIRST:-y}"; then
DIRS_FIRST="true"
else
DIRS_FIRST="false"
fi
# Show icons
if prompt_yes_no "Show file type icons?" "${SHOW_ICONS:-y}"; then
SHOW_ICONS="true"
else
SHOW_ICONS="false"
fi
# Show colors
if prompt_yes_no "Enable colors?" "${SHOW_COLORS:-y}"; then
SHOW_COLORS="true"
else
SHOW_COLORS="false"
fi
# Sort by
local sort_options=("name" "size" "time" "extension" "type")
prompt_list "Default sort method" "${sort_options[@]}"
SORT_BY="$PROMPT_RESULT"
print_info "Sort by: $SORT_BY"
# Reverse sort
if prompt_yes_no "Reverse sort order?" "${REVERSE_SORT:-n}"; then
REVERSE_SORT="true"
else
REVERSE_SORT="false"
fi
# Time style
local time_options=("full-iso" "long-iso" "iso" "relative")
prompt_list "Time format" "${time_options[@]}"
TIME_STYLE="$PROMPT_RESULT"
print_info "Time style: $TIME_STYLE"
# Enable git
if prompt_yes_no "Enable git integration?" "${ENABLE_GIT:-y}"; then
ENABLE_GIT="true"
else
ENABLE_GIT="false"
fi
}
# Configure colors
configure_colors() {
print_section "Color Settings"
echo "Configure colors for different file types:"
echo ""
prompt_color "Directory color"
DIR_COLOR="${PROMPT_RESULT:-$DIR_COLOR:-blue}"
print_info "Directory color: $DIR_COLOR"
prompt_color "Regular file color"
FILE_COLOR="${PROMPT_RESULT:-$FILE_COLOR:-white}"
print_info "File color: $FILE_COLOR"
prompt_color "Executable file color"
EXEC_COLOR="${PROMPT_RESULT:-$EXEC_COLOR:-green}"
print_info "Executable color: $EXEC_COLOR"
prompt_color "Symlink color"
LINK_COLOR="${PROMPT_RESULT:-$LINK_COLOR:-cyan}"
print_info "Symlink color: $LINK_COLOR"
prompt_color "Special file (socket/pipe) color"
SPECIAL_COLOR="${PROMPT_RESULT:-$SPECIAL_COLOR:-yellow}"
print_info "Special file color: $SPECIAL_COLOR"
}
# Configure display settings
configure_display() {
print_section "Display Settings"
# Terminal width
prompt_input "Terminal width override (0 = auto-detect)" "${WIDTH:-0}"
WIDTH="$PROMPT_RESULT"
# Quoting style
local quoting_options=("literal" "shell" "shell-always" "shell-escape" "escape" "locale" "clocale")
prompt_list "Quoting style" "${quoting_options[@]}"
QUOTING_STYLE="$PROMPT_RESULT"
print_info "Quoting style: $QUOTING_STYLE"
# Hyperlink mode
local hyperlink_options=("always" "auto" "never")
prompt_list "Hyperlink mode" "${hyperlink_options[@]}"
HYPERLINK_MODE="$PROMPT_RESULT"
print_info "Hyperlink mode: $HYPERLINK_MODE"
# Indicator style
local indicator_options=("none" "slash" "file-type" "classify")
prompt_list "Indicator style" "${indicator_options[@]}"
INDICATOR_STYLE="$PROMPT_RESULT"
print_info "Indicator style: $INDICATOR_STYLE"
}
# Configure git settings
configure_git() {
print_section "Git Integration Settings"
# Show status
if prompt_yes_no "Show git status in directory listing?" "${SHOW_STATUS:-y}"; then
SHOW_STATUS="true"
else
SHOW_STATUS="false"
fi
# Show branch
if prompt_yes_no "Show branch name?" "${SHOW_BRANCH:-y}"; then
SHOW_BRANCH="true"
else
SHOW_BRANCH="false"
fi
# Show modified
if prompt_yes_no "Show modified file indicator?" "${SHOW_MODIFIED:-y}"; then
SHOW_MODIFIED="true"
else
SHOW_MODIFIED="false"
fi
# Show untracked
if prompt_yes_no "Show untracked file indicator?" "${SHOW_UNTRACKED:-y}"; then
SHOW_UNTRACKED="true"
else
SHOW_UNTRACKED="false"
fi
}
# Configure custom file associations
configure_custom() {
print_section "Custom File Associations"
echo "You can define custom icons and colors for file extensions."
echo "Format: extension=icon:color"
echo ""
if prompt_yes_no "Add custom file associations?" "n"; then
echo ""
echo "Enter custom associations (empty line to finish):"
echo "Examples:"
echo " .cpp=C++:blue"
echo " .py=🐍:yellow"
echo " .md=📖:blue"
echo ""
CUSTOM=""
while true; do
echo -ne "Extension (or empty to finish): "
read -r extension
if [ -z "$extension" ]; then
break
fi
echo -ne "Icon: "
read -r icon
prompt_color "Color"
local color="$PROMPT_RESULT"
CUSTOM="${CUSTOM}
${extension}=${icon}:${color}"
done
print_info "Custom associations saved"
fi
}
# Preview configuration
preview_config() {
print_section "Configuration Preview"
echo "General Settings:"
echo " Theme: $THEME"
echo " Show hidden: $SHOW_HIDDEN"
echo " Long format: $LONG_FORMAT"
echo " Human readable: $HUMAN_READABLE"
echo " Show icons: $SHOW_ICONS"
echo " Sort by: $SORT_BY"
echo " Enable git: $ENABLE_GIT"
echo ""
echo "Colors:"
echo " Directories: $DIR_COLOR"
echo " Files: $FILE_COLOR"
echo " Executables: $EXEC_COLOR"
echo " Symlinks: $LINK_COLOR"
echo ""
}
# Reset to defaults
reset_to_defaults() {
print_section "Reset to Defaults"
if prompt_yes_no "Reset all settings to defaults?" "n"; then
print_step "Resetting configuration..."
# Remove config file
rm -f "$CONFIG_FILE"
# Reset variables
THEME="dark"
SHOW_HIDDEN="false"
SHOW_INODE="false"
LONG_FORMAT="false"
RECURSIVE="false"
HUMAN_READABLE="true"
DIRS_FIRST="true"
SHOW_ICONS="true"
SHOW_COLORS="true"
SORT_BY="name"
REVERSE_SORT="false"
TIME_STYLE="long-iso"
ENABLE_GIT="true"
BLOCK_SIZE="1024"
DIR_COLOR="blue"
FILE_COLOR="white"
EXEC_COLOR="green"
LINK_COLOR="cyan"
SPECIAL_COLOR="yellow"
WIDTH="0"
QUOTING_STYLE="literal"
HYPERLINK_MODE="auto"
INDICATOR_STYLE="none"
SHOW_STATUS="true"
SHOW_BRANCH="true"
SHOW_MODIFIED="true"
SHOW_UNTRACKED="true"
print_success "Configuration reset to defaults"
fi
}
# Test configuration
test_config() {
print_section "Test Configuration"
if [ -f "$SCRIPT_DIR/li" ]; then
print_step "Testing with li binary..."
echo ""
"$SCRIPT_DIR/li" --config "$CONFIG_FILE" . 2>/dev/null || true
echo ""
print_info "Preview complete"
else
print_warning "li binary not found at $SCRIPT_DIR/li"
print_info "Skipping preview"
fi
}
# Print summary
print_summary() {
echo ""
echo -e "${GREEN}${BOLD}╔════════════════════════════════════════════════════════════╗${NC}"
echo -e "${GREEN}${BOLD}║ Configuration Complete! ║${NC}"
echo -e "${GREEN}${BOLD}╚════════════════════════════════════════════════════════════╝${NC}"
echo ""
echo "Configuration saved to: $CONFIG_FILE"
echo ""
echo "To apply changes, restart your terminal or run:"
echo " source ~/.bashrc # or ~/.zshrc"
echo ""
echo "To test the configuration:"
echo " li --config $CONFIG_FILE"
echo ""
}
# Main function
main() {
print_header
# Welcome message
echo -e "${BOLD}Welcome to the li configuration script!${NC}"
echo ""
echo "This script will guide you through configuring li's appearance and behavior."
echo "All settings are saved to: $CONFIG_FILE"
echo ""
# Initialize or load configuration
ensure_config_dir
load_config
# Main menu
while true; do
echo ""
echo -e "${BOLD}Configuration Menu:${NC}"
echo ""
echo " 1) General Settings"
echo " 2) Color Settings"
echo " 3) Display Settings"
echo " 4) Git Integration"
echo " 5) Custom File Associations"
echo " 6) Preview Configuration"
echo " 7) Reset to Defaults"
echo " 8) Save and Exit"
echo " 9) Exit without Saving"
echo ""
echo -ne "${YELLOW}Enter choice [1-9]: ${NC}"
read -r choice
case "$choice" in
1)
configure_general
;;
2)
configure_colors
;;
3)
configure_display
;;
4)
configure_git
;;
5)
configure_custom
;;
6)
preview_config
test_config
;;
7)
reset_to_defaults
;;
8)
save_config
print_summary
exit 0
;;
9)
echo "Exiting without saving."
exit 0
;;
*)
print_error "Invalid choice"
;;
esac
done
}
# Run main function
main "$@"