-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
195 lines (162 loc) · 6.99 KB
/
install.ps1
File metadata and controls
195 lines (162 loc) · 6.99 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
195
# Dotfiles installation script for Windows
# Installs development tools via winget and sets up configurations
#Requires -Version 5.1
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$DotfilesDir = $PSScriptRoot
Write-Host "Installing dotfiles from $DotfilesDir" -ForegroundColor Cyan
Write-Host ""
# =============================================================================
# Winget Check
# =============================================================================
function Test-Winget {
try {
$null = Get-Command winget -ErrorAction Stop
return $true
}
catch {
return $false
}
}
if (-not (Test-Winget)) {
Write-Host "Error: winget is not installed." -ForegroundColor Red
Write-Host ""
Write-Host "Winget comes pre-installed on Windows 11 and recent Windows 10 versions."
Write-Host "If missing, install it from the Microsoft Store (App Installer) or from:"
Write-Host "https://github.com/microsoft/winget-cli/releases"
exit 1
}
Write-Host "Winget is available" -ForegroundColor Green
Write-Host ""
# =============================================================================
# Package Installation via Winget
# =============================================================================
Write-Host "Installing packages from winget.json..." -ForegroundColor Cyan
$WingetJson = Join-Path $DotfilesDir "packages\winget.json"
if (Test-Path $WingetJson) {
# Import packages from JSON file
winget import --import-file $WingetJson --accept-package-agreements --accept-source-agreements
if ($LASTEXITCODE -ne 0) {
Write-Host "Warning: Some packages may have failed to install" -ForegroundColor Yellow
}
}
else {
Write-Host "Warning: winget.json not found at $WingetJson" -ForegroundColor Yellow
}
Write-Host ""
# =============================================================================
# Refresh PATH
# =============================================================================
# Refresh PATH to pick up newly installed tools
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
# =============================================================================
# NPM Global Packages
# =============================================================================
Write-Host "Installing npm global packages..." -ForegroundColor Cyan
try {
$null = Get-Command npm -ErrorAction Stop
npm install -g @openai/codex opencode-ai @github/copilot
}
catch {
Write-Host "Warning: npm not found. Some tools will need to be installed manually after Node.js is available in PATH." -ForegroundColor Yellow
Write-Host "Run: npm install -g @openai/codex opencode-ai @github/copilot" -ForegroundColor Yellow
}
Write-Host ""
# =============================================================================
# Configuration Setup
# =============================================================================
Write-Host "Setting up configurations..." -ForegroundColor Cyan
# Helper function to create symlink or copy (symlinks require admin on Windows)
function Set-ConfigLink {
param(
[string]$Source,
[string]$Destination,
[switch]$IsDirectory
)
# Create parent directory if needed
$ParentDir = Split-Path $Destination -Parent
if (-not (Test-Path $ParentDir)) {
New-Item -ItemType Directory -Path $ParentDir -Force | Out-Null
}
# Backup existing file/directory if it's not a symlink
if (Test-Path $Destination) {
$item = Get-Item $Destination -Force
if ($item.Attributes -band [IO.FileAttributes]::ReparsePoint) {
# It's a symlink, remove it
Remove-Item $Destination -Force -Recurse
}
else {
# It's a real file/directory, backup it
$BackupPath = "$Destination.backup"
Write-Host " Backing up $Destination to $BackupPath"
Move-Item $Destination $BackupPath -Force
}
}
# Try to create symlink (requires admin or developer mode)
try {
if ($IsDirectory) {
New-Item -ItemType SymbolicLink -Path $Destination -Target $Source -Force | Out-Null
}
else {
New-Item -ItemType SymbolicLink -Path $Destination -Target $Source -Force | Out-Null
}
Write-Host " Linked: $Source -> $Destination" -ForegroundColor Green
}
catch {
# Fall back to copying
Write-Host " Symlink failed (admin required), copying instead..." -ForegroundColor Yellow
if ($IsDirectory) {
Copy-Item $Source $Destination -Recurse -Force
}
else {
Copy-Item $Source $Destination -Force
}
Write-Host " Copied: $Source -> $Destination" -ForegroundColor Yellow
}
}
# Neovim config: $env:LOCALAPPDATA\nvim
$NvimSource = Join-Path $DotfilesDir "nvim"
$NvimDest = Join-Path $env:LOCALAPPDATA "nvim"
Set-ConfigLink -Source $NvimSource -Destination $NvimDest -IsDirectory
# Git
$GitConfigSource = Join-Path $DotfilesDir "git\.gitconfig"
$GitConfigDest = Join-Path $HOME ".gitconfig"
Set-ConfigLink -Source $GitConfigSource -Destination $GitConfigDest
$GitIgnoreSource = Join-Path $DotfilesDir "git\.gitignore"
$GitIgnoreDest = Join-Path $HOME ".gitignore"
Set-ConfigLink -Source $GitIgnoreSource -Destination $GitIgnoreDest
# OpenCode
$OpenCodeConfigDir = Join-Path $env:APPDATA "opencode"
if (-not (Test-Path $OpenCodeConfigDir)) {
New-Item -ItemType Directory -Path $OpenCodeConfigDir -Force | Out-Null
}
$OpenCodeSource = Join-Path $DotfilesDir "opencode\opencode.json"
$OpenCodeDest = Join-Path $OpenCodeConfigDir "opencode.json"
Set-ConfigLink -Source $OpenCodeSource -Destination $OpenCodeDest
# Claude Code settings
$ClaudeDir = Join-Path $HOME ".claude"
if (-not (Test-Path $ClaudeDir)) {
New-Item -ItemType Directory -Path $ClaudeDir -Force | Out-Null
}
$ClaudeMdSource = Join-Path $DotfilesDir "claude\CLAUDE.md"
$ClaudeMdDest = Join-Path $ClaudeDir "CLAUDE.md"
Set-ConfigLink -Source $ClaudeMdSource -Destination $ClaudeMdDest
$ClaudeSettingsSource = Join-Path $DotfilesDir "claude\settings.json"
$ClaudeSettingsDest = Join-Path $ClaudeDir "settings.json"
Set-ConfigLink -Source $ClaudeSettingsSource -Destination $ClaudeSettingsDest
Write-Host ""
Write-Host "=============================================" -ForegroundColor Cyan
Write-Host "Installation complete!" -ForegroundColor Green
Write-Host "=============================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "Next steps:"
Write-Host " 1. Restart your terminal to pick up new PATH entries"
Write-Host " 2. Open Neovim to let plugins install automatically"
Write-Host ""
Write-Host "Notes:"
Write-Host " - Tmux is not available on Windows (use Windows Terminal tabs instead)"
Write-Host " - Bash configs are not linked (use PowerShell profile instead)"
Write-Host " - If symlinks failed, configs were copied instead of linked"
Write-Host ""
Write-Host "Secrets (SSH keys, API keys) must be set up manually."
Write-Host ""