-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.ps1
242 lines (206 loc) · 8.22 KB
/
install.ps1
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# This script only works properly in Windows PowerShell (5.1)
if ($PSVersionTable.PSVersion.Major -ne 5)
{
PowerShell.exe -NoProfile -NoLogo -File ./install.ps1
exit
}
$WSL_ENV = "USERPROFILE/up:LOCALAPPDATA/up"
# Disable progress bars
$ProgressPreference = "SilentlyContinue"
function refresh-path {
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" +
[System.Environment]::GetEnvironmentVariable("Path", "User")
}
if (-Not (Get-Command "pwsh" -ErrorAction SilentlyContinue))
{
Write-Output "Installing PowerShell..."
winget install --id Microsoft.Powershell --source winget
}
& {
# Install PowerShell Profile
Write-Output "Configuring Microsoft PowerShell profile..."
$source = Join-Path "PowerShell" "Microsoft.PowerShell_profile.ps1"
$documents = Join-Path $Env:USERPROFILE "Documents"
$dest = Join-Path $documents "WindowsPowerShell"
$null = New-Item -Path $dest -Name "Microsoft.PowerShell_profile.ps1" -ItemType SymbolicLink -Value $source -Force
$dest = Join-Path $documents "PowerShell"
$null = New-Item -Path $dest -Name "Microsoft.PowerShell_profile.ps1" -ItemType SymbolicLink -Value $source -Force
}
if (-Not (Get-Command "oh-my-posh" -ErrorAction SilentlyContinue))
{
# Install Oh-My-Posh
Write-Output "Installing Oh-My-Posh..."
winget install JanDeDobbeleer.OhMyPosh -s winget
}
& {
# Install Oh-My-Posh Theme
Write-Output "Configuring Oh-My-Posh theme..."
$source = Join-Path "Oh-My-Posh" "custom.omp.json"
$null = New-Item -Path $Env:POSH_THEMES_PATH -Name "custom.omp.json" -ItemType SymbolicLink -Value $source -Force
}
if (-Not (Get-Command "rg" -ErrorAction SilentlyContinue))
{
# Install ripgrep
Write-Output "Installing ripgrep"
winget install BurntSushi.ripgrep.MSVC
}
& {
# Configure WSL
Write-Output "Configuring WSL..."
[Environment]::SetEnvironmentVariable("WSLENV", $WSL_ENV, [EnvironmentVariableTarget]::User)
$source = Join-Path "WSL" ".wslconfig"
$null = New-Item -Path $Env:USERPROFILE -Name ".wslconfig" -ItemType SymbolicLink -Value $source -Force
}
# Test if Git is not installed
if (-Not (Get-Command "git" -ErrorAction SilentlyContinue))
{
Write-Output "Installing Git..."
winget install Git.Git
}
& {
# Install .gitconfig
Write-Output "Configuring Git..."
$source = Join-Path "Git" ".gitconfig"
$null = New-Item -Path $HOME -Name ".gitconfig" -ItemType SymbolicLink -Value $source -Force
# Prompt user to initialize default git account details
$userConfig = Join-Path $Env:USERPROFILE ".gitconfig-user"
if (-Not (Test-Path -Path $userConfig))
{
Write-Host "This machine does not have a default git user, please enter the desired account details."
$username = Read-Host -Prompt "Default username"
$email = Read-Host -Prompt "Default email address"
$null = New-Item -Path $Env:USERPROFILE -Name ".gitconfig-user"
Set-Content $userConfig @"
[user]
name = $username
email = $email
"@
}
}
# Check if delta is not installed
if (-Not (Get-Command "delta" -ErrorAction SilentlyContinue))
{
# Install Delta
Write-Output "Installing Delta..."
winget install dandavison.delta
}
# Check if win32yank is not installed
if (-Not (Get-Command "win32yank" -ErrorAction SilentlyContinue))
{
# Install win32yank
Write-Output "Installing win32yank..."
winget install equalsraf.win32yank
}
# Check if Eza is not installed
if (-Not (Get-Command "eza" -ErrorAction SilentlyContinue))
{
# Install Eza
Write-Output "Installing Eza"
winget install eza-community.eza
}
# Check if zoxide is not installed
if (-Not (Get-Command "zoxide" -ErrorAction SilentlyContinue))
{
# Install zoxide
Write-Output "Installing zoxide"
winget install ajeetdsouza.zoxide
}
# Check if fzf is not installed
if (-Not (Get-Command "fzf" -ErrorAction SilentlyContinue))
{
# Install fzf
Write-Output "Installing fzf"
winget install fzf
}
# Check if bat is not installed
if (-Not (Get-Command "bat" -ErrorAction SilentlyContinue))
{
# Install bat
Write-Output "Installing bat..."
winget install sharkdp.bat
refresh-path
}
& {
$batThemes = [IO.Path]::Combine($Env:APPDATA, "bat", "themes")
$batCatppuccin = Join-Path $batThemes "Catppuccin-mocha.tmTheme"
# Check if catppuccin theme for bat is not installed
if (-Not (Test-Path -PathType Leaf -Path $batCatppuccin))
{
# Configure catppuccin theme for bat
Write-Output "Configuring bat..."
$null = New-Item -ItemType Directory -Force -Path $batThemes
$null = Invoke-WebRequest -Uri "https://raw.githubusercontent.com/catppuccin/bat/main/themes/Catppuccin%20Mocha.tmTheme" -OutFile $batCatppuccin
bat cache --build
}
}
# Check if PowerToys is not installed
# TODO: Suppress output of this command
$process = Start-Process "winget" -ArgumentList "list --id Microsoft.PowerToys" -NoNewWindow -Wait -PassThru
if ($process.ExitCode -ne 0)
{
# Install PowerToys
Write-Output "Installing Microsoft PowerToys..."
winget install Microsoft.PowerToys
}
# Configure Windows Terminal
& {
# Patch the root config
$target = [IO.Path]::Combine($Env:LOCALAPPDATA, "Packages", "Microsoft.WindowsTerminal_8wekyb3d8bbwe", "LocalState", "settings.json")
$patch = Join-Path "WindowsTerminal" "settings.patch.json"
pwsh.exe -NoProfile -NoLogo -Command "./scripts/patch-json.ps1 -Patch $patch -Target $target"
}
& {
# Create symlinks for PowerToys
Write-Output "Configuring Microsoft Powertoys..."
$source = [IO.Path]::Combine("PowerToys", "KeyboardManager", "default.json")
$destination = [IO.Path]::Combine($Env:LOCALAPPDATA, "Microsoft", "PowerToys", "Keyboard Manager")
$null = New-Item -Path $destination -Name "default.json" -ItemType SymbolicLink -Value $source -Force
$source = [IO.Path]::Combine("PowerToys", "FancyZones", "custom-layouts.json")
$destination = [IO.Path]::Combine($Env:LOCALAPPDATA, "Microsoft", "PowerToys", "FancyZones")
$null = New-Item -Path $destination -Name "custom-layouts.json" -ItemType SymbolicLink -Value $source -Force
}
& {
# Create symlink for Neovim
Write-Output "Configuring Neovim..."
$null = New-Item -Path $Env:LOCALAPPDATA -Name "nvim" -ItemType SymbolicLink -Value "Neovim" -Force
}
& {
# Install global .editorconfig
Write-Output "Configuring global .editorconfig..."
$null = New-Item -Path $Env:USERPROFILE -Name ".editorconfig" -ItemType SymbolicLink -Value ".editorconfig" -Force
}
function Get-Fonts {
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
(New-Object System.Drawing.Text.InstalledFontCollection).Families
}
# Check if the JetBrainsMono font not is installed
if (-Not ((Get-Fonts) -contains "JetBrainsMonoNL NFM"))
{
# Create temp directory
$tempDirectory = "temp"
$null = New-Item -ItemType Directory -Force -Path $tempDirectory
# Download
Write-Output "Downloading JetBrainsMono font..."
Invoke-WebRequest -Uri "https://github.com/ryanoasis/nerd-fonts/releases/latest/download/JetBrainsMono.zip" -OutFile "./temp/JetBrainsMono.zip"
# Extract
Write-Output "Installing JetBrainsMono font..."
Expand-Archive -Path "./temp/JetBrainsMono.zip" -DestinationPath "./temp/JetBrainsMono" -Force
$fontsDirectory = Join-Path "temp" "JetBrainsMono"
$userFontsDirectory = [IO.Path]::Combine($Env:LOCALAPPDATA, "Microsoft", "Windows", "Fonts")
$fontFilter = "^JetBrainsMonoNLNerdFontMono-[A-Za-z]+.ttf$"
$fonts = Get-ChildItem -Path $fontsDirectory -Name | Where-Object { $_ -match $fontFilter }
foreach ($font in $fonts)
{
# Copy file to user fonts directory
$destination = Join-Path $userFontsDirectory $font
$font = Get-Item -Path "./temp/JetBrainsMono/$font"
$null = Copy-Item $font.FullName -Destination $destination -Force
# Create registry key
$fontName = "$($font.BaseName) (True Type)"
$registryKey = "HKCU:\Software\Microsoft\Windows NT\CurrentVersion\Fonts"
$null = New-ItemProperty -Name $fontName -Path $registryKey -PropertyType string -Value $destination -Force
}
# Remove temp directory
Remove-Item $tempDirectory -Recurse -Force
}
Write-Output "Done."