Jetsung Chan 修订了这个 Gist 4 months ago. 转到此修订
2 files changed, 71 insertions, 14 deletions
README.md
| @@ -36,8 +36,15 @@ irm https://fx4.cn/initpwsh | iex | |||
| 36 | 36 | ccc # Claude CLI 路由器 | |
| 37 | 37 | claude-modelscope # 使用 ModelScope API | |
| 38 | 38 | claude-streamlake # 使用 StreamLake API | |
| 39 | - | claude-minimax # 使用 MiniMax API | |
| 39 | + | claude-router # 使用 Router API | |
| 40 | + | claude-openrouter # 使用 OpenRouter API | |
| 41 | + | claude-minimax # 使用 MiniMax API (已停止服务) | |
| 42 | + | claude-mimo # 使用 Mimo API (已停止服务) | |
| 40 | 43 | claude-longcat # 使用 LongCat API | |
| 44 | + | claude-aiping # 使用 Aiping API (已停止服务) | |
| 45 | + | claude-litellm # 使用 LiteLLM API | |
| 46 | + | claude-mylitellm # 使用 MyLiteLLM API | |
| 47 | + | claude-aihubmix # 使用 AiHubMix API | |
| 41 | 48 | ``` | |
| 42 | 49 | ||
| 43 | 50 | ### 环境变量配置 | |
| @@ -46,8 +53,15 @@ claude-longcat # 使用 LongCat API | |||
| 46 | 53 | ||
| 47 | 54 | * `MODELSCOPE_API_KEY`:ModelScope API 密钥 | |
| 48 | 55 | * `STREAMLAKE_API_KEY`:StreamLake API 密钥 | |
| 56 | + | * `ROUTER_API_KEY`:Router API 密钥 | |
| 57 | + | * `OPENROUTER_API_KEY`:OpenRouter API 密钥 | |
| 49 | 58 | * `MINIMAX_API_KEY`:MiniMax API 密钥 | |
| 59 | + | * `MIMO_API_KEY`:Mimo API 密钥 | |
| 50 | 60 | * `LONGCAT_API_KEY`:LongCat API 密钥 | |
| 61 | + | * `AIPING_API_KEY`:Aiping API 密钥 | |
| 62 | + | * `LITELLM_API_KEY`:LiteLLM API 密钥 | |
| 63 | + | * `MYLITELLM_API_KEY`:MyLiteLLM API 密钥 | |
| 64 | + | * `AIHUBMIX_API_KEY`:AiHubMix API 密钥 | |
| 51 | 65 | * `CLAUDE_DEFAULT`:默认使用的后缀(可选) | |
| 52 | 66 | ||
| 53 | 67 | 在 PowerShell 中设置环境变量: | |
claude.ps1
| @@ -2,7 +2,7 @@ | |||
| 2 | 2 | # File: claude.ps1 | |
| 3 | 3 | # Description: Claude CLI wrapper functions for various backends | |
| 4 | 4 | # Created: 2026-01-21 16:00:00 | |
| 5 | - | # Updated: 2026-01-21 16:46:00 | |
| 5 | + | # Updated: 2026-01-29 10:45:00 | |
| 6 | 6 | # | |
| 7 | 7 | ||
| 8 | 8 | function ccc { | |
| @@ -36,7 +36,8 @@ function ccc { | |||
| 36 | 36 | $log = "" | |
| 37 | 37 | ||
| 38 | 38 | if ($selected) { | |
| 39 | - | $candidate = "$HOME\.claude\settings.json-$selected" | |
| 39 | + | # 查找: settings.name.json | |
| 40 | + | $candidate = "$HOME\.claude\settings.$selected.json" | |
| 40 | 41 | if (Test-Path $candidate) { | |
| 41 | 42 | $settingsFile = $candidate | |
| 42 | 43 | $log = "成功加载专用配置 → $settingsFile" | |
| @@ -83,16 +84,20 @@ function ccc { | |||
| 83 | 84 | } | |
| 84 | 85 | } | |
| 85 | 86 | ||
| 86 | - | function claude-modelscope-default { | |
| 87 | - | # 1. 构造要执行的完整命令数组 | |
| 88 | - | $cmd = @('claude', '--settings', "$HOME\.claude\settings.json-mscope") + $args | |
| 89 | - | ||
| 90 | - | # 2. 打印命令(用双引号包裹每个参数,方便阅读) | |
| 91 | - | $cmdStr = $cmd | ForEach-Object { '"{0}"' -f $_ } | |
| 92 | - | Write-Host "Executing: $cmdStr" -ForegroundColor Cyan | |
| 93 | - | ||
| 94 | - | # 3. 真正执行(使用 & 调用运算符 + 参数展开) | |
| 95 | - | & $cmd[0] $cmd[1..($cmd.Count-1)] | |
| 87 | + | function Check-ServiceDate { | |
| 88 | + | param ( | |
| 89 | + | [string]$ServiceName, | |
| 90 | + | [string]$CutoffDate | |
| 91 | + | ) | |
| 92 | + | $currentDate = Get-Date -Format "yyyyMMdd" | |
| 93 | + | if ([int]$currentDate -gt [int]$CutoffDate) { | |
| 94 | + | $y = $CutoffDate.Substring(0,4) | |
| 95 | + | $m = $CutoffDate.Substring(4,2) | |
| 96 | + | $d = $CutoffDate.Substring(6,2) | |
| 97 | + | Write-Error "错误:$ServiceName 服务已于 ${y}年${m}月${d}日停止服务,此函数已禁用。" | |
| 98 | + | return $false | |
| 99 | + | } | |
| 100 | + | return $true | |
| 96 | 101 | } | |
| 97 | 102 | ||
| 98 | 103 | function claude-modelscope { | |
| @@ -105,12 +110,50 @@ function claude-streamlake { | |||
| 105 | 110 | ccc streamlake @args | |
| 106 | 111 | } | |
| 107 | 112 | ||
| 108 | - | function claude-minimax{ | |
| 113 | + | function claude-router { | |
| 114 | + | $env:ANTHROPIC_AUTH_TOKEN = $env:ROUTER_API_KEY | |
| 115 | + | ccc router @args | |
| 116 | + | } | |
| 117 | + | ||
| 118 | + | function claude-openrouter { | |
| 119 | + | $env:ANTHROPIC_AUTH_TOKEN = $env:OPENROUTER_API_KEY | |
| 120 | + | ccc openrouter @args | |
| 121 | + | } | |
| 122 | + | ||
| 123 | + | function claude-minimax { | |
| 124 | + | if (-not (Check-ServiceDate -ServiceName "minimax" -CutoffDate "20251107")) { return } | |
| 109 | 125 | $env:ANTHROPIC_AUTH_TOKEN = $env:MINIMAX_API_KEY | |
| 110 | 126 | ccc minimax @args | |
| 111 | 127 | } | |
| 112 | 128 | ||
| 129 | + | function claude-mimo { | |
| 130 | + | if (-not (Check-ServiceDate -ServiceName "mimo" -CutoffDate "20260120")) { return } | |
| 131 | + | $env:ANTHROPIC_AUTH_TOKEN = $env:MIMO_API_KEY | |
| 132 | + | ccc mimo @args | |
| 133 | + | } | |
| 134 | + | ||
| 113 | 135 | function claude-longcat { | |
| 114 | 136 | $env:ANTHROPIC_AUTH_TOKEN = $env:LONGCAT_API_KEY | |
| 115 | 137 | ccc longcat @args | |
| 116 | 138 | } | |
| 139 | + | ||
| 140 | + | function claude-aiping { | |
| 141 | + | if (-not (Check-ServiceDate -ServiceName "aiping" -CutoffDate "20260109")) { return } | |
| 142 | + | $env:ANTHROPIC_AUTH_TOKEN = $env:AIPING_API_KEY | |
| 143 | + | ccc aiping @args | |
| 144 | + | } | |
| 145 | + | ||
| 146 | + | function claude-litellm { | |
| 147 | + | $env:ANTHROPIC_AUTH_TOKEN = $env:LITELLM_API_KEY | |
| 148 | + | ccc litellm @args | |
| 149 | + | } | |
| 150 | + | ||
| 151 | + | function claude-mylitellm { | |
| 152 | + | $env:ANTHROPIC_AUTH_TOKEN = $env:MYLITELLM_API_KEY | |
| 153 | + | ccc mylitellm @args | |
| 154 | + | } | |
| 155 | + | ||
| 156 | + | function claude-aihubmix { | |
| 157 | + | $env:ANTHROPIC_API_KEY = $env:AIHUBMIX_API_KEY | |
| 158 | + | ccc aihubmix @args | |
| 159 | + | } | |
Jetsung Chan 修订了这个 Gist 4 months ago. 转到此修订
5 files changed, 364 insertions, 112 deletions
Makefile(文件已创建)
| @@ -0,0 +1,105 @@ | |||
| 1 | + | # Makefile for PowerShell script creation and timestamp management | |
| 2 | + | # Author: Claude Code | |
| 3 | + | # Description: Provides targets to create and manage PowerShell script files with standard header | |
| 4 | + | ||
| 5 | + | .PHONY: help init clean list status install test pull push | |
| 6 | + | ||
| 7 | + | # Default target | |
| 8 | + | help: | |
| 9 | + | @echo "Usage: make <target>" | |
| 10 | + | @echo "" | |
| 11 | + | @echo "Targets:" | |
| 12 | + | @echo " init <name>.ps1 - Create or update a PowerShell script" | |
| 13 | + | @echo " list - List all PowerShell scripts in the project" | |
| 14 | + | @echo " install - Install scripts to PowerShell profile directory" | |
| 15 | + | @echo " test - Test PowerShell scripts for syntax errors" | |
| 16 | + | @echo " status - Show git status" | |
| 17 | + | @echo " clean - Remove temporary files" | |
| 18 | + | @echo " pull - Pull changes from origin pwsh branch" | |
| 19 | + | @echo " push - Push changes to origin pwsh branch (e.g., make push ARGS='-f')" | |
| 20 | + | @echo "" | |
| 21 | + | ||
| 22 | + | # Create or update a powershell script | |
| 23 | + | init: | |
| 24 | + | @$(eval SCRIPT_NAME := $(word 3,$(MAKECMDGOALS))) | |
| 25 | + | @if [ -z "$(SCRIPT_NAME)" ]; then \ | |
| 26 | + | echo "Error: Script name required"; \ | |
| 27 | + | echo "Usage: make init <script_name>.ps1"; \ | |
| 28 | + | exit 1; \ | |
| 29 | + | fi | |
| 30 | + | @if [ ! -f "$(SCRIPT_NAME)" ]; then \ | |
| 31 | + | echo "Creating pwsh script: $(SCRIPT_NAME)"; \ | |
| 32 | + | echo "#" >> "$(SCRIPT_NAME)"; \ | |
| 33 | + | echo "# File: $(SCRIPT_NAME)" >> "$(SCRIPT_NAME)"; \ | |
| 34 | + | echo "# Description: " >> "$(SCRIPT_NAME)"; \ | |
| 35 | + | echo "# Created: $$(date '+%Y-%m-%d %H:%M:%S')" >> "$(SCRIPT_NAME)"; \ | |
| 36 | + | echo "# Updated: $$(date '+%Y-%m-%d %H:%M:%S')" >> "$(SCRIPT_NAME)"; \ | |
| 37 | + | echo "#" >> "$(SCRIPT_NAME)"; \ | |
| 38 | + | echo "" >> "$(SCRIPT_NAME)"; \ | |
| 39 | + | chmod +x "$(SCRIPT_NAME)"; \ | |
| 40 | + | echo "Created $(SCRIPT_NAME) with executable permissions"; \ | |
| 41 | + | else \ | |
| 42 | + | echo "Updating timestamp for existing script: $(SCRIPT_NAME)"; \ | |
| 43 | + | FILE_TIME=$$(stat -c %y "$(SCRIPT_NAME)" | cut -d' ' -f1,2 | cut -d'.' -f1); \ | |
| 44 | + | sed "s/# Updated: .*/# Updated: $$FILE_TIME/" "$(SCRIPT_NAME)" > "$(SCRIPT_NAME).tmp" && \ | |
| 45 | + | mv "$(SCRIPT_NAME).tmp" "$(SCRIPT_NAME)"; \ | |
| 46 | + | echo "Updated $(SCRIPT_NAME) with file modification time: $$FILE_TIME"; \ | |
| 47 | + | fi | |
| 48 | + | ||
| 49 | + | # Clean temporary files | |
| 50 | + | clean: | |
| 51 | + | @rm -f *.ps1.tmp | |
| 52 | + | @echo "Removed temporary files" | |
| 53 | + | ||
| 54 | + | # List all PowerShell scripts | |
| 55 | + | list: | |
| 56 | + | @echo "PowerShell scripts in this project:" | |
| 57 | + | @find . -name "*.ps1" -type f | sort | |
| 58 | + | ||
| 59 | + | # Show git status | |
| 60 | + | status: | |
| 61 | + | @git status --short | |
| 62 | + | ||
| 63 | + | # Install scripts to PowerShell profile directory | |
| 64 | + | install: | |
| 65 | + | @echo "Installing scripts to PowerShell profile directory..." | |
| 66 | + | @if [ -z "$$PROFILE" ]; then \ | |
| 67 | + | echo "Error: \$\$PROFILE is not set"; \ | |
| 68 | + | echo "Please run this in PowerShell, not bash"; \ | |
| 69 | + | exit 1; \ | |
| 70 | + | fi | |
| 71 | + | @PROFILE_DIR=$$(dirname "$$PROFILE"); \ | |
| 72 | + | echo "Profile directory: $$PROFILE_DIR"; \ | |
| 73 | + | mkdir -p "$$PROFILE_DIR"; \ | |
| 74 | + | cp -v profile.ps1 "$$PROFILE_DIR/"; \ | |
| 75 | + | cp -v claude.ps1 "$$PROFILE_DIR/"; \ | |
| 76 | + | echo "Installation complete. Restart PowerShell to load the new profile." | |
| 77 | + | ||
| 78 | + | # Test PowerShell scripts for syntax errors | |
| 79 | + | test: | |
| 80 | + | @echo "Testing PowerShell scripts..." | |
| 81 | + | @if command -v pwsh >/dev/null 2>&1; then \ | |
| 82 | + | for script in *.ps1; do \ | |
| 83 | + | if [ -f "$$script" ]; then \ | |
| 84 | + | echo "Testing $$script..."; \ | |
| 85 | + | pwsh -Command "Get-Content $$script | Out-Null" 2>&1; \ | |
| 86 | + | if [ $$? -eq 0 ]; then \ | |
| 87 | + | echo " ✓ $$script is valid"; \ | |
| 88 | + | else \ | |
| 89 | + | echo " ✗ $$script has errors"; \ | |
| 90 | + | fi; \ | |
| 91 | + | fi; \ | |
| 92 | + | done; \ | |
| 93 | + | else \ | |
| 94 | + | echo "Error: PowerShell (pwsh) is not installed or not in PATH"; \ | |
| 95 | + | echo "Skipping syntax validation"; \ | |
| 96 | + | fi | |
| 97 | + | ||
| 98 | + | push: | |
| 99 | + | @echo "Pushing from origin pwsh with arguments: $(ARGS)" | |
| 100 | + | git push origin main $(ARGS) | |
| 101 | + | ||
| 102 | + | pull: | |
| 103 | + | @echo "Pulling to origin pwsh with arguments: $(ARGS)" | |
| 104 | + | git pull origin main $(ARGS) | |
| 105 | + | ||
README.md
| @@ -1,3 +1,86 @@ | |||
| 1 | - | # Windows 终端配置初始化 | |
| 1 | + | # Windows PowerShell 配置初始化 | |
| 2 | 2 | ||
| 3 | - | 启动 PowerShell 时,自动加载。 | |
| 3 | + | 启动 PowerShell 时自动加载的配置文件。 | |
| 4 | + | ||
| 5 | + | ## 项目结构 | |
| 6 | + | ||
| 7 | + | 本项目采用分离式设计,将不同功能的脚本分开管理: | |
| 8 | + | ||
| 9 | + | * **`profile.ps1`**:主 profile 文件,启动时自动加载 | |
| 10 | + | * **`claude.ps1`**:Claude CLI wrapper 函数定义 | |
| 11 | + | * **`install.ps1`**:安装脚本,支持本地和云端安装 | |
| 12 | + | ||
| 13 | + | ## 安装方式 | |
| 14 | + | ||
| 15 | + | ### 本地安装 | |
| 16 | + | ||
| 17 | + | ```powershell | |
| 18 | + | .\install.ps1 | |
| 19 | + | ``` | |
| 20 | + | ||
| 21 | + | ### 云端安装 | |
| 22 | + | ||
| 23 | + | ```powershell | |
| 24 | + | irm https://fx4.cn/initpwsh | iex | |
| 25 | + | ``` | |
| 26 | + | ||
| 27 | + | ## 用法 | |
| 28 | + | ||
| 29 | + | 安装完成后,PowerShell 启动时会自动加载 profile,所有 Claude 函数即可使用。 | |
| 30 | + | ||
| 31 | + | ### Claude 函数 | |
| 32 | + | ||
| 33 | + | 项目中预定义了多个 `claude-*` 函数,用于便捷地使用不同的 AI 服务: | |
| 34 | + | ||
| 35 | + | ```powershell | |
| 36 | + | ccc # Claude CLI 路由器 | |
| 37 | + | claude-modelscope # 使用 ModelScope API | |
| 38 | + | claude-streamlake # 使用 StreamLake API | |
| 39 | + | claude-minimax # 使用 MiniMax API | |
| 40 | + | claude-longcat # 使用 LongCat API | |
| 41 | + | ``` | |
| 42 | + | ||
| 43 | + | ### 环境变量配置 | |
| 44 | + | ||
| 45 | + | 各个 Claude 函数使用对应的 API 密钥环境变量: | |
| 46 | + | ||
| 47 | + | * `MODELSCOPE_API_KEY`:ModelScope API 密钥 | |
| 48 | + | * `STREAMLAKE_API_KEY`:StreamLake API 密钥 | |
| 49 | + | * `MINIMAX_API_KEY`:MiniMax API 密钥 | |
| 50 | + | * `LONGCAT_API_KEY`:LongCat API 密钥 | |
| 51 | + | * `CLAUDE_DEFAULT`:默认使用的后缀(可选) | |
| 52 | + | ||
| 53 | + | 在 PowerShell 中设置环境变量: | |
| 54 | + | ||
| 55 | + | ```powershell | |
| 56 | + | $env:MODELSCOPE_API_KEY = "your_key_here" | |
| 57 | + | ``` | |
| 58 | + | ||
| 59 | + | ## 文件说明 | |
| 60 | + | ||
| 61 | + | ### install.ps1 | |
| 62 | + | ||
| 63 | + | 安装脚本,支持两种使用方式: | |
| 64 | + | ||
| 65 | + | 1. **本地安装**:从脚本所在目录读取 `profile.ps1` 和 `claude.ps1` | |
| 66 | + | 2. **云端安装**:从 `https://gist.asfd.cn/jetsung/pwsh/raw/HEAD` 下载文件 | |
| 67 | + | ||
| 68 | + | 脚本会自动创建 `$PROFILE` 目录,并将文件保存到正确位置。 | |
| 69 | + | ||
| 70 | + | ### profile.ps1 | |
| 71 | + | ||
| 72 | + | PowerShell 启动时自动加载的主配置文件。该文件会自动加载同目录的 `claude.ps1`。 | |
| 73 | + | ||
| 74 | + | ### claude.ps1 | |
| 75 | + | ||
| 76 | + | 包含所有 Claude CLI wrapper 函数的定义。 | |
| 77 | + | ||
| 78 | + | ## 注意事项 | |
| 79 | + | ||
| 80 | + | * 请勿将包含真实 API 密钥的文件提交到版本控制系统 | |
| 81 | + | * 安装完成后需要重启 PowerShell 以加载新的 profile | |
| 82 | + | * 确保 PowerShell 执行策略允许运行脚本 | |
| 83 | + | ||
| 84 | + | ## 仓库镜像 | |
| 85 | + | ||
| 86 | + | [Gist](https://gist.asfd.cn/jetsung/pwsh) | |
claude.ps1(文件已创建)
| @@ -0,0 +1,116 @@ | |||
| 1 | + | # | |
| 2 | + | # File: claude.ps1 | |
| 3 | + | # Description: Claude CLI wrapper functions for various backends | |
| 4 | + | # Created: 2026-01-21 16:00:00 | |
| 5 | + | # Updated: 2026-01-21 16:46:00 | |
| 6 | + | # | |
| 7 | + | ||
| 8 | + | function ccc { | |
| 9 | + | param ([Parameter(Position=0, ValueFromRemainingArguments=$true)][string[]]$UserArgs) | |
| 10 | + | ||
| 11 | + | $defaultFile = "$HOME\.claude\settings.json" | |
| 12 | + | $selected = $env:CLAUDE_DEFAULT # 完全靠环境变量控制默认(可为空) | |
| 13 | + | $actualArgs = @() | |
| 14 | + | $i = 0 | |
| 15 | + | ||
| 16 | + | # 第一参数:支持 modelscope / -modelscope / -anything | |
| 17 | + | if ($UserArgs.Count -gt 0) { | |
| 18 | + | $first = $UserArgs[0] | |
| 19 | + | if ($first -match '^-?(.+)') { | |
| 20 | + | $selected = $matches[1] | |
| 21 | + | $i = 1 | |
| 22 | + | } | |
| 23 | + | } | |
| 24 | + | ||
| 25 | + | for (; $i -lt $UserArgs.Count; $i++) { | |
| 26 | + | $actualArgs += $UserArgs[$i] | |
| 27 | + | } | |
| 28 | + | ||
| 29 | + | # ============ 超级详细日志 ============ | |
| 30 | + | Write-Host "========== ccc 日志 ==========" -ForegroundColor DarkGray | |
| 31 | + | Write-Host "你输入的完整参数: $($UserArgs -join ' ')" -ForegroundColor Gray | |
| 32 | + | Write-Host "识别到的后缀: $selected" -ForegroundColor Gray | |
| 33 | + | Write-Host "环境变量默认后缀: '$env:CLAUDE_DEFAULT'" -ForegroundColor Gray | |
| 34 | + | ||
| 35 | + | $settingsFile = $null | |
| 36 | + | $log = "" | |
| 37 | + | ||
| 38 | + | if ($selected) { | |
| 39 | + | $candidate = "$HOME\.claude\settings.json-$selected" | |
| 40 | + | if (Test-Path $candidate) { | |
| 41 | + | $settingsFile = $candidate | |
| 42 | + | $log = "成功加载专用配置 → $settingsFile" | |
| 43 | + | } else { | |
| 44 | + | $log = "专用配置不存在 → $candidate" | |
| 45 | + | } | |
| 46 | + | } else { | |
| 47 | + | $log = "未指定后缀" | |
| 48 | + | } | |
| 49 | + | ||
| 50 | + | if (-not $settingsFile -and (Test-Path $defaultFile)) { | |
| 51 | + | $settingsFile = $defaultFile | |
| 52 | + | $log += " → 回退到默认配置 → $defaultFile" | |
| 53 | + | } elseif (-not $settingsFile) { | |
| 54 | + | $log += " → 无任何配置文件,将直接运行 claude(无 --settings 参数)" | |
| 55 | + | } | |
| 56 | + | ||
| 57 | + | Write-Host $log -ForegroundColor Yellow | |
| 58 | + | Write-Host "最终实际使用的配置文件: $($settingsFile ? $settingsFile : '无')" -ForegroundColor Green | |
| 59 | + | Write-Host "===============================" -ForegroundColor DarkGray | |
| 60 | + | # ====================================== | |
| 61 | + | ||
| 62 | + | $baseCmd = @('claude') | |
| 63 | + | if ($settingsFile) { $baseCmd += '--settings', $settingsFile } | |
| 64 | + | ||
| 65 | + | if ($actualArgs.Count -gt 0) { | |
| 66 | + | # 一次性发送 | |
| 67 | + | $cmd = $baseCmd + $actualArgs | |
| 68 | + | $cmdStr = $cmd | ForEach-Object { '"{0}"' -f $_ } | |
| 69 | + | Write-Host "Executing → $cmdStr" -ForegroundColor White | |
| 70 | + | if ($settingsFile) { | |
| 71 | + | & claude --settings $settingsFile @actualArgs | |
| 72 | + | } else { | |
| 73 | + | & claude @actualArgs | |
| 74 | + | } | |
| 75 | + | } else { | |
| 76 | + | # 交互模式 | |
| 77 | + | Write-Host "进入交互模式(按 Ctrl+C 退出)" -ForegroundColor White | |
| 78 | + | if ($settingsFile) { | |
| 79 | + | & claude --settings $settingsFile | |
| 80 | + | } else { | |
| 81 | + | & claude | |
| 82 | + | } | |
| 83 | + | } | |
| 84 | + | } | |
| 85 | + | ||
| 86 | + | function claude-modelscope-default { | |
| 87 | + | # 1. 构造要执行的完整命令数组 | |
| 88 | + | $cmd = @('claude', '--settings', "$HOME\.claude\settings.json-mscope") + $args | |
| 89 | + | ||
| 90 | + | # 2. 打印命令(用双引号包裹每个参数,方便阅读) | |
| 91 | + | $cmdStr = $cmd | ForEach-Object { '"{0}"' -f $_ } | |
| 92 | + | Write-Host "Executing: $cmdStr" -ForegroundColor Cyan | |
| 93 | + | ||
| 94 | + | # 3. 真正执行(使用 & 调用运算符 + 参数展开) | |
| 95 | + | & $cmd[0] $cmd[1..($cmd.Count-1)] | |
| 96 | + | } | |
| 97 | + | ||
| 98 | + | function claude-modelscope { | |
| 99 | + | $env:ANTHROPIC_AUTH_TOKEN = $env:MODELSCOPE_API_KEY | |
| 100 | + | ccc modelscope @args | |
| 101 | + | } | |
| 102 | + | ||
| 103 | + | function claude-streamlake { | |
| 104 | + | $env:ANTHROPIC_AUTH_TOKEN = $env:STREAMLAKE_API_KEY | |
| 105 | + | ccc streamlake @args | |
| 106 | + | } | |
| 107 | + | ||
| 108 | + | function claude-minimax{ | |
| 109 | + | $env:ANTHROPIC_AUTH_TOKEN = $env:MINIMAX_API_KEY | |
| 110 | + | ccc minimax @args | |
| 111 | + | } | |
| 112 | + | ||
| 113 | + | function claude-longcat { | |
| 114 | + | $env:ANTHROPIC_AUTH_TOKEN = $env:LONGCAT_API_KEY | |
| 115 | + | ccc longcat @args | |
| 116 | + | } | |
install.ps1
| @@ -1 +1,44 @@ | |||
| 1 | - | ||
| 1 | + | # | |
| 2 | + | # File: install.ps1 | |
| 3 | + | # Description: PowerShell Profile 安装脚本,支持本地和云端安装 | |
| 4 | + | # Created: 2026-01-21 16:00:00 | |
| 5 | + | # Updated: 2026-01-21 16:46:00 | |
| 6 | + | # | |
| 7 | + | # 本地使用: .\install.ps1 | |
| 8 | + | # 云端使用: irm https://fx4.cn/initpwsh | iex | |
| 9 | + | ||
| 10 | + | $profileDir = Split-Path -Parent $PROFILE | |
| 11 | + | ||
| 12 | + | # 创建 $PROFILE 目录 | |
| 13 | + | if (-not (Test-Path $profileDir)) { | |
| 14 | + | New-Item -ItemType Directory -Path $profileDir -Force | Out-Null | |
| 15 | + | Write-Host "创建目录: $profileDir" -ForegroundColor Green | |
| 16 | + | } | |
| 17 | + | ||
| 18 | + | # 判断是本地还是云端安装 | |
| 19 | + | if ($PSScriptRoot) { | |
| 20 | + | # 本地安装 | |
| 21 | + | $profileContent = Get-Content -Path (Join-Path $PSScriptRoot "profile.ps1") -Raw | |
| 22 | + | Set-Content -Path $PROFILE -Value $profileContent -Encoding UTF8 | |
| 23 | + | Write-Host "已保存 profile 到: $PROFILE" -ForegroundColor Green | |
| 24 | + | ||
| 25 | + | $claudeSource = Join-Path $PSScriptRoot "claude.ps1" | |
| 26 | + | $claudeDest = Join-Path $profileDir "claude.ps1" | |
| 27 | + | Copy-Item -Path $claudeSource -Destination $claudeDest -Force | |
| 28 | + | Write-Host "已复制 claude.ps1 到: $claudeDest" -ForegroundColor Green | |
| 29 | + | } else { | |
| 30 | + | # 云端安装 | |
| 31 | + | $baseUrl = "https://gist.asfd.cn/jetsung/pwsh/raw/HEAD" | |
| 32 | + | ||
| 33 | + | $profileUrl = "$baseUrl/profile.ps1" | |
| 34 | + | $profilePath = $PROFILE | |
| 35 | + | Invoke-RestMethod -Uri $profileUrl -OutFile $profilePath | |
| 36 | + | Write-Host "已保存 profile 到: $profilePath" -ForegroundColor Green | |
| 37 | + | ||
| 38 | + | $claudeUrl = "$baseUrl/claude.ps1" | |
| 39 | + | $claudePath = Join-Path $profileDir "claude.ps1" | |
| 40 | + | Invoke-RestMethod -Uri $claudeUrl -OutFile $claudePath | |
| 41 | + | Write-Host "已保存 claude.ps1 到: $claudePath" -ForegroundColor Green | |
| 42 | + | } | |
| 43 | + | ||
| 44 | + | Write-Host "安装完成!请重启 PowerShell 以加载新的 profile。" -ForegroundColor Cyan | |
profile.ps1
| @@ -1,110 +1,15 @@ | |||
| 1 | - | ||
| 2 | - | function ccc { | |
| 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 "========== ccc 日志 ==========" -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 | - | ccc modelscope @args | |
| 95 | - | } | |
| 96 | - | ||
| 97 | - | function claude-streamlake { | |
| 98 | - | $env:ANTHROPIC_AUTH_TOKEN = $env:STREAMLAKE_API_KEY | |
| 99 | - | ccc streamlake @args | |
| 100 | - | } | |
| 101 | - | ||
| 102 | - | function claude-minimax{ | |
| 103 | - | $env:ANTHROPIC_AUTH_TOKEN = $env:MINIMAX_API_KEY | |
| 104 | - | ccc minimax @args | |
| 105 | - | } | |
| 106 | - | ||
| 107 | - | function claude-longcat { | |
| 108 | - | $env:ANTHROPIC_AUTH_TOKEN = $env:LONGCAT_API_KEY | |
| 109 | - | ccc longcat @args | |
| 1 | + | # | |
| 2 | + | # File: profile.ps1 | |
| 3 | + | # Description: PowerShell Profile,启动时自动加载 | |
| 4 | + | # Created: 2026-01-21 16:00:00 | |
| 5 | + | # Updated: 2026-01-21 16:46:00 | |
| 6 | + | # | |
| 7 | + | ||
| 8 | + | # 获取脚本所在目录 | |
| 9 | + | $scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path | |
| 10 | + | ||
| 11 | + | # 加载 claude 脚本 | |
| 12 | + | $claudeScript = Join-Path $scriptDir "claude.ps1" | |
| 13 | + | if (Test-Path $claudeScript) { | |
| 14 | + | . $claudeScript | |
| 110 | 15 | } | |
README.md(文件已创建)
| @@ -0,0 +1,3 @@ | |||
| 1 | + | # Windows 终端配置初始化 | |
| 2 | + | ||
| 3 | + | 启动 PowerShell 时,自动加载。 | |
install.ps1(文件已创建)
| @@ -0,0 +1 @@ | |||
| 1 | + | ||
profile.ps1
| @@ -95,7 +95,7 @@ function claude-modelscope { | |||
| 95 | 95 | } | |
| 96 | 96 | ||
| 97 | 97 | function claude-streamlake { | |
| 98 | - | $env:ANTHROPIC_AUTH_TOKEN = $env:WQ_API_KEY | |
| 98 | + | $env:ANTHROPIC_AUTH_TOKEN = $env:STREAMLAKE_API_KEY | |
| 99 | 99 | ccc streamlake @args | |
| 100 | 100 | } | |
| 101 | 101 | ||
profile.ps1
| @@ -91,25 +91,20 @@ function claude-modelscope-default { | |||
| 91 | 91 | ||
| 92 | 92 | function claude-modelscope { | |
| 93 | 93 | $env:ANTHROPIC_AUTH_TOKEN = $env:MODELSCOPE_API_KEY | |
| 94 | - | ccc modelscope $args | |
| 94 | + | ccc modelscope @args | |
| 95 | 95 | } | |
| 96 | 96 | ||
| 97 | 97 | function claude-streamlake { | |
| 98 | 98 | $env:ANTHROPIC_AUTH_TOKEN = $env:WQ_API_KEY | |
| 99 | - | ccc streamlake $args | |
| 99 | + | ccc streamlake @args | |
| 100 | 100 | } | |
| 101 | 101 | ||
| 102 | 102 | function claude-minimax{ | |
| 103 | 103 | $env:ANTHROPIC_AUTH_TOKEN = $env:MINIMAX_API_KEY | |
| 104 | - | ccc minimax $args | |
| 105 | - | } | |
| 106 | - | ||
| 107 | - | function claude-minimax{ | |
| 108 | - | $env:ANTHROPIC_AUTH_TOKEN = $env:MINIMAX_API_KEY | |
| 109 | - | ccc minimax $args | |
| 104 | + | ccc minimax @args | |
| 110 | 105 | } | |
| 111 | 106 | ||
| 112 | 107 | function claude-longcat { | |
| 113 | 108 | $env:ANTHROPIC_AUTH_TOKEN = $env:LONGCAT_API_KEY | |
| 114 | - | ccc longcat $args | |
| 109 | + | ccc longcat @args | |
| 115 | 110 | } | |
profile.ps1
| @@ -1,5 +1,5 @@ | |||
| 1 | 1 | ||
| 2 | - | function cc { | |
| 2 | + | function ccc { | |
| 3 | 3 | param ([Parameter(Position=0, ValueFromRemainingArguments=$true)][string[]]$UserArgs) | |
| 4 | 4 | ||
| 5 | 5 | $defaultFile = "$HOME\.claude\settings.json" | |
| @@ -21,7 +21,7 @@ function cc { | |||
| 21 | 21 | } | |
| 22 | 22 | ||
| 23 | 23 | # ============ 超级详细日志 ============ | |
| 24 | - | Write-Host "========== cc 日志 ==========" -ForegroundColor DarkGray | |
| 24 | + | Write-Host "========== ccc 日志 ==========" -ForegroundColor DarkGray | |
| 25 | 25 | Write-Host "你输入的完整参数: $($UserArgs -join ' ')" -ForegroundColor Gray | |
| 26 | 26 | Write-Host "识别到的后缀: $selected" -ForegroundColor Gray | |
| 27 | 27 | Write-Host "环境变量默认后缀: '$env:CLAUDE_DEFAULT'" -ForegroundColor Gray | |
| @@ -91,25 +91,25 @@ function claude-modelscope-default { | |||
| 91 | 91 | ||
| 92 | 92 | function claude-modelscope { | |
| 93 | 93 | $env:ANTHROPIC_AUTH_TOKEN = $env:MODELSCOPE_API_KEY | |
| 94 | - | cc modelscope $args | |
| 94 | + | ccc modelscope $args | |
| 95 | 95 | } | |
| 96 | 96 | ||
| 97 | 97 | function claude-streamlake { | |
| 98 | 98 | $env:ANTHROPIC_AUTH_TOKEN = $env:WQ_API_KEY | |
| 99 | - | cc streamlake $args | |
| 99 | + | ccc streamlake $args | |
| 100 | 100 | } | |
| 101 | 101 | ||
| 102 | 102 | function claude-minimax{ | |
| 103 | 103 | $env:ANTHROPIC_AUTH_TOKEN = $env:MINIMAX_API_KEY | |
| 104 | - | cc minimax $args | |
| 104 | + | ccc minimax $args | |
| 105 | 105 | } | |
| 106 | 106 | ||
| 107 | 107 | function claude-minimax{ | |
| 108 | 108 | $env:ANTHROPIC_AUTH_TOKEN = $env:MINIMAX_API_KEY | |
| 109 | - | cc minimax $args | |
| 109 | + | ccc minimax $args | |
| 110 | 110 | } | |
| 111 | 111 | ||
| 112 | 112 | function claude-longcat { | |
| 113 | 113 | $env:ANTHROPIC_AUTH_TOKEN = $env:LONGCAT_API_KEY | |
| 114 | - | cc longcat $args | |
| 114 | + | ccc longcat $args | |
| 115 | 115 | } | |
profile.ps1
| @@ -111,5 +111,5 @@ function claude-minimax{ | |||
| 111 | 111 | ||
| 112 | 112 | function claude-longcat { | |
| 113 | 113 | $env:ANTHROPIC_AUTH_TOKEN = $env:LONGCAT_API_KEY | |
| 114 | - | cc minimax $args | |
| 114 | + | cc longcat $args | |
| 115 | 115 | } | |
profile.ps1
| @@ -102,4 +102,14 @@ function claude-streamlake { | |||
| 102 | 102 | function claude-minimax{ | |
| 103 | 103 | $env:ANTHROPIC_AUTH_TOKEN = $env:MINIMAX_API_KEY | |
| 104 | 104 | cc minimax $args | |
| 105 | - | } | |
| 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 minimax $args | |
| 115 | + | } | |