aboutsummaryrefslogtreecommitdiff
path: root/.config/powershell
diff options
context:
space:
mode:
Diffstat (limited to '.config/powershell')
-rw-r--r--.config/powershell/bootstrap.ps1193
1 files changed, 110 insertions, 83 deletions
diff --git a/.config/powershell/bootstrap.ps1 b/.config/powershell/bootstrap.ps1
index 1b51ad2..3d04097 100644
--- a/.config/powershell/bootstrap.ps1
+++ b/.config/powershell/bootstrap.ps1
@@ -17,6 +17,11 @@ function handle_error {
exit 1
}
+# Logs
+New-Item -Path $Env:USERPROFILE\Logs -ItemType directory -Force
+Start-Transcript -Path $Env:USERPROFILE\Logs\Bootstrap.log
+$ErrorActionPreference = 'SilentlyContinue'
+
# Function to check if the current session is elevated
function Test-IsAdmin {
$currentUser = [Security.Principal.WindowsIdentity]::GetCurrent()
@@ -78,8 +83,6 @@ if (!(Test-Path -Path "$home\.config\powershell\Microsoft.PowerShell_profile.ps1
Write-Host "Installing Chocolatey"
Write-Host "----------------------------------------"
-#Set-ExecutionPolicy Bypass -Scope Process -Force
-
if (-not (Get-Command choco -ErrorAction SilentlyContinue)) {
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
@@ -106,20 +109,17 @@ $apps = @(
"microsoft-windows-terminal",
"wsl",
"firefox",
- #"spotify",
- #"discord",
- #"vscode",
+ "setdefaultbrowser",
"nodejs",
"bat",
- #"coreutils",
- #"delta",
- #"fnm",
- #"gh",
- #"less",
- #"lua",
- #"make",
- #"tokei",
- #"zoxide"
+ "7zip",
+ "python",
+ "neofetch",
+ "adobereader",
+ "javaruntime",
+ "autohotkey",
+ "bitwarden",
+ "notepadplusplus",
"neovim"
)
@@ -139,6 +139,17 @@ foreach ($app in $apps) {
}
}
+# Set Chrome as default browser ------------------------
+#Add-Type -AssemblyName 'System.Windows.Forms'
+#Start-Process $env:windir\system32\control.exe -ArgumentList '/name Microsoft.DefaultPrograms /page pageDefaultProgram\pageAdvancedSettings?pszAppName=google%20chrome'
+#Sleep 2
+#[System.Windows.Forms.SendKeys]::SendWait("{TAB} {TAB}{TAB} ")
+SetDefaultBrowser firefox
+
+# Refresh the environment variables
+Write-Host "Refreshing environment variables"
+refreshenv
+
# Define the `config` alias in the current session
function global:config {
git --git-dir="$env:USERPROFILE\.cfg" --work-tree="$env:USERPROFILE" $args
@@ -149,19 +160,8 @@ Add-Content -Path "$HOME\.gitignore" -Value ".cfg"
Add-Content -Path "$HOME\.gitignore" -Value "install.bat"
Add-Content -Path "$HOME\.gitignore" -Value ".config/powershell/bootstrap.ps1"
-## Check if the profile exists, otherwise create it
-#if (!(Test-Path -Path $PROFILE)) {
-# New-Item -Type File -Path $PROFILE -Force
-#}
-#Add-Content -Path $PROFILE -Value "`nfunction config { git --git-dir=`$env:USERPROFILE/.cfg/ --work-tree=`$env:USERPROFILE @args }"
-#Add-Content -Path $PROFILE -Value "`n. $PROFILE"
-
-# Source the profile immediately to make the alias available
-
-#echo '. "$HOME\Documents\PowerShell\Microsoft.PowerShell_profile.ps1"' >> $PROFILE
-
-# Create symbolik links
-Write-Host "Create symbolik links"
+# Create symbolic links
+Write-Host "Create symbolic links"
Write-Host "----------------------------------------"
# Visual Studio Code settings.json
@@ -170,12 +170,10 @@ New-Item -Force -ItemType SymbolicLink $HOME\AppData\Roaming\Code\User\ -Name se
# Visual Studio Code keybindings
New-Item -Force -ItemType SymbolicLink $HOME\AppData\Roaming\Code\User\ -Name keybindings.json -Value $HOME\.config\Code\User\keybindings.json
-
# Update the current session environment variables
Write-Host "Setting environment variables" -ForegroundColor Cyan
[Environment]::SetEnvironmentVariable("HOME", "$env:USERPROFILE", "User")
[Environment]::SetEnvironmentVariable("LC_ALL", "C.UTF-8", "User")
-#Update-SessionEnvironment
# Function to install dotfiles
function install_dotfiles {
@@ -214,52 +212,27 @@ function install_dotfiles {
install_dotfiles
-#. $PROFILE
-
# Install python
Write-Host "Updating python packages" -ForegroundColor Cyan
python -m pip install --upgrade pip
-#pip install --upgrade black flake8
# Enable WSL feature
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
Write-Host "Enable WSL feature"
+wsl --install -d ubuntu
+wsl --set-default-version 2
# Enable Virtual Machine feature
-dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
-Write-Host "Enable Virtual Machine feature"
-
-# WSL
-#Write-Host "Configuring WSL"
-#wsl --install -d Ubuntu
-# setup wsl
-#wsl --set-default-version 2
-#wsl -s Ubuntu
-
-## Function to install SSH
-#function install_ssh {
-# Write-Host "Setting Up SSH"
-# Start-Service ssh-agent
-# Start-Service sshd
-# Set-Service -Name ssh-agent -StartupType 'Automatic'
-# Set-Service -Name sshd -StartupType 'Automatic'
-#
-# # Generate SSH key if not exists
-# if (-not (Test-Path -Path "$env:USERPROFILE\.ssh\id_rsa.pub")) {
-# ssh-keygen -t rsa -b 4096 -C "$env:USERNAME@$(hostname)" -f "$env:USERPROFILE\.ssh\id_rsa" -N ""
-# }
-#
-# # Start ssh-agent and add key
-# eval $(ssh-agent -s)
-# ssh-add "$env:USERPROFILE\.ssh\id_rsa"
-#
-# # Display the SSH key
-# $sshKey = Get-Content "$env:USERPROFILE\.ssh\id_rsa.pub"
-# Write-Host "Add the following SSH key to your GitHub account:"
-# Write-Host $sshKey
-#}
-#
-#install_ssh
+#dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
+#Write-Host "Enable Virtual Machine feature"
+
+Write-Header "Installing Hyper-V"
+
+# Install Hyper-V
+Write-Host "Installing Hyper-V and restart"
+Enable-WindowsOptionalFeature -Online -FeatureName Containers -All -NoRestart
+Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -NoRestart
+Install-WindowsFeature -Name Hyper-V -IncludeAllSubFeature -IncludeManagementTools -NoRestart
# Configure Neovim
Write-Host "Configuring Neovim"
@@ -293,55 +266,109 @@ if (Test-Path -Path $windowsTerminalSettingsPath) {
# Create a hard link to the settings.json file in .config\windows-terminal
New-Item -ItemType HardLink -Force -Path $windowsTerminalSettingsPath -Target $windowsTerminalConfigPath
+# Function to check if a registry key exists
+function Test-RegistryKeyExists {
+ param ($path)
+ return (Test-Path $path -PathType Container)
+}
+
+# Function to check if a registry property exists
+function Test-RegistryPropertyExists {
+ param ($keyPath, $propertyName)
+ if (Test-Path $keyPath) {
+ $properties = Get-ItemProperty -Path $keyPath
+ return $properties.PSObject.Properties.Name -contains $propertyName
+ }
+ return $false
+}
+
# Registry Tweaks
Write-Host "Registry Tweaks"
Write-Host "----------------------------------------"
# Show hidden files
-Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name Hidden -Value 1
+$advancedKeyPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced"
+if (-not (Test-RegistryPropertyExists $advancedKeyPath "Hidden")) {
+ Set-ItemProperty -Path $advancedKeyPath -Name Hidden -Value 1
+}
-# Show file extensions for known file types
-Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name HideFileExt -Value 0
+# Show file extensions in Windows Explorer
+$hideFileExtPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced"
+if (-not (Test-RegistryPropertyExists $hideFileExtPath "HideFileExt")) {
+ Set-ItemProperty -Path $hideFileExtPath -Name HideFileExt -Value 0
+}
# Never Combine taskbar buttons when the taskbar is full
-Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name TaskbarGlomLevel -Value 2
+$taskbarGlomLevelPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced"
+if (-not (Test-RegistryPropertyExists $taskbarGlomLevelPath "TaskbarGlomLevel")) {
+ Set-ItemProperty -Path $taskbarGlomLevelPath -Name TaskbarGlomLevel -Value 2
+}
# Taskbar small icons
-Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name TaskbarSmallIcons -Value 1
+$taskbarSmallIconsPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced"
+if (-not (Test-RegistryPropertyExists $taskbarSmallIconsPath "TaskbarSmallIcons")) {
+ Set-ItemProperty -Path $taskbarSmallIconsPath -Name TaskbarSmallIcons -Value 1
+}
# Set Windows to use UTC time instead of local time for system clock
-Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\TimeZoneInformation" -Name RealTimeIsUniversal -Value 1
+$timeZoneInfoPath = "HKLM:\SYSTEM\CurrentControlSet\Control\TimeZoneInformation"
+if (-not (Test-RegistryPropertyExists $timeZoneInfoPath "RealTimeIsUniversal")) {
+ Set-ItemProperty -Path $timeZoneInfoPath -Name RealTimeIsUniversal -Value 1
+}
+
+# Disable the search in taskbar
+$searchBoxTaskbarPath = "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Search"
+if (-not (Test-RegistryPropertyExists $searchBoxTaskbarPath "SearchBoxTaskbarMode")) {
+ New-ItemProperty -Path $searchBoxTaskbarPath -Name SearchBoxTaskbarMode -Value 0 -Type DWord -Force
+}
+
+# Dark mode:
+$personalizePath = "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize"
+if (-not (Test-RegistryPropertyExists $personalizePath "AppsUseLightTheme")) {
+ Set-ItemProperty -Path $personalizePath -Name AppsUseLightTheme -Value 0 -Type Dword -Force
+}
+if (-not (Test-RegistryPropertyExists $personalizePath "SystemUsesLightTheme")) {
+ Set-ItemProperty -Path $personalizePath -Name SystemUsesLightTheme -Value 0 -Type Dword -Force
+}
+
+# Restart explorer so the rest of the settings take effect:
+Stop-Process -f -ProcessName explorer
+Start-Process explorer.exe
# Function to disable the Windows key
function Disable-WindowsKey {
$regPath = "HKLM:\SYSTEM\CurrentControlSet\Control\Keyboard Layout"
$regName = "Scancode Map"
- # Binary data to disable the Windows key
+ # Binary data to remap the Windows key to F24 (an unused key)
$binaryValue = [byte[]](
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
- 0x03, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x5B, 0xE0,
- 0x00, 0x00, 0x5C, 0xE0,
+ 0x02, 0x00, 0x00, 0x00,
+ 0x3A, 0x00, 0x5B, 0xE0,
0x00, 0x00, 0x00, 0x00
)
# Create the registry key if it doesn't exist
- if (-not (Test-Path $regPath)) {
+ if (-not (Test-RegistryKeyExists $regPath)) {
New-Item -Path $regPath -Force | Out-Null
}
- # Set the Scancode Map value
- Set-ItemProperty -Path $regPath -Name $regName -Value $binaryValue
+ # Set the Scancode Map value if it doesn't exist
+ if (-not (Test-RegistryPropertyExists $regPath $regName)) {
+ Set-ItemProperty -Path $regPath -Name $regName -Value $binaryValue
+ }
- Write-Output "Windows key has been disabled. Please restart your computer for the changes to take effect."
+ Write-Output "Windows key has been disabled from opening the start menu. Please restart your computer for the changes to take effect."
}
Disable-WindowsKey
Write-Host "Bootstrap script completed."
+Write-Host "Please Restart."
-# Restart to apply changes
-#Write-Host "Restarting system to apply changes..."
-#Restart-Computer -Force
+# Clean up Bootstrap.log
+Write-Host "Clean up Bootstrap.log"
+Stop-Transcript
+$logSuppress = Get-Content $Env:USERPROFILE\Logs\Bootstrap.log | Where-Object { $_ -notmatch "Host Application: powershell.exe" }
+$logSuppress | Set-Content $Env:USERPROFILE\Logs\Bootstrap.log -Force