#!/usr/bin/env pwsh <# .SYNOPSIS 展示代码仓库的镜像地址(支持横排/竖排) .DESCRIPTION File: git-mirror.ps1 URL: https://fx4.cn/gitmirror Author: Jetsung Chan Version: 0.2.0 UpdatedAt: 2025-12-10 .EXAMPLE ./git-mirror.ps1 -Org "jetsung" -Repo "sh" -Horizontal ./git-mirror.ps1 -Org "myorg" -GitHub -GitCode -H #> [CmdletBinding()] param( [Parameter(Mandatory = $true, HelpMessage = "组织名")] [Alias('o')] [string]$Org, [Parameter(HelpMessage = "仓库名(默认当前目录名)")] [Alias('r')] [string]$Repo, [Alias('gh')][switch]$GitHub, [Alias('ag')][switch]$GitCode, [Alias('fg')][switch]$Framagit, [Alias('cb')][switch]$Codeberg, [Alias('cp')][switch]$Codeup, # 新增:横排模式 [Alias('H')] [switch]$Horizontal ) Set-StrictMode -Version Latest $ErrorActionPreference = 'Stop' # 平台配置 $Platforms = @{ MYCODE = "https://git.jetsung.com" FRAMAGIT = "https://framagit.org" ATOMGIT = "https://atomgit.com" GITHUB = "https://github.com" CODEBERG = "https://codeberg.org" CODEUP = "https://codeup.aliyun.com/jetsung" } function Main { # 自动获取仓库名 if ([string]::IsNullOrWhiteSpace($Repo)) { $Repo = Split-Path -Leaf -Path (Get-Location).Path } if ([string]::IsNullOrWhiteSpace($Repo)) { Write-Error "Error: 无法确定仓库名" exit 1 } # 格式校验 if ($Org -notmatch '^[a-zA-Z0-9_-]+$' -or $Repo -notmatch '^[a-zA-Z0-9_-]+$') { Write-Error "Error: org 和 repo 只能包含字母、数字、- 和 _" exit 1 } # 组织名映射(支持特殊映射) $OrgMap = @{ MYCODE = $Org FRAMAGIT = $Org ATOMGIT = $Org GITHUB = $Org CODEBERG = $Org CODEUP = $Org } switch ($Org) { 'idev' { $OrgMap.GITHUB = 'idevsig'; $OrgMap.ATOMGIT = 'idev' } 'tiny' { $OrgMap.GITHUB = 'tinyzen'; $OrgMap.ATOMGIT = 'tinyzen' } } # 收集所有要显示的链接 $links = [System.Collections.Generic.List[string]]::new() $links.Add("[MyCode]($($Platforms.MYCODE)/$($OrgMap.MYCODE)/$Repo)") if ($Framagit) { $links.Add("[Framagit]($($Platforms.FRAMAGIT)/$($OrgMap.FRAMAGIT)/$Repo)") } if ($GitCode) { $links.Add("[AtomGit]($($Platforms.ATOMGIT)/$($OrgMap.ATOMGIT)/$Repo)") } if ($GitHub) { $links.Add("[GitHub]($($Platforms.GITHUB)/$($OrgMap.GITHUB)/$Repo)") } if ($Codeberg) { $links.Add("[Codeberg]($($Platforms.CODEBERG)/$($OrgMap.CODEBERG)/$Repo)") } if ($Codeup) { $links.Add("[Codeup]($($Platforms.CODEUP)/$($OrgMap.CODEUP)/$Repo)") } # 输出标题 Write-Host "`n## 仓库镜像`n" if ($Horizontal) { # 横排:完美居中的 ● 分隔 $links -join " ● " Write-Host "`n" } else { # 竖排(默认) foreach ($link in $links) { Write-Output "- $link" } Write-Host "" } } Main