Skip to content

Commit

Permalink
feat(win_setup, pwsh): Adding windows setup scripts into .local and r…
Browse files Browse the repository at this point in the history
…efactoring pwsh profile functions.
  • Loading branch information
kalocsaibotond committed Mar 24, 2024
1 parent b65cd83 commit 325de1f
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 26 deletions.
2 changes: 2 additions & 0 deletions home/.chezmoiignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{{- if ne .chezmoi.os "windows" }}
Documents
windows_setup
workspacer
wezterm
{{- end }}

75 changes: 49 additions & 26 deletions home/Documents/PowerShell/Functions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,38 +30,54 @@ function Add-ContextMenuDir
if ($Global){
if (Test-Path $registryContextMenuLocation){
Remove-PSDrive HKCR | Out-Null
New-PSDrive -PSProvider registry -Root HKEY_CLASSES_ROOT `
-Name HKCR | Out-Null
New-PSDrive @{
PSProvider = "registry"
Root = "HKEY_CLASSES_ROOT"
Name = "HKCR"
) | Out-Null
} else {
New-PSDrive -PSProvider registry -Root HKEY_CLASSES_ROOT `
-Name HKCR | Out-Null
New-PSDrive
PSProvider = "registry"
Root = "HKEY_CLASSES_ROOT"
Name = "HKCR"
) | Out-Null
}
$psDriveClasses = "HKCR:"
} else {
$psDriveClasses = "HKCU:\SOFTWARE\Classes"
}

$ContextMenuDirRegeditEntries = @(
"Directory\Background\shell",
"Directory\shell",
"Folder\Background\shell",
"Folder\shell",
"Directory\Background\shell"
"Directory\shell"
"Folder\Background\shell"
"Folder\shell"
"Drive\shell"
)
foreach($shell in $ContextMenuDirRegeditEntries){
$registryPath = Join-Path (Join-Path $psDriveClasses $shell) `
$DisplayName
$registryPath = Join-Path (
Join-Path $psDriveClasses $shell
) $DisplayName

New-Item -Path $registryPath -Force | Out-Null
Set-ItemProperty -Path $registryPath -Name "(Default)" `
-Value "Open $DisplayName here"
Set-ItemProperty -Path $registryPath -Name "Icon" `
-Value "$ApplicationPath"
Set-ItemProperty @{
Path = $registryPath
Name = "(Default)"
Value = "Open $DisplayName here"
}
Set-ItemProperty @{
Path = $registryPath
Name = "Icon"
Value = "$ApplicationPath"
}

$commandPath = Join-Path $registryPath "command"
New-Item -Path $commandPath -Force | Out-Null
Set-ItemProperty -Path $commandPath -Name "(Default)" `
-Value "$ApplicationPath $ApplicationArgs"
Set-ItemProperty @{
Path = $commandPath
Name = "(Default)"
Value = "$ApplicationPath $ApplicationArgs"
}
}
}

Expand All @@ -86,27 +102,34 @@ function Remove-ContextMenuDir
if ($Global){
if (Test-Path $registryContextMenuLocation){
Remove-PSDrive HKCR | Out-Null
New-PSDrive -PSProvider registry -Root HKEY_CLASSES_ROOT `
-Name HKCR | Out-Null
New-PSDrive @{
PSProvider = "registry"
Root = "HKEY_CLASSES_ROOT"
Name = "HKCR"
} | Out-Null
} else {
New-PSDrive -PSProvider registry -Root HKEY_CLASSES_ROOT `
-Name HKCR | Out-Null
New-PSDrive @{
PSProvider = "registry"
Root = "HKEY_CLASSES_ROOT"
Name = "HKCR"
} | Out-Null
}
$psDriveClasses = "HKCR:"
} else {
$psDriveClasses = "HKCU:\SOFTWARE\Classes"
}

$ContextMenuDirRegeditEntries = @(
"Directory\Background\shell",
"Directory\shell",
"Folder\Background\shell",
"Folder\shell",
"Directory\Background\shell"
"Directory\shell"
"Folder\Background\shell"
"Folder\shell"
"Drive\shell"
)
foreach($shell in $ContextMenuDirRegeditEntries){
$registryPath = Join-Path (Join-Path $psDriveClasses $shell) `
$DisplayName
$registryPath = Join-Path (
Join-Path $psDriveClasses $shell
) $DisplayName
Remove-Item -Path $registryPath -Force -Recurse | Out-Null
}
}
1 change: 1 addition & 0 deletions home/Documents/PowerShell/Microsoft.PowerShell_profile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ $ProfileLocation = Split-Path -Path $Profile.CurrentUserCurrentHost -Parent

."$ProfileLocation\Variables.ps1"
."$ProfileLocation\Initialisations.ps1"
."$ProfileLocation\Functions.ps1"
50 changes: 50 additions & 0 deletions home/dot_local/windows_setup/Install-WindowsSetup.ps1.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
."..\..\Documents\PowerShell\Functions.ps1"

# Install Scoop packages
# NOTE: Scoop is the primary package manager for my environment

irm get.scoop.sh | iex
if (-Not (Get-Command git -ErrorAction SilentlyContinue)){
scoop install main/git # Git is required to install other buckets
}

{{range .scoop.buckets -}}
scoop bucket add {{. | quote}}
{{- end}}

scoop install @(
{{range .scoop.packages}}{{. | quote}}
{{end -}}
)

if (-Not (Get-Command winget -ErrorAction SilentlyContinue)){
scoop install main/winget
}

# Install Winget packages

winget install @(
{{range .winget.packages}}{{. | quote}}
{{end -}}
"--accept-source-agreements"
"--accept-package-agreements"
"--silent"
"--disable-interactivity"
)

# Set up configuration

.\Add-ContextMenuDir.ps1 @{
DisplayName = "WezTerm"
ApplicationPath = "$(scoop prefix wezterm)\wezterm-gui.exe"
ApplicationArgs = 'start --no-auto-connect --cwd "%V"'
}

nvm install lts
nvm on
Invoke-Expression "$(scoop prefix nvm)\nodejs\nodejs\npm install -g neovim"

conda init powershell
conda install -y -c conda-forge pynvim

git config --global credential.helper manager
30 changes: 30 additions & 0 deletions home/dot_local/windows_setup/Uninstall-WindowsSetup.ps1.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
."..\..\Documents\PowerShell\Functions.ps1"

# Cleaning up configuration

Remove-ContextMenuDir.ps1 -DisplayName "WezTerm"

$Targets = @(chezmoi managed --include files --path-style absolute)
foreach ($Target in $Targets) {
Remove-Item -Path $Target
}
chezmoi purge

# Cleaning up installations
# NOTE: Only Scoop, Git, and Winget remains

winget uninstall @(
{{range .winget.packages}}{{. | quote}}
{{end -}}
"--purge"
"--accept-source-agreements"
"--accept-package-agreements"
"--silent"
"--disable-interactivity"
)

scoop uninstall @(
{{range .scoop.packages}}{{. | quote}}
{{end -}}
"--purge"
)

0 comments on commit 325de1f

Please sign in to comment.