mirror of
https://github.com/Baipyrus/dotfiles.git
synced 2024-12-25 10:51:46 +00:00
Compare commits
53 Commits
f9db026b16
...
06977c0db5
Author | SHA1 | Date | |
---|---|---|---|
06977c0db5 | |||
c15f2c800c | |||
406367b2eb | |||
7c86d72ece | |||
878db9489b | |||
1ed1bb7ef6 | |||
f952f8c891 | |||
0c3bd50246 | |||
1846230e91 | |||
4ab07fb4db | |||
0e50978a74 | |||
10d520c12a | |||
56d0f1e209 | |||
05de50080a | |||
d79c3bf43f | |||
e1029ae1cd | |||
3e07cfaa12 | |||
b5a56cd60e | |||
8995565e26 | |||
97fcc961a7 | |||
94028eff12 | |||
8a4fed4295 | |||
fa7d942a8f | |||
107b83ced4 | |||
80a34d44c3 | |||
7e8bc5fa19 | |||
7aa94ca8e2 | |||
0da955a90d | |||
cf885e7363 | |||
72061fd686 | |||
1d33d6ed32 | |||
4ce997d016 | |||
24b6d1f115 | |||
52e9367b04 | |||
8ed8d2d411 | |||
eaf1e8e9f3 | |||
8c6dcd4590 | |||
ff07ff7d17 | |||
7f7fc0a8ba | |||
c5c7703e00 | |||
df70d04ddc | |||
eed5118341 | |||
5014da3a46 | |||
509ebf7437 | |||
cb66813a8b | |||
9cc28a14e1 | |||
1e19a5e1cf | |||
e2edd0122e | |||
ec067674d3 | |||
d95ba9823d | |||
3a849a448f | |||
5090a04e95 | |||
ad9ffc0a19 |
34
README.md
34
README.md
@ -33,31 +33,8 @@ These tools include the following for Windows Installs (Recommended using [Choco
|
|||||||
- [Python](https://www.python.org/)
|
- [Python](https://www.python.org/)
|
||||||
- [Composer](https://getcomposer.org/)
|
- [Composer](https://getcomposer.org/)
|
||||||
|
|
||||||
<details><summary>Windows Subsystem for Linux</summary>
|
> **NOTE**
|
||||||
|
> For more information, simply see all [util/](./util) installation modules.
|
||||||
```bash
|
|
||||||
sudo apt update
|
|
||||||
curl -fsSL https://deb.nodesource.com/setup_lts.x -o nodesource_setup.sh
|
|
||||||
sudo -E bash nodesource_setup.sh
|
|
||||||
sudo add-apt-repository ppa:neovim-ppa/unstable -y
|
|
||||||
sudo apt install make gcc ripgrep unzip git xclip neovim nodejs python3-venv
|
|
||||||
curl https://sh.rustup.rs -sSf | sh
|
|
||||||
curl -LO https://go.dev/dl/go1.23.2.linux-amd64.tar.gz
|
|
||||||
sudo rm -rf /usr/local/go
|
|
||||||
sudo tar -C /usr/local -xzf go1.23.2.linux-amd64.tar.gz
|
|
||||||
export PATH=$PATH:/usr/local/go/bin
|
|
||||||
```
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
<details><summary>Winget and Chocolatey</summary>
|
|
||||||
|
|
||||||
```pwsh
|
|
||||||
winget install chocolatey.chocolatey Neovide.Neovide Alacritty.Alacritty Git.Git GoLang.Go Microsoft.DotNet.SDK.8 OpenJS.NodeJS.LTS Python.Python.3.12 Rustlang.Rustup
|
|
||||||
choco install neovim ripgrep curl wget fd unzip gzip mingw make
|
|
||||||
```
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
@ -73,6 +50,9 @@ Alternatively, feel free to run the [install script](./install_windows.ps1) afte
|
|||||||
cloning the repository or directly execute it from shell:
|
cloning the repository or directly execute it from shell:
|
||||||
|
|
||||||
```pwsh
|
```pwsh
|
||||||
# Using 'Invoke-RestMethod' and 'Invoke-Expression'
|
irm https://api.github.com/repos/Baipyrus/dotfiles/zipball -O "$env:TMP\dotfiles.zip"
|
||||||
irm 'https://raw.githubusercontent.com/Baipyrus/dotfiles/main/install_windows.ps1' | iex
|
Expand-Archive "$env:TMP\dotfiles.zip" -D "$env:TMP\dotfiles" -F
|
||||||
|
gci "$env:TMP\dotfiles\**\install_windows.ps1" | select -F 1 | % {
|
||||||
|
saps powershell.exe -Wait -Wo $_.DirectoryName -A "-Ex", "Bypass", "-F", $_.FullName
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
@ -1,154 +1,30 @@
|
|||||||
|
Import-Module ./util/chocolatey.psm1
|
||||||
|
Import-Module ./util/windows.psm1
|
||||||
|
Import-Module ./util/winget.psm1
|
||||||
|
Import-Module ./util/wsl.psm1
|
||||||
|
|
||||||
|
|
||||||
|
# (Optionally) Install required Software
|
||||||
|
WingetInstall
|
||||||
|
ChocolateyInstall
|
||||||
|
WSLInstall
|
||||||
|
|
||||||
|
Write-Host "Installation Steps complete!" -ForegroundColor Cyan
|
||||||
|
$continue = Read-Host "Continue with configuration? [Y/n]"
|
||||||
|
if ($continue.ToLower() -eq 'n')
|
||||||
|
{ return
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# Define paths for tools and configurations
|
# Define paths for tools and configurations
|
||||||
$dotfilesRepo = "$env:TMP\dotfiles"
|
$dotfilesRepo = (Get-Location).Path
|
||||||
$alacrittyConfigDir = "$env:APPDATA\alacritty"
|
$alacrittyConfigDir = "$env:APPDATA\alacritty"
|
||||||
$psProfile = "$env:USERPROFILE\Documents\PowerShell\Microsoft.PowerShell_profile.ps1"
|
$psProfile = "$env:USERPROFILE\Documents\PowerShell\Microsoft.PowerShell_profile.ps1"
|
||||||
$repoUrl = "https://github.com/Baipyrus/dotfiles.git"
|
|
||||||
|
|
||||||
# Function to determine if the current directory is the dotfiles repository
|
|
||||||
function IsGitRepository
|
|
||||||
{
|
|
||||||
param (
|
|
||||||
[string]$dir,
|
|
||||||
[string]$url
|
|
||||||
)
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
$isRepo = git -C $dir rev-parse --is-inside-work-tree 2>$null
|
|
||||||
$originUrl = git -C $dir remote get-url origin 2>$null
|
|
||||||
return $isRepo -eq 'true' -and $originUrl -eq $url
|
|
||||||
} catch
|
|
||||||
{
|
|
||||||
return $false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# Check if the script is running inside the dotfiles repository
|
|
||||||
$currentDir = (Get-Location).Path
|
|
||||||
|
|
||||||
if (IsGitRepository -dir $currentDir -url $repoUrl)
|
|
||||||
{
|
|
||||||
Write-Host "Already inside the dotfiles repository. Skipping clone step and pulling..." -ForegroundColor Yellow
|
|
||||||
$dotfilesRepo = $currentDir
|
|
||||||
git pull
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
# Clone dotfiles repository to TMP if not already inside it
|
|
||||||
if (-not (Test-Path $dotfilesRepo))
|
|
||||||
{
|
|
||||||
Write-Host "Cloning dotfiles repository..." -ForegroundColor Cyan
|
|
||||||
git clone $repoUrl $dotfilesRepo
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
Write-Host "Pulling latest changes from dotfiles repository..." -ForegroundColor Cyan
|
|
||||||
git -C $dotfilesRepo pull
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# Function to copy files with overwrite prompt
|
|
||||||
function CopyFileWithPrompt
|
|
||||||
{
|
|
||||||
param (
|
|
||||||
[string]$source,
|
|
||||||
[string]$destination
|
|
||||||
)
|
|
||||||
|
|
||||||
if (Test-Path $destination)
|
|
||||||
{
|
|
||||||
$overwrite = Read-Host "File $destination exists. Overwrite? (y/n)"
|
|
||||||
if ($overwrite -ne 'y')
|
|
||||||
{
|
|
||||||
Write-Host "Skipping $destination" -ForegroundColor Yellow
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Copy-Item -Path $source -Destination $destination -Force
|
|
||||||
}
|
|
||||||
|
|
||||||
# Function to handle URL files: download files or clone repositories
|
|
||||||
function ProcessUrlFiles
|
|
||||||
{
|
|
||||||
param (
|
|
||||||
[string]$sourceDir,
|
|
||||||
[Parameter(Mandatory=$false)][string]$destinationDir,
|
|
||||||
[Parameter(Mandatory=$false)][string]$fileExt
|
|
||||||
)
|
|
||||||
|
|
||||||
# Ensure the destination directory exists
|
|
||||||
if ($destinationDir -and (-not (Test-Path $destinationDir)))
|
|
||||||
{
|
|
||||||
Write-Host "Creating destination directory $destinationDir..." -ForegroundColor Cyan
|
|
||||||
New-Item -ItemType Directory -Path $destinationDir | Out-Null
|
|
||||||
}
|
|
||||||
|
|
||||||
# Create temporary directory for curl
|
|
||||||
$appname = $sourceDir.Split('\')[-1]
|
|
||||||
$tmpApp = "$env:TMP\$appname-config"
|
|
||||||
if (-not (Test-Path $tmpApp))
|
|
||||||
{ New-Item -ItemType Directory -Path $tmpApp | Out-Null
|
|
||||||
}
|
|
||||||
Set-Location $tmpApp
|
|
||||||
|
|
||||||
# Find all .url files in the source directory
|
|
||||||
$urlFiles = Get-ChildItem -Path $sourceDir -Filter '*.url'
|
|
||||||
|
|
||||||
foreach ($file in $urlFiles)
|
|
||||||
{
|
|
||||||
$url = Get-Content $file.FullName
|
|
||||||
$fileName = [System.IO.Path]::GetFileNameWithoutExtension($file.Name)
|
|
||||||
$destinationPath = "$destinationDir\$fileName"
|
|
||||||
|
|
||||||
if (-not ($url -match 'git@|https://.*\.git'))
|
|
||||||
{
|
|
||||||
# Otherwise, download the file
|
|
||||||
$extension = [System.IO.Path]::GetExtension($url)
|
|
||||||
# Force apply $fileExt if given
|
|
||||||
if ($fileExt)
|
|
||||||
{
|
|
||||||
$extension = $fileExt
|
|
||||||
$url += $fileExt
|
|
||||||
}
|
|
||||||
$destinationPath = "$destinationDir\$fileName$extension"
|
|
||||||
|
|
||||||
# Respond only if destination is provided
|
|
||||||
$conditional = " to $destinationPath"
|
|
||||||
if (-not $destinationDir)
|
|
||||||
{ $conditional = ''
|
|
||||||
}
|
|
||||||
|
|
||||||
Write-Host "Downloading $fileName from $url$conditional..." -ForegroundColor Cyan
|
|
||||||
Invoke-RestMethod $url -OutFile $fileName$extension
|
|
||||||
$tmpDestination = "$tmpApp\$fileName$extension"
|
|
||||||
|
|
||||||
# Copy only if destination is provided
|
|
||||||
if ($destinationDir)
|
|
||||||
{ CopyFileWithPrompt $tmpDestination $destinationPath
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
# Use $tmpApp as destination in case of git repo
|
|
||||||
if (-not $destinationDir)
|
|
||||||
{ $destinationPath = "$tmpApp\$fileName"
|
|
||||||
}
|
|
||||||
|
|
||||||
# If the URL is a git repository, pull it
|
|
||||||
if (IsGitRepository -dir $destinationPath -url $url)
|
|
||||||
{
|
|
||||||
Write-Host "Pulling inside existing repository $fileName..." -ForegroundColor Cyan
|
|
||||||
git -C $destinationPath pull
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
# Or otherwise clone it
|
|
||||||
Write-Host "Cloning $fileName from $url to $destinationPath..." -ForegroundColor Cyan
|
|
||||||
git clone $url $destinationPath
|
|
||||||
}
|
|
||||||
Set-Location -
|
|
||||||
}
|
|
||||||
|
|
||||||
# Setting up Alacritty Configuration
|
# Setting up Alacritty Configuration
|
||||||
Write-Host "Setting up Alacritty configuration..." -ForegroundColor Cyan
|
Write-Host "Setting up Alacritty configuration..." -ForegroundColor Cyan
|
||||||
ProcessUrlFiles -sourceDir "$dotfilesRepo\alacritty" -destinationDir $alacrittyConfigDir
|
ProcessUrlFiles -source "$dotfilesRepo\alacritty" -destination $alacrittyConfigDir
|
||||||
|
|
||||||
# Copy the main Alacritty configuration file
|
# Copy the main Alacritty configuration file
|
||||||
CopyFileWithPrompt "$dotfilesRepo\alacritty\alacritty.toml" "$alacrittyConfigDir\alacritty.toml"
|
CopyFileWithPrompt "$dotfilesRepo\alacritty\alacritty.toml" "$alacrittyConfigDir\alacritty.toml"
|
||||||
@ -157,19 +33,19 @@ CopyFileWithPrompt "$dotfilesRepo\alacritty\alacritty.toml" "$alacrittyConfigDir
|
|||||||
Write-Host "Setting up Neovim configuration..." -ForegroundColor Cyan
|
Write-Host "Setting up Neovim configuration..." -ForegroundColor Cyan
|
||||||
$ubuntu = wsl.exe -l --all | Where-Object { $_.Replace("`0", "") -match '^Ubuntu' }
|
$ubuntu = wsl.exe -l --all | Where-Object { $_.Replace("`0", "") -match '^Ubuntu' }
|
||||||
if ($null -eq $ubuntu)
|
if ($null -eq $ubuntu)
|
||||||
{ ProcessUrlFiles -sourceDir "$dotfilesRepo\nvim" -destinationDir "$env:LOCALAPPDATA"
|
{ ProcessUrlFiles -source "$dotfilesRepo\nvim" -destination "$env:LOCALAPPDATA"
|
||||||
} else
|
} else
|
||||||
{
|
{ InstallWSLNeovim -source "$dotfilesRepo\nvim"
|
||||||
# TODO: Expand into generic WSL setup while installing required dev tools
|
|
||||||
ProcessUrlFiles -sourceDir "$dotfilesRepo\nvim"
|
|
||||||
Set-Location "$env:TMP\nvim-config"
|
|
||||||
Write-Host "Copying (forcably) configuration to WSL..." -ForegroundColor Yellow
|
|
||||||
wsl.exe cp -rf . ~/.config/ 2>$null | Out-Null
|
|
||||||
Set-Location -
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Setting up PowerShell Profile
|
# Setting up PowerShell Profile
|
||||||
Write-Host "Setting up PowerShell profile..." -ForegroundColor Cyan
|
Write-Host "Setting up PowerShell profile..." -ForegroundColor Cyan
|
||||||
|
# Create local PowerShell profile directory
|
||||||
|
$psDir = Split-Path -Path $psProfile
|
||||||
|
if (-not (Test-Path $psDir))
|
||||||
|
{ New-Item -ItemType Directory -Path $psDir | Out-Null
|
||||||
|
}
|
||||||
|
# Copy existing startup script to destination
|
||||||
CopyFileWithPrompt "$dotfilesRepo\PowerShell\Microsoft.PowerShell_profile.ps1" $psProfile
|
CopyFileWithPrompt "$dotfilesRepo\PowerShell\Microsoft.PowerShell_profile.ps1" $psProfile
|
||||||
|
|
||||||
# Setting up self-made ProxySwitcher
|
# Setting up self-made ProxySwitcher
|
||||||
@ -178,37 +54,11 @@ Write-Host "Setting up ProxySwitcher via subscript..." -ForegroundColor Cyan
|
|||||||
Invoke-RestMethod 'https://raw.githubusercontent.com/Baipyrus/ProxySwitcher/main/install.ps1' | Invoke-Expression
|
Invoke-RestMethod 'https://raw.githubusercontent.com/Baipyrus/ProxySwitcher/main/install.ps1' | Invoke-Expression
|
||||||
Write-Host "============================================" -ForegroundColor DarkGray
|
Write-Host "============================================" -ForegroundColor DarkGray
|
||||||
|
|
||||||
function UnzipAndInstall
|
|
||||||
{
|
|
||||||
param (
|
|
||||||
[string]$source
|
|
||||||
)
|
|
||||||
|
|
||||||
# Create temporary directory for unzip
|
|
||||||
$appname = $source.Split('\')[-1]
|
|
||||||
$tmpApp = "$env:TMP\$appname-config"
|
|
||||||
if (-not (Test-Path $tmpApp))
|
|
||||||
{ New-Item -ItemType Directory -Path $tmpApp | Out-Null
|
|
||||||
}
|
|
||||||
|
|
||||||
# Find all .url files in the source directory
|
|
||||||
$urlFiles = Get-ChildItem -Path $source -Filter '*.url'
|
|
||||||
|
|
||||||
foreach ($file in $urlFiles)
|
|
||||||
{
|
|
||||||
$fileName = [System.IO.Path]::GetFileNameWithoutExtension($file.Name)
|
|
||||||
Write-Host "Extracting archive $tmpApp\$fileName.zip to $tmpApp\$fileName\..." -ForegroundColor Cyan
|
|
||||||
unzip -o "$tmpApp\$fileName.zip" -d "$tmpApp\$fileName" | Out-Null
|
|
||||||
|
|
||||||
Write-Host "Installing fonts from $tmpApp\$fileName\ for current user..." -ForegroundColor Cyan
|
|
||||||
Copy-Item -Path "$tmpApp\$fileName\*" -Destination "$env:LOCALAPPDATA\Microsoft\Windows\Fonts\" -Force -ErrorAction SilentlyContinue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# Installing Nerd Fonts
|
# Installing Nerd Fonts
|
||||||
Write-Host "Installing Nerd Fonts..." -ForegroundColor Cyan
|
Write-Host "Installing Nerd Fonts..." -ForegroundColor Cyan
|
||||||
ProcessUrlFiles -sourceDir "$dotfilesRepo\nerd-fonts" -fileExt ".zip"
|
ProcessUrlFiles -source "$dotfilesRepo\nerd-fonts" -fileExt ".zip" -progress $false
|
||||||
UnzipAndInstall -source "$dotfilesRepo\nerd-fonts"
|
Get-ChildItem -Path "$env:TMP\nerd-fonts-config" -Filter "*.zip" | `
|
||||||
|
ForEach-Object { InstallNerdFont -source $_.FullName }
|
||||||
|
|
||||||
# Final message
|
# Final message
|
||||||
Write-Host "Windows setup complete!" -ForegroundColor Green
|
Write-Host "Windows setup complete!" -ForegroundColor Green
|
||||||
|
10
util/chocolatey.list
Normal file
10
util/chocolatey.list
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
neovim
|
||||||
|
ripgrep
|
||||||
|
wget
|
||||||
|
curl
|
||||||
|
fd
|
||||||
|
unzip
|
||||||
|
gzip
|
||||||
|
mingw
|
||||||
|
make
|
||||||
|
composer
|
17
util/chocolatey.psm1
Normal file
17
util/chocolatey.psm1
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
function InstallPackages
|
||||||
|
{
|
||||||
|
choco.exe install (Get-Content ./util/chocolatey.list)
|
||||||
|
}
|
||||||
|
|
||||||
|
function ChocolateyInstall
|
||||||
|
{
|
||||||
|
$install = Read-Host "Install Chocolatey Packages now? [Y/n]"
|
||||||
|
if ($install.ToLower() -eq 'n')
|
||||||
|
{ return
|
||||||
|
}
|
||||||
|
|
||||||
|
# Start admin process, import this script, run 'InstallPackages' function
|
||||||
|
Start-Process powershell.exe -Verb RunAs -Wait `
|
||||||
|
-ArgumentList "-ExecutionPolicy", "Bypass", `
|
||||||
|
"-C", "cd $pwd; ipmo ./util/chocolatey.psm1; InstallPackages"
|
||||||
|
}
|
216
util/windows.psm1
Normal file
216
util/windows.psm1
Normal file
@ -0,0 +1,216 @@
|
|||||||
|
# Function to determine if the current directory is the dotfiles repository
|
||||||
|
function IsGitRepository
|
||||||
|
{
|
||||||
|
param (
|
||||||
|
[string]$dir,
|
||||||
|
[string]$url
|
||||||
|
)
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$isRepo = git -C $dir rev-parse --is-inside-work-tree 2>$null
|
||||||
|
$originUrl = git -C $dir remote get-url origin 2>$null
|
||||||
|
return $isRepo -eq 'true' -and $originUrl -eq $url
|
||||||
|
} catch
|
||||||
|
{
|
||||||
|
return $false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to copy files with overwrite prompt
|
||||||
|
function CopyFileWithPrompt
|
||||||
|
{
|
||||||
|
param (
|
||||||
|
[string]$source,
|
||||||
|
[string]$destination
|
||||||
|
)
|
||||||
|
|
||||||
|
if (Test-Path $destination)
|
||||||
|
{
|
||||||
|
$overwrite = Read-Host "File $destination exists. Overwrite? (y/N)"
|
||||||
|
if ($overwrite.ToLower() -ne 'y')
|
||||||
|
{
|
||||||
|
Write-Host "Skipping $destination" -ForegroundColor Yellow
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Copy-Item -Path $source -Destination $destination -Force
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to handle URL files: download files or clone repositories
|
||||||
|
function ProcessUrlFiles
|
||||||
|
{
|
||||||
|
param (
|
||||||
|
[string]$source,
|
||||||
|
[Parameter(Mandatory=$false)][string]$destination,
|
||||||
|
[Parameter(Mandatory=$false)][string]$fileExt,
|
||||||
|
[bool]$progress=$true
|
||||||
|
)
|
||||||
|
|
||||||
|
# Disable progressbar for faster download
|
||||||
|
$progressPreference = 'continue'
|
||||||
|
if (-not $progress)
|
||||||
|
{ $progressPreference = 'silentlyContinue'
|
||||||
|
}
|
||||||
|
|
||||||
|
# Ensure the destination directory exists
|
||||||
|
if ($destination -and (-not (Test-Path $destination)))
|
||||||
|
{
|
||||||
|
Write-Host "Creating destination directory $destination..." -ForegroundColor Cyan
|
||||||
|
New-Item -ItemType Directory -Path $destination | Out-Null
|
||||||
|
}
|
||||||
|
|
||||||
|
# Create temporary directory for curl
|
||||||
|
$appname = Split-Path -Leaf $source
|
||||||
|
$tmpApp = "$env:TMP\$appname-config"
|
||||||
|
if (-not (Test-Path $tmpApp))
|
||||||
|
{ New-Item -ItemType Directory -Path $tmpApp | Out-Null
|
||||||
|
}
|
||||||
|
Push-Location
|
||||||
|
Set-Location $tmpApp
|
||||||
|
|
||||||
|
# Find all .url files in the source directory
|
||||||
|
$urlFiles = Get-ChildItem -Path $source -Filter '*.url'
|
||||||
|
|
||||||
|
foreach ($file in $urlFiles)
|
||||||
|
{
|
||||||
|
$url = Get-Content $file.FullName
|
||||||
|
$fileName = [System.IO.Path]::GetFileNameWithoutExtension($file.Name)
|
||||||
|
$destinationPath = "$destination\$fileName"
|
||||||
|
|
||||||
|
if (-not ($url -match 'git@|https://.*\.git'))
|
||||||
|
{
|
||||||
|
# Otherwise, download the file
|
||||||
|
$extension = [System.IO.Path]::GetExtension($url)
|
||||||
|
# Force apply $fileExt if given
|
||||||
|
if ($fileExt)
|
||||||
|
{
|
||||||
|
$extension = $fileExt
|
||||||
|
$url += $fileExt
|
||||||
|
}
|
||||||
|
$destinationPath = "$destination\$fileName$extension"
|
||||||
|
|
||||||
|
# Respond only if destination is provided
|
||||||
|
$conditional = " to $destinationPath"
|
||||||
|
if (-not $destination)
|
||||||
|
{ $conditional = ''
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "Downloading $fileName from $url$conditional..." -ForegroundColor Cyan
|
||||||
|
Invoke-WebRequest $url -OutFile $fileName$extension
|
||||||
|
$tmpDestination = "$tmpApp\$fileName$extension"
|
||||||
|
|
||||||
|
# Copy only if destination is provided
|
||||||
|
if ($destination)
|
||||||
|
{ CopyFileWithPrompt $tmpDestination $destinationPath
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
# Use $tmpApp as destination in case of git repo
|
||||||
|
if (-not $destination)
|
||||||
|
{ $destinationPath = "$tmpApp\$fileName"
|
||||||
|
}
|
||||||
|
|
||||||
|
# If the URL is a git repository, pull it
|
||||||
|
if (IsGitRepository -dir $destinationPath -url $url)
|
||||||
|
{
|
||||||
|
Write-Host "Pulling inside existing repository $fileName..." -ForegroundColor Cyan
|
||||||
|
git -C $destinationPath pull
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
# Or otherwise clone it
|
||||||
|
Write-Host "Cloning $fileName from $url to $destinationPath..." -ForegroundColor Cyan
|
||||||
|
git clone $url $destinationPath
|
||||||
|
}
|
||||||
|
Pop-Location
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to unzip and install nerd fonts
|
||||||
|
function InstallNerdFont
|
||||||
|
{
|
||||||
|
param (
|
||||||
|
[string]$source
|
||||||
|
)
|
||||||
|
|
||||||
|
$fileName = [System.IO.Path]::GetFileNameWithoutExtension($source)
|
||||||
|
$parent = Get-ChildItem $source | `
|
||||||
|
Select-Object -ExpandProperty Directory | `
|
||||||
|
Select-Object -ExpandProperty FullName
|
||||||
|
$destination = "$parent\$fileName"
|
||||||
|
|
||||||
|
# Create destination directory
|
||||||
|
if (-not (Test-Path $destination))
|
||||||
|
{ New-Item -ItemType Directory -Path $destination | Out-Null
|
||||||
|
}
|
||||||
|
|
||||||
|
# Extract contents of zip archive
|
||||||
|
Write-Host "Extracting archive $source to $destination..." -ForegroundColor Cyan
|
||||||
|
Expand-Archive $source -DestinationPath $destination -Force | Out-Null
|
||||||
|
|
||||||
|
# Install extracted fonts
|
||||||
|
$fontFiles = Get-ChildItem -Path $destination -Include "*.ttf", "*.otf"
|
||||||
|
|
||||||
|
foreach ($font in $fontFiles)
|
||||||
|
{
|
||||||
|
InstallFont $font
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Reference: https://www.alkanesolutions.co.uk/2021/12/06/installing-fonts-with-powershell/
|
||||||
|
function InstallFont
|
||||||
|
{
|
||||||
|
param
|
||||||
|
(
|
||||||
|
[System.IO.FileInfo]$file
|
||||||
|
)
|
||||||
|
|
||||||
|
# Prerequisites / Constants
|
||||||
|
Add-Type -AssemblyName PresentationCore
|
||||||
|
$destination = "$env:LOCALAPPDATA\Microsoft\Windows\Fonts\"
|
||||||
|
$regKey = "HKLM:\Software\Microsoft\Windows NT\CurrentVersion\Fonts"
|
||||||
|
|
||||||
|
# Create destination directory
|
||||||
|
if (-not (Test-Path $destination))
|
||||||
|
{ New-Item -ItemType Directory -Path $destination | Out-Null
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get Glyph
|
||||||
|
$glyph = New-Object -TypeName Windows.Media.GlyphTypeface -ArgumentList $file.FullName
|
||||||
|
|
||||||
|
$family = $glyph.Win32FamilyNames['en-us']
|
||||||
|
if ($null -eq $family)
|
||||||
|
{ $family = $glyph.Win32FamilyNames.Values | Select-Object -First 1
|
||||||
|
}
|
||||||
|
|
||||||
|
$face = $glyph.Win32FaceNames['en-us']
|
||||||
|
if ($null -eq $face)
|
||||||
|
{ $face = $glyph.Win32FaceNames.Values | Select-Object -First 1
|
||||||
|
}
|
||||||
|
|
||||||
|
$name = ("$family $face").Trim()
|
||||||
|
switch ($file.Extension)
|
||||||
|
{
|
||||||
|
".ttf"
|
||||||
|
{ $name = "$name (TrueType)"
|
||||||
|
}
|
||||||
|
".otf"
|
||||||
|
{ $name = "$name (OpenType)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$destFileName = Join-Path -Path $destination -ChildPath $file.Name
|
||||||
|
Write-Host "Installing font: $file with font name '$name'"
|
||||||
|
If (-not (Test-Path $destFileName))
|
||||||
|
{ Copy-Item -Path $file.FullName -Destination $destFileName -Force
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "Registering font: $file with font name '$name'"
|
||||||
|
$keyValue = Get-ItemProperty -Name $name -Path $regKey -ErrorAction SilentlyContinue
|
||||||
|
If (-not $keyValue)
|
||||||
|
{
|
||||||
|
New-ItemProperty -Name $name -Path $regKey `
|
||||||
|
-PropertyType string -Value $file.Name `
|
||||||
|
-Force -ErrorAction SilentlyContinue | Out-Null
|
||||||
|
}
|
||||||
|
}
|
11
util/winget.list
Normal file
11
util/winget.list
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
Git.Git
|
||||||
|
Microsoft.OpenJDK.21
|
||||||
|
Alacritty.Alacritty
|
||||||
|
OpenJS.NodeJS.LTS
|
||||||
|
Chocolatey.Chocolatey
|
||||||
|
Microsoft.DotNet.SDK.8
|
||||||
|
Microsoft.PowerShell
|
||||||
|
GoLang.Go
|
||||||
|
Python.Python.3.12
|
||||||
|
Rustlang.Rustup
|
||||||
|
rjpcomputing.luaforwindows
|
39
util/winget.psm1
Normal file
39
util/winget.psm1
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
function InstallWinget
|
||||||
|
{
|
||||||
|
$progressPreference = 'silentlyContinue'
|
||||||
|
$download = 'https://api.github.com/repos/microsoft/winget-cli/releases/latest'
|
||||||
|
$setup = "$env:TMP\winget_setup.msixbundle"
|
||||||
|
|
||||||
|
if (-not (Test-Path $setup))
|
||||||
|
{
|
||||||
|
$releases = Invoke-RestMethod $download
|
||||||
|
$assets = $releases | Select-Object -ExpandProperty "assets"
|
||||||
|
$installer = $assets | Where-Object "name" -Match "msixbundle"
|
||||||
|
$url = $installer | Select-Object -ExpandProperty "browser_download_url"
|
||||||
|
|
||||||
|
Write-Host "Downloading WinGet '.msixbundle' installer ..."
|
||||||
|
Invoke-WebRequest $url -OutFile $setup
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "Installing WinGet app package..."
|
||||||
|
Add-AppxPackage -Path $setup
|
||||||
|
}
|
||||||
|
|
||||||
|
function WingetInstall
|
||||||
|
{
|
||||||
|
$update = Read-Host "Install/Update WinGet now? [Y/n]"
|
||||||
|
if ($update.ToLower() -ne 'n')
|
||||||
|
{
|
||||||
|
# Start admin process, import this script, run 'InstallPackages' function
|
||||||
|
Start-Process powershell.exe -Verb RunAs -Wait `
|
||||||
|
-ArgumentList "-ExecutionPolicy", "Bypass", `
|
||||||
|
"-C", "cd $pwd; ipmo ./util/winget.psm1; InstallWinget"
|
||||||
|
}
|
||||||
|
|
||||||
|
$install = Read-Host "Install WinGet Packages now? [Y/n]"
|
||||||
|
if ($install.ToLower() -eq 'n')
|
||||||
|
{ return
|
||||||
|
}
|
||||||
|
|
||||||
|
winget.exe install -s winget --accept-source-agreements (Get-Content ./util/winget.list)
|
||||||
|
}
|
14
util/wsl.list
Normal file
14
util/wsl.list
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
make
|
||||||
|
gcc
|
||||||
|
ripgrep
|
||||||
|
unzip
|
||||||
|
git
|
||||||
|
xclip
|
||||||
|
python3
|
||||||
|
python3-venv
|
||||||
|
composer
|
||||||
|
luarocks
|
||||||
|
fd-find
|
||||||
|
python3-pip
|
||||||
|
python3-pynvim
|
||||||
|
openjdk-21-jdk-headless
|
61
util/wsl.psm1
Normal file
61
util/wsl.psm1
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
function InstallWSL
|
||||||
|
{
|
||||||
|
Write-Host "Enabling and downloading required Windows Features..."
|
||||||
|
Enable-WindowsOptionalFeature -Online -FeatureName "Microsoft-Windows-Subsystem-Linux" -All -NoRestart | Out-Null
|
||||||
|
Enable-WindowsOptionalFeature -Online -FeatureName "VirtualMachinePlatform" -All -NoRestart | Out-Null
|
||||||
|
Write-Host "Installing WSL2..."
|
||||||
|
wsl.exe --install --no-distribution
|
||||||
|
wsl.exe --set-default-version 2
|
||||||
|
}
|
||||||
|
|
||||||
|
function WSLInstall
|
||||||
|
{
|
||||||
|
# Skip if any WSL2 installations can be found
|
||||||
|
$installations = wsl.exe -l -v
|
||||||
|
$filtered = $installations | Where-Object { $_.Replace("`0", '') -match '^.{2}Ubuntu' }
|
||||||
|
$versions = $filtered | ForEach-Object { $_.Substring($_.LastIndexOf(' ') + 1) }
|
||||||
|
if ($null -ne $versions -and $versions.Contains('2'))
|
||||||
|
{ return
|
||||||
|
}
|
||||||
|
|
||||||
|
$update = Read-Host "Install/Update WSL2 now? [Y/n]"
|
||||||
|
if ($update.ToLower() -ne 'n')
|
||||||
|
{
|
||||||
|
# Start admin process, import this script, run 'InstallPackages' function
|
||||||
|
Start-Process powershell.exe -Verb RunAs -Wait `
|
||||||
|
-ArgumentList "-ExecutionPolicy", "Bypass", `
|
||||||
|
"-C", "cd $pwd; ipmo ./util/wsl.psm1; InstallWSL"
|
||||||
|
}
|
||||||
|
|
||||||
|
$install = Read-Host "Install WSL Distribution now? [Y/n]"
|
||||||
|
if ($install.ToLower() -eq 'n')
|
||||||
|
{ return
|
||||||
|
}
|
||||||
|
|
||||||
|
wsl.exe --install -d Ubuntu
|
||||||
|
|
||||||
|
# Add newly created user to sudoers group
|
||||||
|
$user = wsl.exe cut "-d:" "-f1" /etc/passwd | Select-Object -Last 1
|
||||||
|
wsl.exe -u root echo "$user ALL=(ALL) NOPASSWD:ALL" ">>" "/etc/sudoers.d/$user"
|
||||||
|
|
||||||
|
# Update packages and install from list
|
||||||
|
wsl.exe sudo apt update "&&" sudo apt upgrade "-y"
|
||||||
|
wsl.exe sudo apt install "-y" (Get-Content ./util/wsl.list)
|
||||||
|
}
|
||||||
|
|
||||||
|
function InstallWSLNeovim
|
||||||
|
{
|
||||||
|
param (
|
||||||
|
[string]$source
|
||||||
|
)
|
||||||
|
|
||||||
|
Import-Module ./util/windows.psm1
|
||||||
|
|
||||||
|
Push-Location
|
||||||
|
ProcessUrlFiles -source $source
|
||||||
|
Set-Location "$env:TMP\nvim-config"
|
||||||
|
|
||||||
|
Write-Host "Copying (forcably) configuration to WSL..." -ForegroundColor Yellow
|
||||||
|
wsl.exe cp -rf . ~/.config/ 2>$null | Out-Null
|
||||||
|
Pop-Location
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user