mirror of
https://github.com/m1ngsama/winfig.git
synced 2025-12-24 10:51:49 +00:00
feat: add setup and uninstall scripts
This commit is contained in:
parent
da82a5866f
commit
03080b89e8
2 changed files with 251 additions and 0 deletions
162
setup.ps1
Normal file
162
setup.ps1
Normal file
|
|
@ -0,0 +1,162 @@
|
|||
# Winfig Setup Script
|
||||
# Automated setup for Windows development environment
|
||||
|
||||
param(
|
||||
[switch]$SkipScoop,
|
||||
[switch]$SkipGit,
|
||||
[switch]$SkipPowerShell,
|
||||
[switch]$SkipTerminal,
|
||||
[switch]$DryRun
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
function Write-ColorOutput {
|
||||
param($message, $color = "White")
|
||||
Write-Host $message -ForegroundColor $color
|
||||
}
|
||||
|
||||
function Write-Section {
|
||||
param($title)
|
||||
Write-ColorOutput "`n=== $title ===" "Magenta"
|
||||
}
|
||||
|
||||
function Test-Admin {
|
||||
$currentUser = [Security.Principal.WindowsIdentity]::GetCurrent()
|
||||
$principal = New-Object Security.Principal.WindowsPrincipal($currentUser)
|
||||
return $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
|
||||
}
|
||||
|
||||
function Copy-ConfigFile {
|
||||
param($source, $destination, $description)
|
||||
|
||||
if ($DryRun) {
|
||||
Write-ColorOutput " [DRY RUN] Would copy: $description" "Yellow"
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
$destDir = Split-Path $destination -Parent
|
||||
if (-not (Test-Path $destDir)) {
|
||||
New-Item -ItemType Directory -Path $destDir -Force | Out-Null
|
||||
}
|
||||
|
||||
Copy-Item -Path $source -Destination $destination -Force
|
||||
Write-ColorOutput " ✓ Copied: $description" "Green"
|
||||
} catch {
|
||||
Write-ColorOutput " ✗ Failed: $description - $($_.Exception.Message)" "Red"
|
||||
}
|
||||
}
|
||||
|
||||
Write-Section "Winfig Setup"
|
||||
Write-ColorOutput "Automated Windows development environment configuration"
|
||||
Write-ColorOutput ""
|
||||
|
||||
if ($DryRun) {
|
||||
Write-ColorOutput "Running in DRY RUN mode - no changes will be made" "Yellow"
|
||||
Write-ColorOutput ""
|
||||
}
|
||||
|
||||
# Check for admin rights for certain operations
|
||||
if (-not (Test-Admin)) {
|
||||
Write-ColorOutput "Note: Some operations may require administrator privileges" "Yellow"
|
||||
Write-ColorOutput ""
|
||||
}
|
||||
|
||||
# PowerShell Configuration
|
||||
if (-not $SkipPowerShell) {
|
||||
Write-Section "PowerShell Configuration"
|
||||
|
||||
$profileDir = Split-Path $PROFILE -Parent
|
||||
$sourceProfile = Join-Path $PSScriptRoot "powershell\user_profile.ps1"
|
||||
$sourceOmp = Join-Path $PSScriptRoot "powershell\m1ng.omp.json"
|
||||
|
||||
Copy-ConfigFile $sourceProfile $PROFILE "PowerShell profile"
|
||||
Copy-ConfigFile $sourceOmp (Join-Path $profileDir "m1ng.omp.json") "Oh-My-Posh theme"
|
||||
|
||||
Write-ColorOutput ""
|
||||
Write-ColorOutput " Required PowerShell modules:" "Cyan"
|
||||
Write-ColorOutput " - posh-git" "White"
|
||||
Write-ColorOutput " - Terminal-Icons" "White"
|
||||
Write-ColorOutput " - PSFzf" "White"
|
||||
Write-ColorOutput ""
|
||||
Write-ColorOutput " Install with: Install-Module <module-name> -Scope CurrentUser" "Yellow"
|
||||
}
|
||||
|
||||
# Git Configuration
|
||||
if (-not $SkipGit) {
|
||||
Write-Section "Git Configuration"
|
||||
|
||||
$homeDir = $env:USERPROFILE
|
||||
$sourceGitConfig = Join-Path $PSScriptRoot "git\.gitconfig"
|
||||
$sourceGitIgnore = Join-Path $PSScriptRoot "git\.gitignore_global"
|
||||
|
||||
Copy-ConfigFile $sourceGitConfig (Join-Path $homeDir ".gitconfig") "Git config"
|
||||
Copy-ConfigFile $sourceGitIgnore (Join-Path $homeDir ".gitignore_global") "Global gitignore"
|
||||
|
||||
Write-ColorOutput ""
|
||||
Write-ColorOutput " Don't forget to set your Git identity:" "Yellow"
|
||||
Write-ColorOutput " git config --global user.name `"Your Name`"" "White"
|
||||
Write-ColorOutput " git config --global user.email `"your.email@example.com`"" "White"
|
||||
}
|
||||
|
||||
# Windows Terminal Configuration
|
||||
if (-not $SkipTerminal) {
|
||||
Write-Section "Windows Terminal Configuration"
|
||||
|
||||
$terminalSettingsPath = "$env:LOCALAPPDATA\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json"
|
||||
$sourceTerminalSettings = Join-Path $PSScriptRoot "windows-terminal\settings.json"
|
||||
|
||||
if (Test-Path (Split-Path $terminalSettingsPath -Parent)) {
|
||||
# Backup existing settings
|
||||
if (Test-Path $terminalSettingsPath) {
|
||||
$backupPath = "$terminalSettingsPath.backup.$(Get-Date -Format 'yyyyMMdd-HHmmss')"
|
||||
if (-not $DryRun) {
|
||||
Copy-Item $terminalSettingsPath $backupPath
|
||||
Write-ColorOutput " ✓ Backed up existing settings to: $backupPath" "Green"
|
||||
} else {
|
||||
Write-ColorOutput " [DRY RUN] Would backup to: $backupPath" "Yellow"
|
||||
}
|
||||
}
|
||||
|
||||
Copy-ConfigFile $sourceTerminalSettings $terminalSettingsPath "Windows Terminal settings"
|
||||
} else {
|
||||
Write-ColorOutput " ⚠ Windows Terminal not found or not installed" "Yellow"
|
||||
}
|
||||
}
|
||||
|
||||
# Scoop Setup
|
||||
if (-not $SkipScoop) {
|
||||
Write-Section "Scoop Package Manager"
|
||||
|
||||
if (Get-Command scoop -ErrorAction SilentlyContinue) {
|
||||
Write-ColorOutput " ✓ Scoop is already installed" "Green"
|
||||
Write-ColorOutput ""
|
||||
Write-ColorOutput " Install packages with:" "Cyan"
|
||||
Write-ColorOutput " cd scoop" "White"
|
||||
Write-ColorOutput " .\install-packages.ps1" "White"
|
||||
} else {
|
||||
Write-ColorOutput " ✗ Scoop is not installed" "Red"
|
||||
Write-ColorOutput ""
|
||||
Write-ColorOutput " Install Scoop with:" "Yellow"
|
||||
Write-ColorOutput " Set-ExecutionPolicy RemoteSigned -Scope CurrentUser" "White"
|
||||
Write-ColorOutput " irm get.scoop.sh | iex" "White"
|
||||
}
|
||||
}
|
||||
|
||||
# Tmux Configuration (if using WSL)
|
||||
Write-Section "Tmux Configuration (WSL)"
|
||||
Write-ColorOutput " Tmux configuration is available in tmux/ directory" "Cyan"
|
||||
Write-ColorOutput " Copy to WSL: cp -r tmux ~/.config/tmux" "White"
|
||||
|
||||
# Summary
|
||||
Write-Section "Setup Complete"
|
||||
Write-ColorOutput ""
|
||||
Write-ColorOutput "Next steps:" "Green"
|
||||
Write-ColorOutput " 1. Restart PowerShell to apply changes" "White"
|
||||
Write-ColorOutput " 2. Install required PowerShell modules" "White"
|
||||
Write-ColorOutput " 3. Set your Git identity" "White"
|
||||
Write-ColorOutput " 4. Install Scoop packages (cd scoop && .\install-packages.ps1)" "White"
|
||||
Write-ColorOutput " 5. Restart Windows Terminal to see new settings" "White"
|
||||
Write-ColorOutput ""
|
||||
Write-ColorOutput "For more information, see README.md" "Cyan"
|
||||
89
uninstall.ps1
Normal file
89
uninstall.ps1
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
# Winfig Uninstall Script
|
||||
# Removes winfig configurations and restores backups
|
||||
|
||||
param(
|
||||
[switch]$RemoveModules,
|
||||
[switch]$Force
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
function Write-ColorOutput {
|
||||
param($message, $color = "White")
|
||||
Write-Host $message -ForegroundColor $color
|
||||
}
|
||||
|
||||
function Write-Section {
|
||||
param($title)
|
||||
Write-ColorOutput "`n=== $title ===" "Magenta"
|
||||
}
|
||||
|
||||
function Remove-ConfigFile {
|
||||
param($path, $description)
|
||||
|
||||
if (Test-Path $path) {
|
||||
if ($Force) {
|
||||
Remove-Item $path -Force
|
||||
Write-ColorOutput " ✓ Removed: $description" "Green"
|
||||
} else {
|
||||
$backup = "$path.backup.$(Get-Date -Format 'yyyyMMdd-HHmmss')"
|
||||
Move-Item $path $backup
|
||||
Write-ColorOutput " ✓ Backed up to: $backup" "Green"
|
||||
}
|
||||
} else {
|
||||
Write-ColorOutput " ⚠ Not found: $description" "Yellow"
|
||||
}
|
||||
}
|
||||
|
||||
Write-Section "Winfig Uninstall"
|
||||
Write-ColorOutput "Removing winfig configurations"
|
||||
Write-ColorOutput ""
|
||||
|
||||
if (-not $Force) {
|
||||
Write-ColorOutput "Running in safe mode - configurations will be backed up" "Yellow"
|
||||
Write-ColorOutput "Use -Force to remove without backup" "Yellow"
|
||||
Write-ColorOutput ""
|
||||
}
|
||||
|
||||
# Remove PowerShell configuration
|
||||
Write-Section "PowerShell Configuration"
|
||||
$profileDir = Split-Path $PROFILE -Parent
|
||||
Remove-ConfigFile $PROFILE "PowerShell profile"
|
||||
Remove-ConfigFile (Join-Path $profileDir "m1ng.omp.json") "Oh-My-Posh theme"
|
||||
|
||||
# Remove Git configuration
|
||||
Write-Section "Git Configuration"
|
||||
$homeDir = $env:USERPROFILE
|
||||
Remove-ConfigFile (Join-Path $homeDir ".gitconfig") "Git config"
|
||||
Remove-ConfigFile (Join-Path $homeDir ".gitignore_global") "Global gitignore"
|
||||
|
||||
# Remove Windows Terminal configuration
|
||||
Write-Section "Windows Terminal Configuration"
|
||||
$terminalSettingsPath = "$env:LOCALAPPDATA\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json"
|
||||
Remove-ConfigFile $terminalSettingsPath "Windows Terminal settings"
|
||||
|
||||
# Remove PowerShell modules
|
||||
if ($RemoveModules) {
|
||||
Write-Section "PowerShell Modules"
|
||||
Write-ColorOutput " Uninstalling modules..." "Cyan"
|
||||
|
||||
$modules = @('posh-git', 'Terminal-Icons', 'PSFzf')
|
||||
foreach ($module in $modules) {
|
||||
if (Get-Module -ListAvailable -Name $module) {
|
||||
Uninstall-Module $module -Force -ErrorAction SilentlyContinue
|
||||
Write-ColorOutput " ✓ Removed: $module" "Green"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Write-Section "Uninstall Complete"
|
||||
Write-ColorOutput ""
|
||||
Write-ColorOutput "Configurations have been removed or backed up" "Green"
|
||||
Write-ColorOutput "Restart PowerShell and Windows Terminal to apply changes" "Cyan"
|
||||
Write-ColorOutput ""
|
||||
|
||||
if (-not $RemoveModules) {
|
||||
Write-ColorOutput "PowerShell modules were not removed" "Yellow"
|
||||
Write-ColorOutput "Use -RemoveModules to uninstall them" "Yellow"
|
||||
Write-ColorOutput ""
|
||||
}
|
||||
Loading…
Reference in a new issue