main
md 95 lines 3.52 KB
Rendered Raw
1 ---
2 name: github-multi-account
3 description: Detect and set up account-locked gh aliases for multi-account GitHub. The AI reads this skill, detects accounts, asks the user which is personal/work, and runs the setup automatically.
4 confidence: high
5 source: https://github.com/tamirdresher/squad-skills/tree/main/plugins/github-multi-account
6 author: tamirdresher
7 ---
8
9 # GitHub Multi-Account — AI-Driven Setup
10
11 ## When to Activate
12 When the user has multiple GitHub accounts (check with `gh auth status`). If you see 2+ accounts listed, this skill applies.
13
14 ## What to Do (as the AI agent)
15
16 ### Step 1: Detect accounts
17 Run: `gh auth status`
18 Look for multiple accounts. Note which usernames are listed.
19
20 ### Step 2: Ask the user
21 Ask: "I see you have multiple GitHub accounts: {list them}. Which one is your personal account and which is your work/EMU account?"
22
23 ### Step 3: Run the setup automatically
24 Once the user confirms, do ALL of this for them:
25
26 ```powershell
27 # 1. Define the functions
28 $personal = "THEIR_PERSONAL_USERNAME"
29 $work = "THEIR_WORK_USERNAME"
30
31 # 2. Add to PowerShell profile
32 $profilePath = $PROFILE.CurrentUserAllHosts
33 if (!(Test-Path $profilePath)) { New-Item -Path $profilePath -Force | Out-Null }
34 $existing = Get-Content $profilePath -Raw -ErrorAction SilentlyContinue
35 if ($existing -notmatch "gh-personal") {
36 $block = @"
37
38 # === GitHub Multi-Account Aliases ===
39 function gh-personal { gh auth switch --user $personal 2>`$null | Out-Null; gh @args }
40 function gh-work { gh auth switch --user $work 2>`$null | Out-Null; gh @args }
41 Set-Alias ghp gh-personal
42 Set-Alias ghw gh-work
43 "@
44 Add-Content -Path $profilePath -Value $block
45 }
46
47 # 3. Create CMD wrappers
48 $binDir = Join-Path $env:USERPROFILE ".squad\bin"
49 if (!(Test-Path $binDir)) { New-Item -ItemType Directory -Path $binDir -Force | Out-Null }
50 "@echo off`ngh auth switch --user $personal >nul 2>&1`ngh %*" | Out-File "$binDir\ghp.cmd" -Encoding ascii
51 "@echo off`ngh auth switch --user $work >nul 2>&1`ngh %*" | Out-File "$binDir\ghw.cmd" -Encoding ascii
52
53 # 4. Add to PATH
54 $userPath = [Environment]::GetEnvironmentVariable("PATH", "User")
55 if ($userPath -notmatch [regex]::Escape($binDir)) {
56 [Environment]::SetEnvironmentVariable("PATH", "$binDir;$userPath", "User")
57 $env:PATH = "$binDir;$env:PATH"
58 }
59
60 # 5. Load in current session
61 function gh-personal { gh auth switch --user $personal 2>$null | Out-Null; gh @args }
62 function gh-work { gh auth switch --user $work 2>$null | Out-Null; gh @args }
63 Set-Alias ghp gh-personal
64 Set-Alias ghw gh-work
65 ```
66
67 ### Step 4: Verify for the user
68 Run these and show the results:
69 ```powershell
70 ghp api user --jq '.login' # should show personal username
71 ghw api user --jq '.login' # should show work username
72 ```
73
74 ### Step 5: Tell the user
75 "All set! From now on use `ghp` for personal repos and `ghw` for work repos. I'll use them too."
76
77 ## After Setup — Usage Rules
78
79 1. **NEVER** use bare `gh` for repo operations — always `ghp` or `ghw`
80 2. **NEVER** manually `gh auth switch` — the aliases handle it
81 3. Determine alias by repo owner:
82 - Personal account repos → `ghp` / `gh-personal`
83 - Work/EMU account repos → `ghw` / `gh-work`
84
85 ## Repo-Specific Account Binding
86
87 This repo (`bradygaster/squad`) is bound to the **bradygaster** (personal) account.
88 All `gh` operations in this repo MUST use `ghp` / `gh-personal`.
89
90 ## For Squad Agents
91 At the TOP of any script touching GitHub, define:
92 ```powershell
93 function gh-personal { gh auth switch --user bradygaster 2>$null | Out-Null; gh @args }
94 function gh-work { gh auth switch --user bradyg_microsoft 2>$null | Out-Null; gh @args }
95 ```