Update powershell shit

This commit is contained in:
Isaac Shoebottom 2024-02-02 22:28:57 -04:00
parent 8918c9d197
commit 69c1645301
4 changed files with 53 additions and 1 deletions

View File

@ -0,0 +1,8 @@
# Sync apps with scoop
&~/Documents/PowerShell/verify-state.ps1
# Shell completion
&~/Documents/PowerShell/completions.ps1
# Aliases
&~/Documents/PowerShell/aliases.ps1

View File

@ -0,0 +1,5 @@
# Unix like pwd
if (Test-Path alias:pwd) {
Remove-Alias -Name pwd
}
Function pwd {(Get-Location).Path}

View File

@ -1,2 +1,10 @@
# Scoop search
Invoke-Expression (&scoop-search --hook)
# Scoop completion
Import-Module "$($(Get-Item $(Get-Command scoop.ps1).Path).Directory.Parent.FullName)\modules\scoop-completion"
# Chezmoi
if (Get-Command chezmoi -ErrorAction SilentlyContinue) { chezmoi completion powershell | Out-String | Invoke-Expression }
if (Get-Command chezmoi -ErrorAction SilentlyContinue) { chezmoi completion powershell | Out-String | Invoke-Expression }
# LunarVim
Set-Alias lvim 'C:\Users\Isaac\.local\bin\lvim.ps1'
# Github CLI
Invoke-Expression -Command $(gh completion -s powershell | Out-String)

View File

@ -0,0 +1,31 @@
function differences($required, $installed) {
# Args in json format
# Only compare the names of the software
# Format is a json array of objects with a name property
$required_names = $required | ForEach-Object { $_.name }
$installed_names = $installed | ForEach-Object { $_.name }
$diff = Compare-Object $required_names $installed_names
return $diff
}
if (-not (Test-Path "~\scoop\apps.json")) {
Write-Host "Scoop is installed but the apps.json file is missing"
scoop export | Out-File "~\scoop\apps.json"
}
# Diff the installed software with the required software, if there are differences, install the required software
$required = Get-Content "~\scoop\apps.json" | ConvertFrom-Json
$installed = scoop export | ConvertFrom-Json
$differences = differences $required.apps $installed.apps
if ($differences) {
Write-Host "The following software is missing:"
$differences | ForEach-Object { Write-Host $_.InputObject }
$install = Read-Host "Would you like to install the missing software? (y/n)"
if ($install -eq "y") {
# Install the missing software
scoop import "~\scoop\apps.json"
}
else {
Write-Host "The required software is not installed"
}
}