#!/bin/bash

# Helper function to find which file contains a config option
findConfigFileForOption()
{
    local config_option="$1"

    # Global configs first.
    for config_file in $(find "$configs_dir" -type f -name "*" ! -name ".category"); do
        if [ -f "$config_file" ] && grep -q "^$config_option=" "$config_file"; then
            echo "$config_file"
            return 0
        fi
    done

    # Fall back to per-app configs (CFG_<APP>_*). Without this, tools that
    # mutate per-app CFGs (password reset, shortcut manager) silently no-op.
    if [[ -n "$containers_dir" && -d "$containers_dir" ]]; then
        for config_file in "$containers_dir"*/*.config; do
            if [ -f "$config_file" ] && grep -q "^$config_option=" "$config_file"; then
                echo "$config_file"
                return 0
            fi
        done
    fi
    return 1
}
