-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.ps1
More file actions
194 lines (171 loc) · 7.2 KB
/
setup.ps1
File metadata and controls
194 lines (171 loc) · 7.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# ================================================================================
# Git 拡張コマンド セットアップスクリプト (Windows)
# ================================================================================
# このスクリプトは以下の処理を実行します:
# 1. ユーザーディレクトリに bin フォルダを作成
# 2. git-plus.exe をビルド
# 3. 36個のgit拡張コマンド用に実行ファイルをコピー
# 4. ユーザーのPATH環境変数にbinディレクトリを追加
#
# これにより、git newbranch、git pr-merge などのコマンドが使用可能になります。
#
# 使用方法:
# .\setup.ps1
#
# 前提条件:
# - Go 1.25.3以上がインストールされていること
# - PowerShell実行ポリシーが適切に設定されていること
# ================================================================================
Write-Host "=== Git 拡張コマンド セットアップ ===" -ForegroundColor Cyan
Write-Host ""
# ================================================================================
# ステップ1: binディレクトリの作成
# ================================================================================
# ユーザープロファイル配下に bin フォルダを作成します
# 既に存在する場合はエラーを抑制します(-Force オプション)
$binPath = "$env:USERPROFILE\bin"
Write-Host "binディレクトリを作成中: $binPath" -ForegroundColor Yellow
New-Item -ItemType Directory -Force -Path $binPath | Out-Null
Write-Host ""
# ================================================================================
# ステップ2: git-plus.exe のビルド
# ================================================================================
# Goコンパイラを使用してgit-plus.exeをビルドします
# カレントディレクトリ(.)のGoソースコードをコンパイルし、
# binディレクトリに git-plus.exe として出力します
Write-Host "git-plusコマンドをビルド中..." -ForegroundColor Yellow
Write-Host ""
Write-Host " ビルド中: git-plus... " -NoNewline
# go build コマンドを実行し、標準出力とエラー出力の両方をキャプチャ
$output = go build -o "$binPath\git-plus.exe" . 2>&1
# ビルド結果を確認
if ($LASTEXITCODE -eq 0) {
Write-Host "✓ OK" -ForegroundColor Green
} else {
# ビルド失敗時はエラーメッセージを表示して終了
Write-Host "✗ FAILED" -ForegroundColor Red
Write-Host ""
Write-Host "エラー: ビルドに失敗しました" -ForegroundColor Red
Write-Host " $output" -ForegroundColor Red
exit 1
}
# ================================================================================
# ステップ3: 各コマンド用の実行ファイルをコピー
# ================================================================================
# git-plus.exe を36個のgit-xxxコマンド用にコピーします
# Windowsでは、main.goの実行ファイル名判定機能により、
# コピーした各実行ファイルが対応するサブコマンドとして動作します
#
# 例: git-newbranch.exe を実行すると、
# main.goがファイル名から "newbranch" コマンドを推測して実行します
$commands = @(
"git-newbranch",
"git-rename-branch",
"git-reset-tag",
"git-amend",
"git-squash",
"git-track",
"git-delete-local-branches",
"git-undo-last-commit",
"git-tag-diff",
"git-tag-diff-all",
"git-tag-checkout",
"git-stash-cleanup",
"git-stash-select",
"git-recent",
"git-step",
"git-sync",
"git-pr-create-merge",
"git-pr-merge",
"git-pr-list",
"git-pause",
"git-resume",
"git-create-repository",
"git-new-tag",
"git-browse",
"git-pr-checkout",
"git-clone-org",
"git-batch-clone",
"git-abort",
"git-issue-list",
"git-issue-create",
"git-issue-edit",
"git-issue-bulk-close",
"git-release-notes",
"git-repo-others",
"git-pr-browse",
"git-pr-issue-link",
"git-worktree-new",
"git-worktree-switch",
"git-worktree-delete"
)
Write-Host ""
Write-Host "コマンドのコピーを作成中..." -ForegroundColor Yellow
Write-Host ""
# 成功カウンタの初期化
$successCount = 0
# 各コマンド用に git-plus.exe をコピー
foreach ($cmd in $commands) {
Write-Host " 作成中: $cmd... " -NoNewline
# 既存のファイルがある場合は削除(クリーンインストール)
$targetPath = "$binPath\$cmd.exe"
if (Test-Path $targetPath) {
Remove-Item $targetPath -Force
}
# git-plus.exe をターゲット名でコピー
Copy-Item "$binPath\git-plus.exe" $targetPath
# コピー結果を確認
if ($LASTEXITCODE -eq 0 -or (Test-Path $targetPath)) {
Write-Host "✓ OK" -ForegroundColor Green
$successCount++
} else {
Write-Host "✗ FAILED" -ForegroundColor Red
}
}
Write-Host ""
Write-Host "コピー作成完了: $successCount 個" -ForegroundColor Green
# ================================================================================
# ステップ4: PATH環境変数への追加
# ================================================================================
# binディレクトリをユーザーのPATH環境変数に追加します
# これにより、どこからでも git xxx コマンドを実行できるようになります
Write-Host ""
Write-Host "PATHの設定を確認中..." -ForegroundColor Yellow
# ユーザー環境変数のPATHを取得
$currentPath = [Environment]::GetEnvironmentVariable("Path", "User")
# binディレクトリが既にPATHに含まれているか確認
if ($currentPath -notlike "*$binPath*") {
Write-Host "PATHに追加中: $binPath" -ForegroundColor Yellow
# 既存のPATHの先頭にbinディレクトリを追加
# 既存のPATHがない場合は、binディレクトリのみを設定
$newPath = if ($currentPath) {
"$binPath;$currentPath"
} else {
$binPath
}
# ユーザー環境変数を永続的に更新
[Environment]::SetEnvironmentVariable("Path", $newPath, "User")
# 現在のPowerShellセッションにも即座に反映
# これにより、スクリプト実行後すぐにコマンドを使用可能になります
$env:Path = "$binPath;$env:Path"
Write-Host "✓ PATHに追加しました" -ForegroundColor Green
Write-Host ""
Write-Host "注意: 他のPowerShellウィンドウで使用する場合は再起動が必要です" -ForegroundColor Cyan
} else {
Write-Host "✓ 既にPATHに含まれています" -ForegroundColor Green
}
# ================================================================================
# セットアップ完了メッセージと使用例
# ================================================================================
Write-Host ""
Write-Host "=== セットアップ完了 ===" -ForegroundColor Green
Write-Host ""
Write-Host "使用例:" -ForegroundColor Cyan
Write-Host " git newbranch feature-xxx"
Write-Host " git new-tag feature"
Write-Host " git browse"
Write-Host ""
Write-Host "ヘルプを表示:" -ForegroundColor Cyan
Write-Host " git newbranch -h"
Write-Host " git step -h"
Write-Host ""