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