(stdscr, friendly_names, num_items)
| 2613 | if in_marked_block: |
| 2614 | continue |
| 2615 | |
| 2616 | if not regex_pattern.search(line): |
| 2617 | filtered_lines.append(line) |
| 2618 | |
| 2619 | try: |
| 2620 | with open(BASHRC_PATH, "w") as f: |
| 2621 | f.writelines(filtered_lines) |
| 2622 | return True |
| 2623 | except Exception as e: |
| 2624 | print(f"Error writing to {BASHRC_PATH}: {e}") |
| 2625 | return False |
| 2626 | |
| 2627 | |
| 2628 | def update_bashrc(current_language_path, current_style): |
| 2629 | """Write the DedSec startup block without any hidden background workers.""" |
| 2630 | save_menu_style_preference(current_style) |
| 2631 | try: |
| 2632 | with open(BASHRC_PATH, "r", encoding="utf-8", errors="replace") as handle: |
| 2633 | lines = handle.readlines() |
| 2634 | except Exception as exc: |
| 2635 | print(_("Error reading") + f" {BASHRC_PATH}: {exc}") |
| 2636 | return |
| 2637 | |
| 2638 | filtered_lines = [] |
| 2639 | regex_pattern = re.compile( |
| 2640 | r"(cd\s+.*DedSec/Scripts.*python3\s+.*Settings\.py\s+--menu.*|" |
| 2641 | r"alias\s+(m|e|g)=.*cd\s+.*DedSec/Scripts.*|" |
| 2642 | r"Settings\.py.*--pipboy-scan)" |
| 2643 | ) |
| 2644 | in_marked_block = False |
| 2645 | for line in lines: |
| 2646 | if BASHRC_START_MARKER in line or (line.startswith("# --- DedSec ") and "Background Checker" in line): |
| 2647 | in_marked_block = True |
| 2648 | continue |
| 2649 | if BASHRC_END_MARKER in line or (line.startswith("# --- End DedSec ") and "Background Checker" in line): |
| 2650 | in_marked_block = False |
| 2651 | continue |
| 2652 | if in_marked_block: |
| 2653 | continue |
| 2654 | if not regex_pattern.search(line): |
| 2655 | filtered_lines.append(line) |
| 2656 | |
| 2657 | launch_style = "ded-guy" if current_style == "pipboy" else current_style |
| 2658 | startup = f'cd "{current_language_path}" && python3 "{SETTINGS_SCRIPT_PATH}" --menu {launch_style}; cd "{HOME_DIR}"\n' |
| 2659 | alias_line = "" |
| 2660 | if current_language_path == ENGLISH_BASE_PATH: |
| 2661 | alias_line = f'alias e=\'cd "{ENGLISH_BASE_PATH}" && python3 "{SETTINGS_SCRIPT_PATH}" --menu {launch_style}\'\n' |
| 2662 | elif current_language_path == GREEK_PATH_FULL: |
| 2663 | alias_line = f'alias g=\'cd "{GREEK_PATH_FULL}" && python3 "{SETTINGS_SCRIPT_PATH}" --menu {launch_style}\'\n' |
| 2664 | |
| 2665 | autostart_enabled = load_menu_autostart_preference() or current_style in {"pipboy", "dedsec_os"} |
| 2666 | filtered_lines.append("\n" + BASHRC_START_MARKER + "\n") |
| 2667 | if autostart_enabled: |
| 2668 | filtered_lines.append(startup) |
| 2669 | else: |
| 2670 | filtered_lines.append("# DedSec Menu auto-start disabled.\n") |
| 2671 | if alias_line: |
| 2672 | filtered_lines.append(alias_line) |
no test coverage detected