aboutsummaryrefslogtreecommitdiff
path: root/.config/powershell
diff options
context:
space:
mode:
authorsrdusr <trevorgray@srdusr.com>2024-05-28 01:26:15 +0200
committersrdusr <trevorgray@srdusr.com>2024-05-28 01:26:15 +0200
commitc464f80112a2f1a9ca973904e5f05df916e7d72e (patch)
treee87afab1631fd10402bc31ae85c6a9988645fab6 /.config/powershell
parent1002ffb8b2c7aa97d2a42d2e8cb2aa56a1fdecc3 (diff)
downloaddotfiles-c464f80112a2f1a9ca973904e5f05df916e7d72e.tar.gz
dotfiles-c464f80112a2f1a9ca973904e5f05df916e7d72e.zip
Set correct username, source/checkout profile
Diffstat (limited to '.config/powershell')
-rw-r--r--.config/powershell/bootstrap.ps175
1 files changed, 70 insertions, 5 deletions
diff --git a/.config/powershell/bootstrap.ps1 b/.config/powershell/bootstrap.ps1
index 53ec1b0..df0af1c 100644
--- a/.config/powershell/bootstrap.ps1
+++ b/.config/powershell/bootstrap.ps1
@@ -4,12 +4,55 @@
# Write-Host ----------------------------------------
# Set-ExecutionPolicy Unrestricted
-# Function to check if NVM is installed
-function Test-NVMInstalled {
- $nvmPath = "$env:USERPROFILE\AppData\Roaming\nvm\nvm.exe"
- return Test-Path -Path $nvmPath
+$newUsername = "srdusr"
+$newUserProfilePath = "C:\Users\$newUsername"
+$oldUsername = $env:USERNAME
+
+# Function to update registry for user profile path
+function Update-ProfileRegistry {
+ $profileListKey = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
+ $subKeys = Get-ChildItem -Path $profileListKey
+ foreach ($subKey in $subKeys) {
+ $profileImagePath = (Get-ItemProperty -Path "$profileListKey\$($subKey.PSChildName)").ProfileImagePath
+ if ($profileImagePath -like "*$oldUsername*") {
+ $newProfileImagePath = $profileImagePath -replace $oldUsername, $newUsername
+ Set-ItemProperty -Path "$profileListKey\$($subKey.PSChildName)" -Name ProfileImagePath -Value $newProfileImagePath
+ Write-Host "Updated ProfileImagePath for $($subKey.PSChildName)"
+ }
+ }
}
+# Function to update environment variables
+function Update-EnvironmentVariables {
+ $envVars = [System.Environment]::GetEnvironmentVariables("User")
+ foreach ($envVar in $envVars.Keys) {
+ if ($envVars[$envVar] -like "*$oldUsername*") {
+ $newEnvValue = $envVars[$envVar] -replace $oldUsername, $newUsername
+ [System.Environment]::SetEnvironmentVariable($envVar, $newEnvValue, "User")
+ Write-Host "Updated environment variable $envVar"
+ }
+ }
+}
+
+# Rename the user profile directory
+function Rename-UserProfileDirectory {
+ $oldUserProfilePath = "C:\Users\$oldUsername"
+ if (Test-Path -Path $oldUserProfilePath) {
+ Rename-Item -Path $oldUserProfilePath -NewName $newUsername
+ Write-Host "Renamed user profile directory from $oldUserProfilePath to $newUserProfilePath"
+ } else {
+ Write-Host "The old user profile directory $oldUserProfilePath does not exist."
+ }
+}
+
+# Perform the updates
+Rename-UserProfileDirectory
+Update-ProfileRegistry
+Update-EnvironmentVariables
+
+Write-Host "Profile registry paths, environment variables, and user profile directory have been updated. Please reboot the system."
+
+
# Install NVM if not installed
Write-Host "Configuring NVM"
Write-Host "----------------------------------------"
@@ -74,8 +117,17 @@ New-Item -ItemType HardLink -Force `
# Configure PowerShell
Write-Host "Configuring PowerShell"
Write-Host "----------------------------------------"
+$documentsPath = [Environment]::GetFolderPath('Personal') # Default Documents folder
+if ($documentsPath -like "*OneDrive*") {
+ $documentsPath = "$env:USERPROFILE\Documents"
+}
+$powerShellProfileDir = "$documentsPath\PowerShell"
+
+if (-not (Test-Path -Path $powerShellProfileDir)) {
+ New-Item -ItemType Directory -Path $powerShellProfileDir -Force
+}
New-Item -ItemType HardLink -Force `
- -Path "$home\Documents\PowerShell\Microsoft.PowerShell_profile.ps1" `
+ -Path "$powerShellProfileDir\Microsoft.PowerShell_profile.ps1" `
-Target "$home\.config\powershell\Microsoft.PowerShell_profile.ps1"
# Registry Tweaks
@@ -124,3 +176,16 @@ if (Test-IsAdmin) {
} else {
Write-Output "You need to run this script as Administrator to disable the Windows key."
}
+
+
+# Check if the profile exists, otherwise create it
+if (!(Test-Path -Path $PROFILE)) {
+ New-Item -Type File -Path $PROFILE -Force
+}
+
+# Set the content of the profile to load your dotfiles and define 'config' alias
+"'$env:USERPROFILE\.cfg'" >> $PROFILE
+"function global:config { git --git-dir=$env:USERPROFILE/.cfg --work-tree=$env:USERPROFILE $args }" >> $PROFILE
+"config config --local status.showUntrackedFiles no" >> $PROFILE
+"config checkout" >> $PROFILE
+