diff --git a/Documents/PowerShell/Microsoft.PowerShell_profile.ps1 b/Documents/PowerShell/Microsoft.PowerShell_profile.ps1 new file mode 100644 index 0000000..3f76851 --- /dev/null +++ b/Documents/PowerShell/Microsoft.PowerShell_profile.ps1 @@ -0,0 +1,8 @@ +# Sync apps with scoop +&~/Documents/PowerShell/verify-state.ps1 + +# Shell completion +&~/Documents/PowerShell/completions.ps1 + +# Aliases +&~/Documents/PowerShell/aliases.ps1 \ No newline at end of file diff --git a/Documents/PowerShell/aliases.ps1 b/Documents/PowerShell/aliases.ps1 new file mode 100644 index 0000000..ceb4b6d --- /dev/null +++ b/Documents/PowerShell/aliases.ps1 @@ -0,0 +1,5 @@ +# Unix like pwd +if (Test-Path alias:pwd) { + Remove-Alias -Name pwd + } + Function pwd {(Get-Location).Path} \ No newline at end of file diff --git a/Documents/PowerShell/completions.ps1 b/Documents/PowerShell/completions.ps1 index 3afa3a2..c5ab71f 100644 --- a/Documents/PowerShell/completions.ps1 +++ b/Documents/PowerShell/completions.ps1 @@ -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 } \ No newline at end of file +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) \ No newline at end of file diff --git a/Documents/PowerShell/verify-state.ps1 b/Documents/PowerShell/verify-state.ps1 new file mode 100644 index 0000000..91c4e10 --- /dev/null +++ b/Documents/PowerShell/verify-state.ps1 @@ -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" + } +} \ No newline at end of file