profile.ps1
· 3.6 KiB · PowerShell
Eredeti
function cc {
param ([Parameter(Position=0, ValueFromRemainingArguments=$true)][string[]]$UserArgs)
$defaultFile = "$HOME\.claude\settings.json"
$selected = $env:CLAUDE_DEFAULT # 完全靠环境变量控制默认(可为空)
$actualArgs = @()
$i = 0
# 第一参数:支持 modelscope / -modelscope / -anything
if ($UserArgs.Count -gt 0) {
$first = $UserArgs[0]
if ($first -match '^-?(.+)') {
$selected = $matches[1]
$i = 1
}
}
for (; $i -lt $UserArgs.Count; $i++) {
$actualArgs += $UserArgs[$i]
}
# ============ 超级详细日志 ============
Write-Host "========== cc 日志 ==========" -ForegroundColor DarkGray
Write-Host "你输入的完整参数: $($UserArgs -join ' ')" -ForegroundColor Gray
Write-Host "识别到的后缀: $selected" -ForegroundColor Gray
Write-Host "环境变量默认后缀: '$env:CLAUDE_DEFAULT'" -ForegroundColor Gray
$settingsFile = $null
$log = ""
if ($selected) {
$candidate = "$HOME\.claude\settings.json-$selected"
if (Test-Path $candidate) {
$settingsFile = $candidate
$log = "成功加载专用配置 → $settingsFile"
} else {
$log = "专用配置不存在 → $candidate"
}
} else {
$log = "未指定后缀"
}
if (-not $settingsFile -and (Test-Path $defaultFile)) {
$settingsFile = $defaultFile
$log += " → 回退到默认配置 → $defaultFile"
} elseif (-not $settingsFile) {
$log += " → 无任何配置文件,将直接运行 claude(无 --settings 参数)"
}
Write-Host $log -ForegroundColor Yellow
Write-Host "最终实际使用的配置文件: $($settingsFile ? $settingsFile : '无')" -ForegroundColor Green
Write-Host "===============================" -ForegroundColor DarkGray
# ======================================
$baseCmd = @('claude')
if ($settingsFile) { $baseCmd += '--settings', $settingsFile }
if ($actualArgs.Count -gt 0) {
# 一次性发送
$cmd = $baseCmd + $actualArgs
$cmdStr = $cmd | ForEach-Object { '"{0}"' -f $_ }
Write-Host "Executing → $cmdStr" -ForegroundColor White
if ($settingsFile) {
& claude --settings $settingsFile @actualArgs
} else {
& claude @actualArgs
}
} else {
# 交互模式
Write-Host "进入交互模式(按 Ctrl+C 退出)" -ForegroundColor White
if ($settingsFile) {
& claude --settings $settingsFile
} else {
& claude
}
}
}
function claude-modelscope-default {
# 1. 构造要执行的完整命令数组
$cmd = @('claude', '--settings', "$HOME\.claude\settings.json-mscope") + $args
# 2. 打印命令(用双引号包裹每个参数,方便阅读)
$cmdStr = $cmd | ForEach-Object { '"{0}"' -f $_ }
Write-Host "Executing: $cmdStr" -ForegroundColor Cyan
# 3. 真正执行(使用 & 调用运算符 + 参数展开)
& $cmd[0] $cmd[1..($cmd.Count-1)]
}
function claude-modelscope {
$env:ANTHROPIC_AUTH_TOKEN = $env:MODELSCOPE_API_KEY
cc modelscope $args
}
function claude-streamlake {
$env:ANTHROPIC_AUTH_TOKEN = $env:WQ_API_KEY
cc streamlake $args
}
function claude-minimax{
$env:ANTHROPIC_AUTH_TOKEN = $env:MINIMAX_API_KEY
cc minimax $args
}
function claude-minimax{
$env:ANTHROPIC_AUTH_TOKEN = $env:MINIMAX_API_KEY
cc minimax $args
}
function claude-longcat {
$env:ANTHROPIC_AUTH_TOKEN = $env:LONGCAT_API_KEY
cc longcat $args
}
| 1 | |
| 2 | function cc { |
| 3 | param ([Parameter(Position=0, ValueFromRemainingArguments=$true)][string[]]$UserArgs) |
| 4 | |
| 5 | $defaultFile = "$HOME\.claude\settings.json" |
| 6 | $selected = $env:CLAUDE_DEFAULT # 完全靠环境变量控制默认(可为空) |
| 7 | $actualArgs = @() |
| 8 | $i = 0 |
| 9 | |
| 10 | # 第一参数:支持 modelscope / -modelscope / -anything |
| 11 | if ($UserArgs.Count -gt 0) { |
| 12 | $first = $UserArgs[0] |
| 13 | if ($first -match '^-?(.+)') { |
| 14 | $selected = $matches[1] |
| 15 | $i = 1 |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | for (; $i -lt $UserArgs.Count; $i++) { |
| 20 | $actualArgs += $UserArgs[$i] |
| 21 | } |
| 22 | |
| 23 | # ============ 超级详细日志 ============ |
| 24 | Write-Host "========== cc 日志 ==========" -ForegroundColor DarkGray |
| 25 | Write-Host "你输入的完整参数: $($UserArgs -join ' ')" -ForegroundColor Gray |
| 26 | Write-Host "识别到的后缀: $selected" -ForegroundColor Gray |
| 27 | Write-Host "环境变量默认后缀: '$env:CLAUDE_DEFAULT'" -ForegroundColor Gray |
| 28 | |
| 29 | $settingsFile = $null |
| 30 | $log = "" |
| 31 | |
| 32 | if ($selected) { |
| 33 | $candidate = "$HOME\.claude\settings.json-$selected" |
| 34 | if (Test-Path $candidate) { |
| 35 | $settingsFile = $candidate |
| 36 | $log = "成功加载专用配置 → $settingsFile" |
| 37 | } else { |
| 38 | $log = "专用配置不存在 → $candidate" |
| 39 | } |
| 40 | } else { |
| 41 | $log = "未指定后缀" |
| 42 | } |
| 43 | |
| 44 | if (-not $settingsFile -and (Test-Path $defaultFile)) { |
| 45 | $settingsFile = $defaultFile |
| 46 | $log += " → 回退到默认配置 → $defaultFile" |
| 47 | } elseif (-not $settingsFile) { |
| 48 | $log += " → 无任何配置文件,将直接运行 claude(无 --settings 参数)" |
| 49 | } |
| 50 | |
| 51 | Write-Host $log -ForegroundColor Yellow |
| 52 | Write-Host "最终实际使用的配置文件: $($settingsFile ? $settingsFile : '无')" -ForegroundColor Green |
| 53 | Write-Host "===============================" -ForegroundColor DarkGray |
| 54 | # ====================================== |
| 55 | |
| 56 | $baseCmd = @('claude') |
| 57 | if ($settingsFile) { $baseCmd += '--settings', $settingsFile } |
| 58 | |
| 59 | if ($actualArgs.Count -gt 0) { |
| 60 | # 一次性发送 |
| 61 | $cmd = $baseCmd + $actualArgs |
| 62 | $cmdStr = $cmd | ForEach-Object { '"{0}"' -f $_ } |
| 63 | Write-Host "Executing → $cmdStr" -ForegroundColor White |
| 64 | if ($settingsFile) { |
| 65 | & claude --settings $settingsFile @actualArgs |
| 66 | } else { |
| 67 | & claude @actualArgs |
| 68 | } |
| 69 | } else { |
| 70 | # 交互模式 |
| 71 | Write-Host "进入交互模式(按 Ctrl+C 退出)" -ForegroundColor White |
| 72 | if ($settingsFile) { |
| 73 | & claude --settings $settingsFile |
| 74 | } else { |
| 75 | & claude |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | function claude-modelscope-default { |
| 81 | # 1. 构造要执行的完整命令数组 |
| 82 | $cmd = @('claude', '--settings', "$HOME\.claude\settings.json-mscope") + $args |
| 83 | |
| 84 | # 2. 打印命令(用双引号包裹每个参数,方便阅读) |
| 85 | $cmdStr = $cmd | ForEach-Object { '"{0}"' -f $_ } |
| 86 | Write-Host "Executing: $cmdStr" -ForegroundColor Cyan |
| 87 | |
| 88 | # 3. 真正执行(使用 & 调用运算符 + 参数展开) |
| 89 | & $cmd[0] $cmd[1..($cmd.Count-1)] |
| 90 | } |
| 91 | |
| 92 | function claude-modelscope { |
| 93 | $env:ANTHROPIC_AUTH_TOKEN = $env:MODELSCOPE_API_KEY |
| 94 | cc modelscope $args |
| 95 | } |
| 96 | |
| 97 | function claude-streamlake { |
| 98 | $env:ANTHROPIC_AUTH_TOKEN = $env:WQ_API_KEY |
| 99 | cc streamlake $args |
| 100 | } |
| 101 | |
| 102 | function claude-minimax{ |
| 103 | $env:ANTHROPIC_AUTH_TOKEN = $env:MINIMAX_API_KEY |
| 104 | cc minimax $args |
| 105 | } |
| 106 | |
| 107 | function claude-minimax{ |
| 108 | $env:ANTHROPIC_AUTH_TOKEN = $env:MINIMAX_API_KEY |
| 109 | cc minimax $args |
| 110 | } |
| 111 | |
| 112 | function claude-longcat { |
| 113 | $env:ANTHROPIC_AUTH_TOKEN = $env:LONGCAT_API_KEY |
| 114 | cc longcat $args |
| 115 | } |
| 116 |