Jetsung Chan ревизий этого фрагмента 1 month ago. К ревизии
2 files changed, 16 insertions, 16 deletions
git-mirror.ps1
| @@ -24,7 +24,7 @@ param( | |||
| 24 | 24 | [string]$Repo, | |
| 25 | 25 | ||
| 26 | 26 | [Alias('gh')][switch]$GitHub, | |
| 27 | - | [Alias('gc')][switch]$GitCode, | |
| 27 | + | [Alias('ag')][switch]$GitCode, | |
| 28 | 28 | [Alias('fg')][switch]$Framagit, | |
| 29 | 29 | [Alias('cb')][switch]$Codeberg, | |
| 30 | 30 | [Alias('cp')][switch]$Codeup, | |
| @@ -41,7 +41,7 @@ $ErrorActionPreference = 'Stop' | |||
| 41 | 41 | $Platforms = @{ | |
| 42 | 42 | MYCODE = "https://git.jetsung.com" | |
| 43 | 43 | FRAMAGIT = "https://framagit.org" | |
| 44 | - | GITCODE = "https://gitcode.com" | |
| 44 | + | ATOMGIT = "https://atomgit.com" | |
| 45 | 45 | GITHUB = "https://github.com" | |
| 46 | 46 | CODEBERG = "https://codeberg.org" | |
| 47 | 47 | CODEUP = "https://codeup.aliyun.com/jetsung" | |
| @@ -67,15 +67,15 @@ function Main { | |||
| 67 | 67 | $OrgMap = @{ | |
| 68 | 68 | MYCODE = $Org | |
| 69 | 69 | FRAMAGIT = $Org | |
| 70 | - | GITCODE = $Org | |
| 70 | + | ATOMGIT = $Org | |
| 71 | 71 | GITHUB = $Org | |
| 72 | 72 | CODEBERG = $Org | |
| 73 | 73 | CODEUP = $Org | |
| 74 | 74 | } | |
| 75 | 75 | ||
| 76 | 76 | switch ($Org) { | |
| 77 | - | 'idev' { $OrgMap.GITHUB = 'idevsig'; $OrgMap.GITCODE = 'idev' } | |
| 78 | - | 'tiny' { $OrgMap.GITHUB = 'tinyzen'; $OrgMap.GITCODE = 'tinyzen' } | |
| 77 | + | 'idev' { $OrgMap.GITHUB = 'idevsig'; $OrgMap.ATOMGIT = 'idev' } | |
| 78 | + | 'tiny' { $OrgMap.GITHUB = 'tinyzen'; $OrgMap.ATOMGIT = 'tinyzen' } | |
| 79 | 79 | } | |
| 80 | 80 | ||
| 81 | 81 | # 收集所有要显示的链接 | |
| @@ -84,7 +84,7 @@ function Main { | |||
| 84 | 84 | $links.Add("[MyCode]($($Platforms.MYCODE)/$($OrgMap.MYCODE)/$Repo)") | |
| 85 | 85 | ||
| 86 | 86 | if ($Framagit) { $links.Add("[Framagit]($($Platforms.FRAMAGIT)/$($OrgMap.FRAMAGIT)/$Repo)") } | |
| 87 | - | if ($GitCode) { $links.Add("[GitCode]($($Platforms.GITCODE)/$($OrgMap.GITCODE)/$Repo)") } | |
| 87 | + | if ($GitCode) { $links.Add("[AtomGit]($($Platforms.ATOMGIT)/$($OrgMap.ATOMGIT)/$Repo)") } | |
| 88 | 88 | if ($GitHub) { $links.Add("[GitHub]($($Platforms.GITHUB)/$($OrgMap.GITHUB)/$Repo)") } | |
| 89 | 89 | if ($Codeberg) { $links.Add("[Codeberg]($($Platforms.CODEBERG)/$($OrgMap.CODEBERG)/$Repo)") } | |
| 90 | 90 | if ($Codeup) { $links.Add("[Codeup]($($Platforms.CODEUP)/$($OrgMap.CODEUP)/$Repo)") } | |
git-mirror.sh
| @@ -13,7 +13,7 @@ | |||
| 13 | 13 | declare -A PLATFORMS=( | |
| 14 | 14 | ["MYCODE"]="https://git.jetsung.com" | |
| 15 | 15 | ["FRAMAGIT"]="https://framagit.org" | |
| 16 | - | ["GITCODE"]="https://gitcode.com" | |
| 16 | + | ["ATOMGIT"]="https://atomgit.com" | |
| 17 | 17 | ["GITHUB"]="https://github.com" | |
| 18 | 18 | ["CODEBERG"]="https://codeberg.org" | |
| 19 | 19 | ["CODEUP"]="https://codeup.aliyun.com/jetsung" | |
| @@ -21,14 +21,14 @@ declare -A PLATFORMS=( | |||
| 21 | 21 | ||
| 22 | 22 | parse_args() { | |
| 23 | 23 | local org="" repo="" | |
| 24 | - | local github="" gitcode="" framagit="" codeup="" codeberg="" horizontal="" | |
| 24 | + | local github="" atomgit="" framagit="" codeup="" codeberg="" horizontal="" | |
| 25 | 25 | ||
| 26 | 26 | while [[ $# -gt 0 ]]; do | |
| 27 | 27 | case "$1" in | |
| 28 | 28 | -o|--org) org="${2:-}"; shift 2 ;; | |
| 29 | 29 | -r|--repo) repo="${2:-}"; shift 2 ;; | |
| 30 | 30 | -gh|--github) github="YES"; shift ;; | |
| 31 | - | -gc|--gitcode) gitcode="YES"; shift ;; | |
| 31 | + | -ag|--atomgit) atomgit="YES"; shift ;; | |
| 32 | 32 | -fg|--framagit) framagit="YES"; shift ;; | |
| 33 | 33 | -cb|--codeberg) codeberg="YES"; shift ;; | |
| 34 | 34 | -cp|--codeup) codeup="YES"; shift ;; | |
| @@ -41,7 +41,7 @@ Options: | |||
| 41 | 41 | -o, --org 组织名(必填) | |
| 42 | 42 | -r, --repo 仓库名(默认当前目录) | |
| 43 | 43 | -gh, --github 显示 GitHub | |
| 44 | - | -gc, --gitcode 显示 GitCode | |
| 44 | + | -ag, --atomgit 显示 AtomGit | |
| 45 | 45 | -fg, --framagit 显示 Framagit | |
| 46 | 46 | -cb, --codeberg 显示 Codeberg | |
| 47 | 47 | -cp, --codeup 显示 Codeup | |
| @@ -61,7 +61,7 @@ EOF | |||
| 61 | 61 | ORG="$org" | |
| 62 | 62 | REPO="$repo" | |
| 63 | 63 | GITHUB="$github" | |
| 64 | - | GITCODE="$gitcode" | |
| 64 | + | ATOMGIT="$atomgit" | |
| 65 | 65 | FRAMAGIT="$framagit" | |
| 66 | 66 | CODEUP="$codeup" | |
| 67 | 67 | CODEBERG="$codeberg" | |
| @@ -70,7 +70,7 @@ EOF | |||
| 70 | 70 | ||
| 71 | 71 | main() { | |
| 72 | 72 | # 初始化全局变量 | |
| 73 | - | ORG="" REPO="" GITHUB="" GITCODE="" FRAMAGIT="" CODEUP="" CODEBERG="" HORIZONTAL="" | |
| 73 | + | ORG="" REPO="" GITHUB="" ATOMGIT="" FRAMAGIT="" CODEUP="" CODEBERG="" HORIZONTAL="" | |
| 74 | 74 | ||
| 75 | 75 | parse_args "$@" | |
| 76 | 76 | ||
| @@ -90,12 +90,12 @@ main() { | |||
| 90 | 90 | # 特殊组织映射 | |
| 91 | 91 | ORG_FRAMAGIT="$ORG" | |
| 92 | 92 | ORG_CODEUP="$ORG" | |
| 93 | - | ORG_GITCODE="$ORG" | |
| 93 | + | ORG_ATOMGIT="$ORG" | |
| 94 | 94 | ORG_GITHUB="$ORG" | |
| 95 | 95 | ORG_CODEBERG="$ORG" | |
| 96 | 96 | case "$ORG" in | |
| 97 | - | idev) ORG_GITHUB="idevsig"; ORG_GITCODE="idev" ;; | |
| 98 | - | tiny) ORG_GITHUB="tinyzen"; ORG_GITCODE="tinyzen" ;; | |
| 97 | + | idev) ORG_GITHUB="idevsig"; ORG_ATOMGIT="idev" ;; | |
| 98 | + | tiny) ORG_GITHUB="tinyzen"; ORG_ATOMGIT="tinyzen" ;; | |
| 99 | 99 | esac | |
| 100 | 100 | ||
| 101 | 101 | echo | |
| @@ -106,7 +106,7 @@ main() { | |||
| 106 | 106 | local links=() | |
| 107 | 107 | links+=("[MyCode](${PLATFORMS[MYCODE]}/${ORG}/${REPO})") | |
| 108 | 108 | [[ -n "$FRAMAGIT" ]] && links+=("[Framagit](${PLATFORMS[FRAMAGIT]}/${ORG_FRAMAGIT}/${REPO})") | |
| 109 | - | [[ -n "$GITCODE" ]] && links+=("[GitCode](${PLATFORMS[GITCODE]}/${ORG_GITCODE}/${REPO})") | |
| 109 | + | [[ -n "$ATOMGIT" ]] && links+=("[AtomGit](${PLATFORMS[ATOMGIT]}/${ORG_ATOMGIT}/${REPO})") | |
| 110 | 110 | [[ -n "$GITHUB" ]] && links+=("[GitHub](${PLATFORMS[GITHUB]}/${ORG_GITHUB}/${REPO})") | |
| 111 | 111 | [[ -n "$CODEBERG" ]] && links+=("[Codeberg](${PLATFORMS[CODEBERG]}/${ORG_CODEBERG}/${REPO})") | |
| 112 | 112 | [[ -n "$CODEUP" ]] && links+=("[Codeup](${PLATFORMS[CODEUP]}/${ORG_CODEUP}/${REPO})") | |
Jetsung Chan ревизий этого фрагмента 4 months ago. К ревизии
2 files changed, 246 insertions
git-mirror.ps1(файл создан)
| @@ -0,0 +1,109 @@ | |||
| 1 | + | #!/usr/bin/env pwsh | |
| 2 | + | <# | |
| 3 | + | .SYNOPSIS | |
| 4 | + | 展示代码仓库的镜像地址(支持横排/竖排) | |
| 5 | + | .DESCRIPTION | |
| 6 | + | File: git-mirror.ps1 | |
| 7 | + | URL: https://fx4.cn/gitmirror | |
| 8 | + | Author: Jetsung Chan <[email protected]> | |
| 9 | + | Version: 0.2.0 | |
| 10 | + | UpdatedAt: 2025-12-10 | |
| 11 | + | .EXAMPLE | |
| 12 | + | ./git-mirror.ps1 -Org "jetsung" -Repo "sh" -Horizontal | |
| 13 | + | ./git-mirror.ps1 -Org "myorg" -GitHub -GitCode -H | |
| 14 | + | #> | |
| 15 | + | ||
| 16 | + | [CmdletBinding()] | |
| 17 | + | param( | |
| 18 | + | [Parameter(Mandatory = $true, HelpMessage = "组织名")] | |
| 19 | + | [Alias('o')] | |
| 20 | + | [string]$Org, | |
| 21 | + | ||
| 22 | + | [Parameter(HelpMessage = "仓库名(默认当前目录名)")] | |
| 23 | + | [Alias('r')] | |
| 24 | + | [string]$Repo, | |
| 25 | + | ||
| 26 | + | [Alias('gh')][switch]$GitHub, | |
| 27 | + | [Alias('gc')][switch]$GitCode, | |
| 28 | + | [Alias('fg')][switch]$Framagit, | |
| 29 | + | [Alias('cb')][switch]$Codeberg, | |
| 30 | + | [Alias('cp')][switch]$Codeup, | |
| 31 | + | ||
| 32 | + | # 新增:横排模式 | |
| 33 | + | [Alias('H')] | |
| 34 | + | [switch]$Horizontal | |
| 35 | + | ) | |
| 36 | + | ||
| 37 | + | Set-StrictMode -Version Latest | |
| 38 | + | $ErrorActionPreference = 'Stop' | |
| 39 | + | ||
| 40 | + | # 平台配置 | |
| 41 | + | $Platforms = @{ | |
| 42 | + | MYCODE = "https://git.jetsung.com" | |
| 43 | + | FRAMAGIT = "https://framagit.org" | |
| 44 | + | GITCODE = "https://gitcode.com" | |
| 45 | + | GITHUB = "https://github.com" | |
| 46 | + | CODEBERG = "https://codeberg.org" | |
| 47 | + | CODEUP = "https://codeup.aliyun.com/jetsung" | |
| 48 | + | } | |
| 49 | + | ||
| 50 | + | function Main { | |
| 51 | + | # 自动获取仓库名 | |
| 52 | + | if ([string]::IsNullOrWhiteSpace($Repo)) { | |
| 53 | + | $Repo = Split-Path -Leaf -Path (Get-Location).Path | |
| 54 | + | } | |
| 55 | + | if ([string]::IsNullOrWhiteSpace($Repo)) { | |
| 56 | + | Write-Error "Error: 无法确定仓库名" | |
| 57 | + | exit 1 | |
| 58 | + | } | |
| 59 | + | ||
| 60 | + | # 格式校验 | |
| 61 | + | if ($Org -notmatch '^[a-zA-Z0-9_-]+$' -or $Repo -notmatch '^[a-zA-Z0-9_-]+$') { | |
| 62 | + | Write-Error "Error: org 和 repo 只能包含字母、数字、- 和 _" | |
| 63 | + | exit 1 | |
| 64 | + | } | |
| 65 | + | ||
| 66 | + | # 组织名映射(支持特殊映射) | |
| 67 | + | $OrgMap = @{ | |
| 68 | + | MYCODE = $Org | |
| 69 | + | FRAMAGIT = $Org | |
| 70 | + | GITCODE = $Org | |
| 71 | + | GITHUB = $Org | |
| 72 | + | CODEBERG = $Org | |
| 73 | + | CODEUP = $Org | |
| 74 | + | } | |
| 75 | + | ||
| 76 | + | switch ($Org) { | |
| 77 | + | 'idev' { $OrgMap.GITHUB = 'idevsig'; $OrgMap.GITCODE = 'idev' } | |
| 78 | + | 'tiny' { $OrgMap.GITHUB = 'tinyzen'; $OrgMap.GITCODE = 'tinyzen' } | |
| 79 | + | } | |
| 80 | + | ||
| 81 | + | # 收集所有要显示的链接 | |
| 82 | + | $links = [System.Collections.Generic.List[string]]::new() | |
| 83 | + | ||
| 84 | + | $links.Add("[MyCode]($($Platforms.MYCODE)/$($OrgMap.MYCODE)/$Repo)") | |
| 85 | + | ||
| 86 | + | if ($Framagit) { $links.Add("[Framagit]($($Platforms.FRAMAGIT)/$($OrgMap.FRAMAGIT)/$Repo)") } | |
| 87 | + | if ($GitCode) { $links.Add("[GitCode]($($Platforms.GITCODE)/$($OrgMap.GITCODE)/$Repo)") } | |
| 88 | + | if ($GitHub) { $links.Add("[GitHub]($($Platforms.GITHUB)/$($OrgMap.GITHUB)/$Repo)") } | |
| 89 | + | if ($Codeberg) { $links.Add("[Codeberg]($($Platforms.CODEBERG)/$($OrgMap.CODEBERG)/$Repo)") } | |
| 90 | + | if ($Codeup) { $links.Add("[Codeup]($($Platforms.CODEUP)/$($OrgMap.CODEUP)/$Repo)") } | |
| 91 | + | ||
| 92 | + | # 输出标题 | |
| 93 | + | Write-Host "`n## 仓库镜像`n" | |
| 94 | + | ||
| 95 | + | if ($Horizontal) { | |
| 96 | + | # 横排:完美居中的 ● 分隔 | |
| 97 | + | $links -join " ● " | |
| 98 | + | Write-Host "`n" | |
| 99 | + | } | |
| 100 | + | else { | |
| 101 | + | # 竖排(默认) | |
| 102 | + | foreach ($link in $links) { | |
| 103 | + | Write-Output "- $link" | |
| 104 | + | } | |
| 105 | + | Write-Host "" | |
| 106 | + | } | |
| 107 | + | } | |
| 108 | + | ||
| 109 | + | Main | |
git-mirror.sh(файл создан)
| @@ -0,0 +1,137 @@ | |||
| 1 | + | #!/usr/bin/env bash | |
| 2 | + | #============================================================ | |
| 3 | + | # File: git-mirror.sh | |
| 4 | + | # Description: 展示代码仓库的镜像地址(支持完美横排) | |
| 5 | + | # Author: Jetsung Chan <[email protected]> | |
| 6 | + | # Version: 0.2.0 | |
| 7 | + | # UpdatedAt: 2025-12-10 | |
| 8 | + | #============================================================ | |
| 9 | + | ||
| 10 | + | [[ -n "${DEBUG:-}" ]] && set -eux || set -euo pipefail | |
| 11 | + | ||
| 12 | + | # 平台 URL 配置 | |
| 13 | + | declare -A PLATFORMS=( | |
| 14 | + | ["MYCODE"]="https://git.jetsung.com" | |
| 15 | + | ["FRAMAGIT"]="https://framagit.org" | |
| 16 | + | ["GITCODE"]="https://gitcode.com" | |
| 17 | + | ["GITHUB"]="https://github.com" | |
| 18 | + | ["CODEBERG"]="https://codeberg.org" | |
| 19 | + | ["CODEUP"]="https://codeup.aliyun.com/jetsung" | |
| 20 | + | ) | |
| 21 | + | ||
| 22 | + | parse_args() { | |
| 23 | + | local org="" repo="" | |
| 24 | + | local github="" gitcode="" framagit="" codeup="" codeberg="" horizontal="" | |
| 25 | + | ||
| 26 | + | while [[ $# -gt 0 ]]; do | |
| 27 | + | case "$1" in | |
| 28 | + | -o|--org) org="${2:-}"; shift 2 ;; | |
| 29 | + | -r|--repo) repo="${2:-}"; shift 2 ;; | |
| 30 | + | -gh|--github) github="YES"; shift ;; | |
| 31 | + | -gc|--gitcode) gitcode="YES"; shift ;; | |
| 32 | + | -fg|--framagit) framagit="YES"; shift ;; | |
| 33 | + | -cb|--codeberg) codeberg="YES"; shift ;; | |
| 34 | + | -cp|--codeup) codeup="YES"; shift ;; | |
| 35 | + | -H|--horizontal) horizontal="YES"; shift ;; | |
| 36 | + | -h|--help) | |
| 37 | + | cat <<'EOF' | |
| 38 | + | Usage: gitmirror -o <org> [-r <repo>] [options] | |
| 39 | + | ||
| 40 | + | Options: | |
| 41 | + | -o, --org 组织名(必填) | |
| 42 | + | -r, --repo 仓库名(默认当前目录) | |
| 43 | + | -gh, --github 显示 GitHub | |
| 44 | + | -gc, --gitcode 显示 GitCode | |
| 45 | + | -fg, --framagit 显示 Framagit | |
| 46 | + | -cb, --codeberg 显示 Codeberg | |
| 47 | + | -cp, --codeup 显示 Codeup | |
| 48 | + | -H, --horizontal 横排显示(完美居中 ● 分隔) | |
| 49 | + | -h, --help 显示帮助 | |
| 50 | + | EOF | |
| 51 | + | exit 0 | |
| 52 | + | ;; | |
| 53 | + | *) | |
| 54 | + | echo "未知选项: $1" >&2 | |
| 55 | + | echo "使用 --help 查看帮助" >&2 | |
| 56 | + | exit 1 | |
| 57 | + | ;; | |
| 58 | + | esac | |
| 59 | + | done | |
| 60 | + | ||
| 61 | + | ORG="$org" | |
| 62 | + | REPO="$repo" | |
| 63 | + | GITHUB="$github" | |
| 64 | + | GITCODE="$gitcode" | |
| 65 | + | FRAMAGIT="$framagit" | |
| 66 | + | CODEUP="$codeup" | |
| 67 | + | CODEBERG="$codeberg" | |
| 68 | + | HORIZONTAL="$horizontal" | |
| 69 | + | } | |
| 70 | + | ||
| 71 | + | main() { | |
| 72 | + | # 初始化全局变量 | |
| 73 | + | ORG="" REPO="" GITHUB="" GITCODE="" FRAMAGIT="" CODEUP="" CODEBERG="" HORIZONTAL="" | |
| 74 | + | ||
| 75 | + | parse_args "$@" | |
| 76 | + | ||
| 77 | + | # 必填校验 | |
| 78 | + | [[ -z "$ORG" ]] && { echo "Error: 缺少 -o/--org 参数" >&2; exit 1; } | |
| 79 | + | ||
| 80 | + | # REPO 默认当前目录名 | |
| 81 | + | [[ -z "$REPO" ]] && REPO=$(basename "$PWD") | |
| 82 | + | [[ -z "$REPO" ]] && { echo "Error: 无法确定不了仓库名" >&2; exit 1; } | |
| 83 | + | ||
| 84 | + | # 简单格式校验 | |
| 85 | + | if ! [[ "$ORG" =~ ^[a-zA-Z0-9_-]+$ && "$REPO" =~ ^[a-zA-Z0-9_-]+$ ]]; then | |
| 86 | + | echo "Error: org 和 repo 只能包含字母、数字、- 和 _" >&2 | |
| 87 | + | exit 1 | |
| 88 | + | fi | |
| 89 | + | ||
| 90 | + | # 特殊组织映射 | |
| 91 | + | ORG_FRAMAGIT="$ORG" | |
| 92 | + | ORG_CODEUP="$ORG" | |
| 93 | + | ORG_GITCODE="$ORG" | |
| 94 | + | ORG_GITHUB="$ORG" | |
| 95 | + | ORG_CODEBERG="$ORG" | |
| 96 | + | case "$ORG" in | |
| 97 | + | idev) ORG_GITHUB="idevsig"; ORG_GITCODE="idev" ;; | |
| 98 | + | tiny) ORG_GITHUB="tinyzen"; ORG_GITCODE="tinyzen" ;; | |
| 99 | + | esac | |
| 100 | + | ||
| 101 | + | echo | |
| 102 | + | echo "## 仓库镜像" | |
| 103 | + | echo | |
| 104 | + | ||
| 105 | + | # 收集所有要显示的链接 | |
| 106 | + | local links=() | |
| 107 | + | links+=("[MyCode](${PLATFORMS[MYCODE]}/${ORG}/${REPO})") | |
| 108 | + | [[ -n "$FRAMAGIT" ]] && links+=("[Framagit](${PLATFORMS[FRAMAGIT]}/${ORG_FRAMAGIT}/${REPO})") | |
| 109 | + | [[ -n "$GITCODE" ]] && links+=("[GitCode](${PLATFORMS[GITCODE]}/${ORG_GITCODE}/${REPO})") | |
| 110 | + | [[ -n "$GITHUB" ]] && links+=("[GitHub](${PLATFORMS[GITHUB]}/${ORG_GITHUB}/${REPO})") | |
| 111 | + | [[ -n "$CODEBERG" ]] && links+=("[Codeberg](${PLATFORMS[CODEBERG]}/${ORG_CODEBERG}/${REPO})") | |
| 112 | + | [[ -n "$CODEUP" ]] && links+=("[Codeup](${PLATFORMS[CODEUP]}/${ORG_CODEUP}/${REPO})") | |
| 113 | + | ||
| 114 | + | if [[ "$HORIZONTAL" == "YES" ]]; then | |
| 115 | + | # 完美横排:每个链接之间用「 ● 」分隔(左右各一个空格) | |
| 116 | + | local first=1 | |
| 117 | + | for link in "${links[@]}"; do | |
| 118 | + | if (( first )); then | |
| 119 | + | printf "%s" "$link" | |
| 120 | + | first=0 | |
| 121 | + | else | |
| 122 | + | printf " ● %s" "$link" | |
| 123 | + | fi | |
| 124 | + | done | |
| 125 | + | echo | |
| 126 | + | echo | |
| 127 | + | # 空一行,保持和竖排一致 | |
| 128 | + | else | |
| 129 | + | # 竖排(原样) | |
| 130 | + | for link in "${links[@]}"; do | |
| 131 | + | echo "- $link" | |
| 132 | + | done | |
| 133 | + | echo | |
| 134 | + | fi | |
| 135 | + | } | |
| 136 | + | ||
| 137 | + | main "$@" | |