feat: 添加环境变量写入功能
- Claude Code: 写入 ANTHROPIC_BASE_URL, ANTHROPIC_AUTH_TOKEN - Codex: 写入 OPENAI_API_KEY, OPENAI_BASE_URL - Bash 脚本: 自动检测 shell 配置文件 (.bashrc/.zshrc/.profile) - PowerShell 脚本: 使用 [Environment]::SetEnvironmentVariable 设置用户环境变量 - 添加 API key 格式验证 - 修复文件末尾换行问题,使用单引号包裹值更安全 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -18,6 +18,19 @@ $DefaultBaseUrl = "https://api2.xcodecli.com"
|
||||
$CodexConfigDir = "$env:USERPROFILE\.codex"
|
||||
$CodexConfigFile = "$CodexConfigDir\config.toml"
|
||||
|
||||
# Function to write environment variable (User level)
|
||||
function Set-EnvVariable {
|
||||
param(
|
||||
[string]$Name,
|
||||
[string]$Value
|
||||
)
|
||||
# Set for current session
|
||||
[Environment]::SetEnvironmentVariable($Name, $Value, [System.EnvironmentVariableTarget]::Process)
|
||||
# Set permanently for user
|
||||
[Environment]::SetEnvironmentVariable($Name, $Value, [System.EnvironmentVariableTarget]::User)
|
||||
Write-Info "Environment variable set: $Name"
|
||||
}
|
||||
|
||||
# Color functions for output
|
||||
function Write-Info {
|
||||
param([string]$Message)
|
||||
@@ -192,6 +205,13 @@ env_key = "OPENAI_API_KEY"
|
||||
$authJsonPath = "$CodexConfigDir\auth.json"
|
||||
$authJson | ConvertTo-Json | Set-Content -Path $authJsonPath -Encoding UTF8
|
||||
Write-Success "Codex auth file written to: $authJsonPath"
|
||||
|
||||
# Set environment variables
|
||||
Write-Info "Setting environment variables..."
|
||||
Set-EnvVariable -Name "OPENAI_API_KEY" -Value $ApiKey
|
||||
Set-EnvVariable -Name "OPENAI_BASE_URL" -Value "$BaseUrl/v1"
|
||||
Write-Success "Environment variables configured"
|
||||
|
||||
return $true
|
||||
}
|
||||
catch {
|
||||
|
||||
Reference in New Issue
Block a user