profile.ps1
· 2.0 KiB · PowerShell
Bruto
function cc {
param ([Parameter(Position=0, ValueFromRemainingArguments=$true)][string[]]$UserArgs)
# 颜色表(常用后缀高亮,其他白色)
$colorMap = @{
mscope = 'Cyan'; streamlake = 'Magenta'; opendevin = 'Green'; deepseek = 'Yellow'
groq = 'DarkCyan'; together = 'DarkMagenta'; azure = 'Blue'; openrouter = 'DarkGreen'
deepinfra = 'Red'; ollama = 'DarkYellow'; lmstudio = 'White'; local = 'Gray'
}
$selected = $env:CLAUDE_DEFAULT
$actualArgs = @()
for($i=0; $i -lt $UserArgs.Count; $i++) {
$arg = $UserArgs[$i]
# 支持 cc modescope(无 -)和 cc -mscope 两种写法
if ($arg -match '^-?(.+)$') {
$selected = $matches[1]
continue
}
$actualArgs += $arg
}
# 构建 settings 路径
$defaultFile = "$HOME\.claude\settings.json"
$selectedFile = if ($selected) { "$HOME\.claude\settings.json-$selected" } else { $defaultFile }
# 检查文件是否存在,不存在则不传 --settings(避免报错)
if ($selected -and -not (Test-Path $selectedFile)) {
Write-Host "警告:配置文件不存在 $selectedFile,使用默认配置" -ForegroundColor Yellow
$settings = $defaultFile
if (-not (Test-Path $defaultFile)) { $settings = $null } # 连默认都没有
} elseif (-not (Test-Path $defaultFile)) {
$settings = $null
} else {
$settings = $selectedFile
}
# 构建命令
$cmd = @('claude')
if ($settings) { $cmd += '--settings', $settings }
$cmd += $actualArgs
# 显示命令(美化)
$cmdStr = $cmd | ForEach-Object { '"{0}"' -f $_ }
$color = if ($colorMap.ContainsKey($selected)) { $colorMap[$selected] } else { 'White' }
$disp = if ($selected) { "($selected)" } else { "(default)" }
Write-Host "Executing cc $disp → $cmdStr" -ForegroundColor $color
# 执行
if ($settings) {
& claude --settings $settings @actualArgs
} else {
& claude @actualArgs
}
}
| 1 | function cc { |
| 2 | param ([Parameter(Position=0, ValueFromRemainingArguments=$true)][string[]]$UserArgs) |
| 3 | |
| 4 | # 颜色表(常用后缀高亮,其他白色) |
| 5 | $colorMap = @{ |
| 6 | mscope = 'Cyan'; streamlake = 'Magenta'; opendevin = 'Green'; deepseek = 'Yellow' |
| 7 | groq = 'DarkCyan'; together = 'DarkMagenta'; azure = 'Blue'; openrouter = 'DarkGreen' |
| 8 | deepinfra = 'Red'; ollama = 'DarkYellow'; lmstudio = 'White'; local = 'Gray' |
| 9 | } |
| 10 | |
| 11 | $selected = $env:CLAUDE_DEFAULT |
| 12 | $actualArgs = @() |
| 13 | |
| 14 | for($i=0; $i -lt $UserArgs.Count; $i++) { |
| 15 | $arg = $UserArgs[$i] |
| 16 | # 支持 cc modescope(无 -)和 cc -mscope 两种写法 |
| 17 | if ($arg -match '^-?(.+)$') { |
| 18 | $selected = $matches[1] |
| 19 | continue |
| 20 | } |
| 21 | $actualArgs += $arg |
| 22 | } |
| 23 | |
| 24 | # 构建 settings 路径 |
| 25 | $defaultFile = "$HOME\.claude\settings.json" |
| 26 | $selectedFile = if ($selected) { "$HOME\.claude\settings.json-$selected" } else { $defaultFile } |
| 27 | |
| 28 | # 检查文件是否存在,不存在则不传 --settings(避免报错) |
| 29 | if ($selected -and -not (Test-Path $selectedFile)) { |
| 30 | Write-Host "警告:配置文件不存在 $selectedFile,使用默认配置" -ForegroundColor Yellow |
| 31 | $settings = $defaultFile |
| 32 | if (-not (Test-Path $defaultFile)) { $settings = $null } # 连默认都没有 |
| 33 | } elseif (-not (Test-Path $defaultFile)) { |
| 34 | $settings = $null |
| 35 | } else { |
| 36 | $settings = $selectedFile |
| 37 | } |
| 38 | |
| 39 | # 构建命令 |
| 40 | $cmd = @('claude') |
| 41 | if ($settings) { $cmd += '--settings', $settings } |
| 42 | $cmd += $actualArgs |
| 43 | |
| 44 | # 显示命令(美化) |
| 45 | $cmdStr = $cmd | ForEach-Object { '"{0}"' -f $_ } |
| 46 | $color = if ($colorMap.ContainsKey($selected)) { $colorMap[$selected] } else { 'White' } |
| 47 | $disp = if ($selected) { "($selected)" } else { "(default)" } |
| 48 | Write-Host "Executing cc $disp → $cmdStr" -ForegroundColor $color |
| 49 | |
| 50 | # 执行 |
| 51 | if ($settings) { |
| 52 | & claude --settings $settings @actualArgs |
| 53 | } else { |
| 54 | & claude @actualArgs |
| 55 | } |
| 56 | } |