-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdxsbash-config.sh
More file actions
executable file
·633 lines (575 loc) · 23.7 KB
/
Copy pathdxsbash-config.sh
File metadata and controls
executable file
·633 lines (575 loc) · 23.7 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
#!/bin/bash
#=================================================================
# DXSBash Interactive Configuration
# Repository: https://github.com/digitalxs/dxsbash
# Author: Luis Miguel P. Freitas
# Website: https://digitalxs.ca
# License: GPL-3.0
#
# Manages user preferences stored in ~/.dxsbash/user.conf
# Settings take effect in new shell sessions (or after: source ~/.bashrc)
#=================================================================
RC='\033[0m'
RED='\033[1;31m'
YELLOW='\033[1;33m'
GREEN='\033[1;32m'
BLUE='\033[1;34m'
CYAN='\033[1;36m'
WHITE='\033[1;37m'
DIM='\033[2m'
CONF_DIR="$HOME/.dxsbash"
CONF_FILE="$CONF_DIR/user.conf"
# DXSBash repository location (matches setup.sh's install path). Used
# to resolve Starship theme preset files.
DXSBASH_DIR="${DXSBASH_DIR:-$HOME/linuxtoolbox/dxsbash}"
STARSHIP_CONFIG="$HOME/.config/starship.toml"
STARSHIP_THEMES_DIR="$DXSBASH_DIR/starship-themes"
# ── Starship theme registry ───────────────────────────────────────
# Display name | filename in starship-themes/
STARSHIP_THEMES=(
"DXS Starship|dxs-starship.toml"
"Nerd Font Symbols|nerd-font-symbols.toml"
"Bracketed Segments|bracketed-segments.toml"
"Pastel Powerline|pastel-powerline.toml"
"Tokyo Night|tokyo-night.toml"
"Gruvbox Rainbow|gruvbox-rainbow.toml"
"Catppuccin Powerline|catppuccin-powerline.toml"
)
# ── Defaults ──────────────────────────────────────────────────────
DEF_EDITOR="nano"
DEF_HISTSIZE=500
DEF_HISTFILESIZE=10000
DEF_FASTFETCH="true"
DEF_PROMPT_STYLE="starship"
DEF_STARSHIP_THEME="dxs-starship.toml"
DEF_SECSUMMARY="false"
# ── Current (working) values ──────────────────────────────────────
CUR_EDITOR=""
CUR_HISTSIZE=""
CUR_HISTFILESIZE=""
CUR_FASTFETCH=""
CUR_PROMPT_STYLE=""
CUR_STARSHIP_THEME=""
CUR_SECSUMMARY=""
#=================================================================
# Banner
#=================================================================
display_banner() {
clear
echo -e "${BLUE}╔════════════════════════════════════════════════════════╗${RC}"
echo -e "${BLUE}║ ${WHITE}DXSBash Configuration${BLUE} ║${RC}"
echo -e "${BLUE}║ ${DIM}~/.dxsbash/user.conf${RC}${BLUE} ║${RC}"
echo -e "${BLUE}╚════════════════════════════════════════════════════════╝${RC}"
echo ""
}
#=================================================================
# Read one value from the conf file without sourcing it globally
#=================================================================
_read_conf() {
local key="$1"
local default="$2"
if [ ! -f "$CONF_FILE" ]; then
echo "$default"
return
fi
local val
val=$(grep -E "^export ${key}=" "$CONF_FILE" 2>/dev/null \
| head -1 \
| sed -E 's/^export [^=]+="?([^"]*)"?$/\1/')
echo "${val:-$default}"
}
#=================================================================
# Load config into CUR_* variables
#=================================================================
load_config() {
CUR_EDITOR=$( _read_conf "EDITOR" "$DEF_EDITOR")
CUR_HISTSIZE=$( _read_conf "HISTSIZE" "$DEF_HISTSIZE")
CUR_HISTFILESIZE=$( _read_conf "HISTFILESIZE" "$DEF_HISTFILESIZE")
CUR_FASTFETCH=$( _read_conf "DXSBASH_FASTFETCH" "$DEF_FASTFETCH")
CUR_PROMPT_STYLE=$( _read_conf "DXSBASH_PROMPT_STYLE" "$DEF_PROMPT_STYLE")
CUR_STARSHIP_THEME=$( _read_conf "DXSBASH_STARSHIP_THEME" "$DEF_STARSHIP_THEME")
CUR_SECSUMMARY=$( _read_conf "DXSBASH_SECSUMMARY" "$DEF_SECSUMMARY")
# If the starship symlink points at a known preset, trust the
# filesystem over the conf file — users may have run setup.sh or
# hand-edited the symlink since the conf was written.
if [ -L "$STARSHIP_CONFIG" ]; then
local target
target="$(readlink "$STARSHIP_CONFIG")"
local fname="${target##*/}"
case "$fname" in
starship.toml|dxs-starship.toml)
CUR_STARSHIP_THEME="dxs-starship.toml"
;;
nerd-font-symbols.toml|bracketed-segments.toml|\
pastel-powerline.toml|tokyo-night.toml|\
gruvbox-rainbow.toml|catppuccin-powerline.toml)
CUR_STARSHIP_THEME="$fname"
;;
esac
fi
}
#=================================================================
# Write current CUR_* values to the conf file
#=================================================================
save_config() {
mkdir -p "$CONF_DIR"
cat > "$CONF_FILE" <<EOF
# DXSBash User Configuration
# Generated by dxsbash-config on $(date '+%Y-%m-%d %H:%M:%S')
# Edit with: dxsbash-config
# Apply now: source ~/.bashrc (or ~/.zshrc)
export EDITOR="${CUR_EDITOR}"
export VISUAL="${CUR_EDITOR}"
export HISTSIZE=${CUR_HISTSIZE}
export HISTFILESIZE=${CUR_HISTFILESIZE}
export DXSBASH_FASTFETCH="${CUR_FASTFETCH}"
export DXSBASH_PROMPT_STYLE="${CUR_PROMPT_STYLE}"
export DXSBASH_STARSHIP_THEME="${CUR_STARSHIP_THEME}"
export DXSBASH_SECSUMMARY="${CUR_SECSUMMARY}"
EOF
# Fish cannot source POSIX files — write a fish-syntax twin so the
# same settings apply there (HISTSIZE has no fish equivalent).
cat > "$CONF_DIR/user.fish" <<EOF
# DXSBash User Configuration (fish)
# Generated by dxsbash-config on $(date '+%Y-%m-%d %H:%M:%S')
# Edit with: dxsbash-config
set -gx EDITOR "${CUR_EDITOR}"
set -gx VISUAL "${CUR_EDITOR}"
set -gx DXSBASH_FASTFETCH "${CUR_FASTFETCH}"
set -gx DXSBASH_PROMPT_STYLE "${CUR_PROMPT_STYLE}"
set -gx DXSBASH_STARSHIP_THEME "${CUR_STARSHIP_THEME}"
set -gx DXSBASH_SECSUMMARY "${CUR_SECSUMMARY}"
EOF
echo ""
echo -e "${GREEN} ✓ Saved to ${WHITE}$CONF_FILE${RC}"
echo -e "${GREEN} ✓ Fish settings written to ${WHITE}$CONF_DIR/user.fish${RC}"
echo -e "${YELLOW} Run ${WHITE}source ~/.bashrc${YELLOW} (or open a new terminal) to apply.${RC}"
echo ""
}
#=================================================================
# Detect available text editors
#=================================================================
detect_editors() {
AVAILABLE_EDITORS=()
local candidates=(nano vim neovim nvim joe micro emacs gedit kate mousepad xed)
for ed in "${candidates[@]}"; do
if command -v "$ed" &>/dev/null; then
# Normalise: prefer the canonical name users type
AVAILABLE_EDITORS+=("$ed")
fi
done
}
#=================================================================
# Show a summary table of current settings
#=================================================================
show_current_settings() {
local fastfetch_label
[ "$CUR_FASTFETCH" = "true" ] && fastfetch_label="${GREEN}enabled${RC}" || fastfetch_label="${RED}disabled${RC}"
local prompt_label
if [ "$CUR_PROMPT_STYLE" = "custom" ]; then
prompt_label="${CYAN}built-in custom${RC}"
else
prompt_label="${CYAN}Starship${RC}${DIM} (falls back to custom if not installed)${RC}"
fi
local theme_label
theme_label="${CYAN}$(starship_theme_display_name "$CUR_STARSHIP_THEME")${RC}"
local secsummary_label
[ "$CUR_SECSUMMARY" = "true" ] && secsummary_label="${GREEN}enabled${RC}" || secsummary_label="${RED}disabled${RC}"
echo -e "${BLUE}┌─────────────────────────────────────────────────────────┐${RC}"
echo -e "${BLUE}│ Current Configuration │${RC}"
echo -e "${BLUE}├──────────────────────┬──────────────────────────────────┤${RC}"
printf "${BLUE}│${RC} %-20s${BLUE}│${RC} %-32b${BLUE}│${RC}\n" "Editor" "${WHITE}$CUR_EDITOR${RC}"
printf "${BLUE}│${RC} %-20s${BLUE}│${RC} %-32s${BLUE}│${RC}\n" "History size" "$CUR_HISTSIZE entries"
printf "${BLUE}│${RC} %-20s${BLUE}│${RC} %-32s${BLUE}│${RC}\n" "History file" "$CUR_HISTFILESIZE entries"
printf "${BLUE}│${RC} %-20s${BLUE}│${RC} %-32b${BLUE}│${RC}\n" "Fastfetch" "$fastfetch_label"
printf "${BLUE}│${RC} %-20s${BLUE}│${RC} %-32b${BLUE}│${RC}\n" "Prompt style" "$prompt_label"
printf "${BLUE}│${RC} %-20s${BLUE}│${RC} %-32b${BLUE}│${RC}\n" "Starship theme" "$theme_label"
printf "${BLUE}│${RC} %-20s${BLUE}│${RC} %-32b${BLUE}│${RC}\n" "Security summary" "$secsummary_label"
echo -e "${BLUE}└──────────────────────┴──────────────────────────────────┘${RC}"
echo ""
}
#=================================================================
# Starship theme helpers
#=================================================================
# Given a filename (e.g. dxs-starship.toml), return the display name.
starship_theme_display_name() {
local file="$1"
local entry name fname
for entry in "${STARSHIP_THEMES[@]}"; do
name="${entry%%|*}"
fname="${entry##*|}"
if [ "$fname" = "$file" ]; then
echo "$name"
return
fi
done
echo "unknown ($file)"
}
# Switch ~/.config/starship.toml to point at the selected preset.
# The file under $STARSHIP_THEMES_DIR must exist; the caller is
# responsible for validating that.
apply_starship_theme() {
local fname="$1"
local src="$STARSHIP_THEMES_DIR/$fname"
if [ ! -e "$src" ]; then
echo -e "${RED} ✗ Theme file not found: $src${RC}"
return 1
fi
mkdir -p "$(dirname "$STARSHIP_CONFIG")"
# Replace any existing file/symlink and re-point at the preset.
if [ -L "$STARSHIP_CONFIG" ] || [ -e "$STARSHIP_CONFIG" ]; then
rm -f "$STARSHIP_CONFIG"
fi
ln -s "$src" "$STARSHIP_CONFIG"
echo -e "${GREEN} ✓ Linked $STARSHIP_CONFIG → $src${RC}"
return 0
}
#=================================================================
# Submenu — Editor
#=================================================================
configure_editor() {
display_banner
echo -e "${CYAN}▶ Text Editor${RC}"
echo -e " Current: ${WHITE}$CUR_EDITOR${RC}"
echo ""
detect_editors
if [ ${#AVAILABLE_EDITORS[@]} -eq 0 ]; then
echo -e "${RED} No supported editors found on this system.${RC}"
echo -e "${YELLOW} Install one with: sudo apt install nano${RC}"
echo ""
read -rp " Press Enter to return..."
return
fi
echo -e " Available editors on this system:"
echo ""
local i=1
for ed in "${AVAILABLE_EDITORS[@]}"; do
local marker=""
[ "$ed" = "$CUR_EDITOR" ] && marker=" ${GREEN}← current${RC}"
printf " ${WHITE}%d)${RC} %s%b\n" "$i" "$ed" "$marker"
(( i++ ))
done
echo ""
echo -e " ${WHITE}c)${RC} Enter a custom path"
echo -e " ${WHITE}0)${RC} Back"
echo ""
read -rp " Choice: " choice
case "$choice" in
0|"") return ;;
c|C)
read -rp " Enter full path to editor: " custom_ed
if [ -z "$custom_ed" ]; then
echo -e "${YELLOW} No input — keeping $CUR_EDITOR${RC}"
elif ! command -v "$custom_ed" &>/dev/null && [ ! -x "$custom_ed" ]; then
echo -e "${RED} '$custom_ed' not found or not executable.${RC}"
else
CUR_EDITOR="$custom_ed"
save_config
fi
;;
*)
if [[ "$choice" =~ ^[0-9]+$ ]] && [ "$choice" -ge 1 ] && [ "$choice" -le "${#AVAILABLE_EDITORS[@]}" ]; then
CUR_EDITOR="${AVAILABLE_EDITORS[$((choice-1))]}"
save_config
else
echo -e "${RED} Invalid choice.${RC}"
sleep 1
fi
;;
esac
}
#=================================================================
# Submenu — History
#=================================================================
configure_history() {
display_banner
echo -e "${CYAN}▶ Shell History${RC}"
echo ""
echo -e " ${WHITE}HISTSIZE${RC} — lines kept in memory during a session"
echo -e " ${WHITE}HISTFILESIZE${RC} — lines persisted to the history file"
echo ""
echo -e " Current: ${WHITE}HISTSIZE=${CUR_HISTSIZE}${RC} ${WHITE}HISTFILESIZE=${CUR_HISTFILESIZE}${RC}"
echo ""
echo -e " ${WHITE}1)${RC} Small (500 / 5 000)"
echo -e " ${WHITE}2)${RC} Medium (1 000 / 10 000) ${DIM}← default${RC}"
echo -e " ${WHITE}3)${RC} Large (5 000 / 50 000)"
echo -e " ${WHITE}4)${RC} Unlimited (no pruning)"
echo -e " ${WHITE}5)${RC} Custom values"
echo -e " ${WHITE}0)${RC} Back"
echo ""
read -rp " Choice: " choice
case "$choice" in
1) CUR_HISTSIZE=500; CUR_HISTFILESIZE=5000; save_config ;;
2) CUR_HISTSIZE=1000; CUR_HISTFILESIZE=10000; save_config ;;
3) CUR_HISTSIZE=5000; CUR_HISTFILESIZE=50000; save_config ;;
4) CUR_HISTSIZE=-1; CUR_HISTFILESIZE=-1; save_config ;;
5)
read -rp " HISTSIZE (entries in memory): " hs
read -rp " HISTFILESIZE (entries on disk): " hf
if [[ "$hs" =~ ^-?[0-9]+$ ]] && [[ "$hf" =~ ^-?[0-9]+$ ]]; then
CUR_HISTSIZE="$hs"
CUR_HISTFILESIZE="$hf"
save_config
else
echo -e "${RED} Invalid input — must be integers.${RC}"
sleep 1
fi
;;
0|"") return ;;
*) echo -e "${RED} Invalid choice.${RC}"; sleep 1 ;;
esac
}
#=================================================================
# Submenu — Prompt style
#=================================================================
configure_prompt() {
display_banner
echo -e "${CYAN}▶ Prompt Style${RC}"
echo ""
echo -e " ${WHITE}starship${RC} — Starship cross-shell prompt (recommended)"
echo -e " Falls back to built-in if Starship is not installed."
echo ""
echo -e " ${WHITE}custom${RC} — DXSBash built-in prompt"
echo -e " Colour-coded: username, path, git branch, exit code."
echo ""
local starship_status
if command -v starship &>/dev/null; then
starship_status="${GREEN}installed${RC}"
else
starship_status="${RED}not installed${RC}"
fi
echo -e " Starship: $starship_status"
echo -e " Current: ${WHITE}$CUR_PROMPT_STYLE${RC}"
echo ""
echo -e " ${WHITE}1)${RC} Starship prompt"
echo -e " ${WHITE}2)${RC} Built-in custom prompt"
echo -e " ${WHITE}0)${RC} Back"
echo ""
read -rp " Choice: " choice
case "$choice" in
1) CUR_PROMPT_STYLE="starship"; save_config ;;
2) CUR_PROMPT_STYLE="custom"; save_config ;;
0|"") return ;;
*) echo -e "${RED} Invalid choice.${RC}"; sleep 1 ;;
esac
}
#=================================================================
# Submenu — Starship theme
#=================================================================
configure_starship_theme() {
display_banner
echo -e "${CYAN}▶ Starship Theme${RC}"
echo ""
if [ ! -d "$STARSHIP_THEMES_DIR" ]; then
echo -e "${RED} Themes directory not found: $STARSHIP_THEMES_DIR${RC}"
echo -e "${YELLOW} Run dxsbash-repair or re-install DXSBash.${RC}"
echo ""
read -rp " Press Enter to return..."
return
fi
local starship_status
if command -v starship &>/dev/null; then
starship_status="${GREEN}installed${RC}"
else
starship_status="${RED}not installed${RC}${DIM} (themes will apply once starship is installed)${RC}"
fi
echo -e " Starship: $starship_status"
echo -e " Current: ${WHITE}$(starship_theme_display_name "$CUR_STARSHIP_THEME")${RC}"
echo ""
echo -e " Pick a preset:"
echo ""
local i=1
local entry name fname marker
for entry in "${STARSHIP_THEMES[@]}"; do
name="${entry%%|*}"
fname="${entry##*|}"
marker=""
[ "$fname" = "$CUR_STARSHIP_THEME" ] && marker=" ${GREEN}← current${RC}"
printf " ${WHITE}%d)${RC} %s%b\n" "$i" "$name" "$marker"
(( i++ ))
done
echo ""
echo -e " ${WHITE}0)${RC} Back"
echo ""
read -rp " Choice: " choice
if [ "$choice" = "0" ] || [ -z "$choice" ]; then
return
fi
if ! [[ "$choice" =~ ^[0-9]+$ ]] || \
[ "$choice" -lt 1 ] || [ "$choice" -gt "${#STARSHIP_THEMES[@]}" ]; then
echo -e "${RED} Invalid choice.${RC}"
sleep 1
return
fi
entry="${STARSHIP_THEMES[$((choice-1))]}"
name="${entry%%|*}"
fname="${entry##*|}"
echo ""
if apply_starship_theme "$fname"; then
CUR_STARSHIP_THEME="$fname"
# Switching to a Starship preset implies the user wants the
# Starship prompt active, not the built-in one.
if [ "$CUR_PROMPT_STYLE" != "starship" ]; then
CUR_PROMPT_STYLE="starship"
echo -e "${YELLOW} Prompt style switched to 'starship'.${RC}"
fi
save_config
echo -e "${GREEN} Theme set to: ${WHITE}$name${RC}"
sleep 1
else
sleep 2
fi
}
#=================================================================
# Submenu — Startup display (fastfetch)
#=================================================================
configure_fastfetch() {
display_banner
echo -e "${CYAN}▶ Startup Display (Fastfetch)${RC}"
echo ""
echo -e " Fastfetch shows system information when a new terminal opens."
echo -e " It is suppressed automatically in SSH sessions."
echo ""
local ff_status
if command -v fastfetch &>/dev/null; then
ff_status="${GREEN}installed${RC}"
else
ff_status="${RED}not installed${RC}"
fi
local ff_setting
[ "$CUR_FASTFETCH" = "true" ] && ff_setting="${GREEN}enabled${RC}" || ff_setting="${RED}disabled${RC}"
echo -e " Fastfetch: $ff_status"
echo -e " Current: $ff_setting"
echo ""
echo -e " ${WHITE}1)${RC} Enable fastfetch on startup"
echo -e " ${WHITE}2)${RC} Disable fastfetch on startup"
echo -e " ${WHITE}0)${RC} Back"
echo ""
read -rp " Choice: " choice
case "$choice" in
1) CUR_FASTFETCH="true"; save_config ;;
2) CUR_FASTFETCH="false"; save_config ;;
0|"") return ;;
*) echo -e "${RED} Invalid choice.${RC}"; sleep 1 ;;
esac
}
#=================================================================
# Submenu — Security summary at login
#=================================================================
configure_secsummary() {
display_banner
echo -e "${CYAN}▶ Security Summary at Login${RC}"
echo ""
echo -e " Shows a one-line security status when a new shell opens"
echo -e " (pending security updates, failed SSH logins, firewall"
echo -e " state, reboot-required). Unlike fastfetch it is ${WHITE}also"
echo -e " shown over SSH${RC}, where it is most useful."
echo ""
echo -e " It reads from a cache and refreshes in the background, so"
echo -e " it does not slow down opening a terminal. For the full"
echo -e " report run ${WHITE}dxsbash audit${RC}."
echo ""
local ss_setting
[ "$CUR_SECSUMMARY" = "true" ] && ss_setting="${GREEN}enabled${RC}" || ss_setting="${RED}disabled${RC}"
echo -e " Current: $ss_setting"
echo ""
echo -e " ${WHITE}1)${RC} Enable security summary at login"
echo -e " ${WHITE}2)${RC} Disable security summary at login"
echo -e " ${WHITE}0)${RC} Back"
echo ""
read -rp " Choice: " choice
case "$choice" in
1)
CUR_SECSUMMARY="true"
save_config
# Prime the cache now so the first login shows real data.
if [ -x "$DXSBASH_DIR/secsummary.sh" ]; then
"$DXSBASH_DIR/secsummary.sh" --refresh >/dev/null 2>&1 &
fi
;;
2) CUR_SECSUMMARY="false"; save_config ;;
0|"") return ;;
*) echo -e "${RED} Invalid choice.${RC}"; sleep 1 ;;
esac
}
#=================================================================
# Reset to defaults
#=================================================================
reset_to_defaults() {
display_banner
echo -e "${YELLOW} This will reset all DXSBash settings to their defaults:${RC}"
echo ""
echo -e " Editor → ${WHITE}$DEF_EDITOR${RC}"
echo -e " HISTSIZE → ${WHITE}$DEF_HISTSIZE${RC}"
echo -e " HISTFILESIZE → ${WHITE}$DEF_HISTFILESIZE${RC}"
echo -e " Fastfetch → ${WHITE}$DEF_FASTFETCH${RC}"
echo -e " Prompt style → ${WHITE}$DEF_PROMPT_STYLE${RC}"
echo -e " Starship theme → ${WHITE}$(starship_theme_display_name "$DEF_STARSHIP_THEME")${RC}"
echo -e " Security summary → ${WHITE}$DEF_SECSUMMARY${RC}"
echo ""
read -rp " Continue? (y/N): " confirm
if [[ "$confirm" =~ ^[Yy]$ ]]; then
CUR_EDITOR="$DEF_EDITOR"
CUR_HISTSIZE="$DEF_HISTSIZE"
CUR_HISTFILESIZE="$DEF_HISTFILESIZE"
CUR_FASTFETCH="$DEF_FASTFETCH"
CUR_PROMPT_STYLE="$DEF_PROMPT_STYLE"
CUR_STARSHIP_THEME="$DEF_STARSHIP_THEME"
CUR_SECSUMMARY="$DEF_SECSUMMARY"
apply_starship_theme "$DEF_STARSHIP_THEME" >/dev/null 2>&1 || true
save_config
else
echo -e "${YELLOW} Reset cancelled.${RC}"
sleep 1
fi
}
#=================================================================
# Main menu loop
#=================================================================
main_menu() {
while true; do
display_banner
load_config
show_current_settings
echo -e " ${WHITE}1)${RC} Editor preference ${DIM}(${CUR_EDITOR})${RC}"
echo -e " ${WHITE}2)${RC} Shell history ${DIM}(HISTSIZE=${CUR_HISTSIZE})${RC}"
echo -e " ${WHITE}3)${RC} Prompt style ${DIM}(${CUR_PROMPT_STYLE})${RC}"
echo -e " ${WHITE}4)${RC} Starship theme ${DIM}($(starship_theme_display_name "$CUR_STARSHIP_THEME"))${RC}"
echo -e " ${WHITE}5)${RC} Startup display ${DIM}(fastfetch=${CUR_FASTFETCH})${RC}"
echo -e " ${WHITE}6)${RC} Security summary ${DIM}(secsummary=${CUR_SECSUMMARY})${RC}"
echo -e " ${WHITE}7)${RC} Reset to defaults"
echo -e " ${WHITE}0)${RC} Exit"
echo ""
read -rp " Choice: " choice
case "$choice" in
1) configure_editor ;;
2) configure_history ;;
3) configure_prompt ;;
4) configure_starship_theme ;;
5) configure_fastfetch ;;
6) configure_secsummary ;;
7) reset_to_defaults ;;
0|"q"|"Q"|"exit") break ;;
*) echo -e "${RED} Invalid choice.${RC}"; sleep 1 ;;
esac
done
}
#=================================================================
# Entry point
#=================================================================
main() {
# Must be run interactively
if [ ! -t 0 ]; then
echo "dxsbash-config must be run in an interactive terminal." >&2
exit 1
fi
mkdir -p "$CONF_DIR"
load_config
main_menu
echo ""
echo -e "${CYAN} Configuration complete. Open a new terminal or run:${RC}"
echo -e " ${WHITE}source ~/.bashrc${RC} (bash)"
echo -e " ${WHITE}source ~/.zshrc${RC} (zsh)"
echo ""
}
main