diff --git a/.gitignore b/.gitignore index 68ab61c..1201466 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ profile.d/env.ps1 *.local.ps1 *.local +.vscode/tasks.json diff --git a/base/Get-MyModules.ps1 b/base/Get-MyModules.ps1 index 9bb0096..3e7c7da 100644 --- a/base/Get-MyModules.ps1 +++ b/base/Get-MyModules.ps1 @@ -2,6 +2,21 @@ param([switch]$IgnoreSystem,[switch]$MissingOnly) $local:currentSys = @('Always') + ([SystemName]::_GetValidValues('',$true,$true)); +$local:oldPSGet = Get-Module PowerShellGet -ListAvailable -ErrorAction SilentlyContinue | + Sort-Object -Property Version -Descending | + Select-Object -First 1 | + Where-Object { $_.Version.Major -eq 1 } +if( $local:oldPSGet ) { + Write-Warning $(@( + "PowerShellGet is an old version ($($oldPSGet.Version)), the following code should upgrade it" + , " [Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12" + , " Install-PackageProvider -Name NuGet -Force" + , " Remove-Module PowerShellGet" + , " Install-Module -Name PowerShellGet -Force" + , " Update-Module -Name PowerShellGet" + ) -join "`n" ) +} + [MyConfig]::GetConfigPaths('mymodules',$false) | ForEach-Object { $local:modules = $( Get-Content $_ | ConvertFrom-Json ); diff --git a/base/Get-RandomString.ps1 b/base/Get-RandomString.ps1 new file mode 100644 index 0000000..05d3720 --- /dev/null +++ b/base/Get-RandomString.ps1 @@ -0,0 +1,8 @@ +param( + [Parameter(Mandatory)] + [int]$Length, + [string]$AllowedChars="ABCDEFGHIJKLMNOPQVRSTUWXYZabcdefghijklmnopqvrstuwxyz0123456789" +) + 1..$Length | ForEach-Object { + $AllowedChars[$([math]::Round($(Get-Random -Minimum 0 -Maximum ($AllowedChars.Length)),0))] + } | Join-String \ No newline at end of file diff --git a/base/Pause.ps1 b/base/Pause.ps1 new file mode 100644 index 0000000..64f8bc1 --- /dev/null +++ b/base/Pause.ps1 @@ -0,0 +1,45 @@ +# Code grabbed from: +# https://devtipscurator.wordpress.com/2017/02/01/quick-tip-how-to-wait-for-user-keypress-in-powershell/ +param($Message = "Press any key to continue...") +# Check if running in PowerShell ISE +If ($psISE) { + # "ReadKey" not supported in PowerShell ISE. + # Show MessageBox UI + $Shell = New-Object -ComObject "WScript.Shell" + $Button = $Shell.Popup("Click OK to continue.", 0, "Hello", 0) + Return +} +$Ignore = + 16, # Shift (left or right) + 17, # Ctrl (left or right) + 18, # Alt (left or right) + 20, # Caps lock + 91, # Windows key (left) + 92, # Windows key (right) + 93, # Menu key + 144, # Num lock + 145, # Scroll lock + 166, # Back + 167, # Forward + 168, # Refresh + 169, # Stop + 170, # Search + 171, # Favorites + 172, # Start/Home + 173, # Mute + 174, # Volume Down + 175, # Volume Up + 176, # Next Track + 177, # Previous Track + 178, # Stop Media + 179, # Play + 180, # Mail + 181, # Select Media + 182, # Application 1 + 183 # Application 2 + +Write-Host -NoNewline $Message +While ($Null -Eq $KeyInfo.VirtualKeyCode -Or $Ignore -Contains $KeyInfo.VirtualKeyCode) { + $KeyInfo = $Host.UI.RawUI.ReadKey("NoEcho, IncludeKeyDown") +} +$KeyInfo \ No newline at end of file diff --git a/base/profile.d/Style.ps1 b/base/profile.d/Style.ps1 index f635f5a..75acb43 100644 --- a/base/profile.d/Style.ps1 +++ b/base/profile.d/Style.ps1 @@ -1,4 +1,5 @@ -Get-Command Set-PSReadLineKeyHandler | ForEach-Object { Set-PSReadLineKeyHandler -Key Tab -Function MenuComplete } +Get-Command Set-PSReadLineKeyHandler -ErrorAction SilentlyContinue | + ForEach-Object { Set-PSReadLineKeyHandler -Key Tab -Function MenuComplete } if( Get-Command Set-PoshPrompt -ErrorAction SilentlyContinue ) { $local:poshPrompt = Join-Path $HOME ".oh-my-posh.omp.json" if( -not (Test-Path $poshPrompt) ) { $poshPrompt = "slim" } diff --git a/base/src/modules.json b/base/src/modules.json index f4bba93..c3241c8 100644 --- a/base/src/modules.json +++ b/base/src/modules.json @@ -1,5 +1,6 @@ { "Always": [ + "psreadline", "PowerShellCookbook", "oh-my-posh", "posh-git", diff --git a/scoop/profile.d/smart-refresh-on-startup.ps1 b/scoop/profile.d/smart-refresh-on-startup.ps1 index 02886a9..4c90375 100644 --- a/scoop/profile.d/smart-refresh-on-startup.ps1 +++ b/scoop/profile.d/smart-refresh-on-startup.ps1 @@ -1,3 +1,5 @@ +scoop autocomplete-on + if( Test-Path (Join-Path $env:SCOOP last-scoop-refresh.clixml) ) { scoop refresh } else {