| 221 | |
| 222 | |
| 223 | def shell_config_value(name: str) -> str: |
| 224 | pattern = re.compile(rf"^\s*(?:export\s+)?{re.escape(name)}=(.*)$") |
| 225 | for path in SHELL_CONFIG_FILES: |
| 226 | if not path.exists() or not path.is_file(): |
| 227 | continue |
| 228 | try: |
| 229 | lines = path.read_text(encoding="utf-8").splitlines() |
| 230 | except Exception: |
| 231 | continue |
| 232 | for raw_line in reversed(lines): |
| 233 | line = raw_line.strip() |
| 234 | if not line or line.startswith("#"): |
| 235 | continue |
| 236 | match = pattern.match(line) |
| 237 | if not match: |
| 238 | continue |
| 239 | value = match.group(1).strip() |
| 240 | if len(value) >= 2 and value[0] == value[-1] and value[0] in {'"', "'"}: |
| 241 | value = value[1:-1] |
| 242 | return value.strip() |
| 243 | return "" |
| 244 | |
| 245 | |
| 246 | def env_config_value(*names: str, default: str = "") -> str: |