Skip to content

Add detect_environment() function for runtime re-detection#35

Merged
lunarcloud merged 3 commits intomainfrom
copilot/allow-re-run-environment-detection
Feb 10, 2026
Merged

Add detect_environment() function for runtime re-detection#35
lunarcloud merged 3 commits intomainfrom
copilot/allow-re-run-environment-detection

Conversation

Copy link
Contributor

Copilot AI commented Feb 10, 2026

Environment detection runs once on initial sourcing. Scripts that switch contexts (CI → interactive) or temporarily force fallback mode have no way to re-detect without re-sourcing the entire library.

Changes

  • init.sh: Add detect_environment() function encapsulating all detection logic

    • Defined as a reusable function that's called immediately for initial detection
    • Respects pre-set INTERFACE and GUI variables (only detects if unset)
    • Updates all environment globals: DETECTED_DESKTOP, INTERFACE, GUI, terminal, tool availability flags, sudo method, etc.
  • README.md: Document function and add usage example

  • helpers.sh: Remove duplicate detection code to maintain single source of truth

Usage

source script-dialog.sh

# Force fallback for CI operations
INTERFACE=""
GUI=false
# ... CI work ...

# Re-detect for interactive context
unset INTERFACE
unset GUI
detect_environment  # Now using whiptail/dialog/zenity as available

message-info "Now in interactive mode"

Backward compatible—existing scripts unchanged. Eliminates code duplication by defining the function once in init.sh.

Original prompt

We should allow users to re-run the environment detection, so that if they happen to force a mode, like fallback/dumb mode and then later go into another context (like going from CI to interactive contexts in a script).


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: lunarcloud <1565970+lunarcloud@users.noreply.github.com>
Copilot AI changed the title [WIP] Add ability to re-run environment detection for users Add detect_environment() function for runtime re-detection Feb 10, 2026
Copilot AI requested a review from lunarcloud February 10, 2026 17:37
init.sh Outdated
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to call detect_environment here instead of having duplicate code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! I've moved the detect_environment() function to init.sh and eliminated the duplicate code. The function is now defined once in init.sh (where it's called for initial detection) and can be called later for re-detection. This removes 165 lines of duplicate code from helpers.sh. (commit 4e90bd7)

Co-authored-by: lunarcloud <1565970+lunarcloud@users.noreply.github.com>
@lunarcloud lunarcloud marked this pull request as ready for review February 10, 2026 18:43
@lunarcloud lunarcloud merged commit 5d592ce into main Feb 10, 2026
1 check passed
@lunarcloud lunarcloud deleted the copilot/allow-re-run-environment-detection branch February 10, 2026 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants