Skip to content

Commit 1fafe78

Browse files
committed
some small changes to fix warnings of PSScriptAnalyzer
1 parent 0223d39 commit 1fafe78

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

Microsoft.PowerShell_profile.ps1

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
### PowerShell Profile Refactor
2-
### Version 1.03 - Refactored
2+
### Version 1.04 - Refactored
33

44
$debug = $false
55

@@ -35,9 +35,6 @@ $debug = $false
3535
############ Set-PredictionSource ############
3636
#################################################################################################################################
3737

38-
### PowerShell Profile Refactor
39-
### Version 1.04 - Refactored
40-
4138
if ($debug_Override){
4239
# If variable debug_Override is defined in profile.ps1 file
4340
# then use it instead
@@ -110,7 +107,7 @@ if ($debug) {
110107
}
111108

112109

113-
#opt-out of telemetry before doing anything, only if PowerShell is run as admin
110+
# Opt-out of telemetry before doing anything, only if PowerShell is run as admin
114111
if ([bool]([System.Security.Principal.WindowsIdentity]::GetCurrent()).IsSystem) {
115112
[System.Environment]::SetEnvironmentVariable('POWERSHELL_TELEMETRY_OPTOUT', 'true', [System.EnvironmentVariableTarget]::Machine)
116113
}
@@ -145,7 +142,7 @@ function Update-Profile {
145142
# If function "Update-Profile_Override" is defined in profile.ps1 file
146143
# then call it instead.
147144
if (Get-Command -Name "Update-Profile_Override" -ErrorAction SilentlyContinue) {
148-
Update-Profile_Override;
145+
Update-Profile_Override
149146
} else {
150147
try {
151148
$url = "$repo_root/powershell-profile/main/Microsoft.PowerShell_profile.ps1"
@@ -184,7 +181,7 @@ function Update-PowerShell {
184181
# If function "Update-PowerShell_Override" is defined in profile.ps1 file
185182
# then call it instead.
186183
if (Get-Command -Name "Update-PowerShell_Override" -ErrorAction SilentlyContinue) {
187-
Update-PowerShell_Override;
184+
Update-PowerShell_Override
188185
} else {
189186
try {
190187
Write-Host "Checking for PowerShell updates..." -ForegroundColor Cyan
@@ -293,6 +290,13 @@ function Edit-Profile {
293290
}
294291
Set-Alias -Name ep -Value Edit-Profile
295292

293+
function Invoke-Profile {
294+
if ($PSVersionTable.PSEdition -eq "Desktop") {
295+
Write-Host "Note: Some Oh My Posh/PSReadLine errors are expected in PowerShell 5. The profile still works fine." -ForegroundColor Yellow
296+
}
297+
& $PROFILE
298+
}
299+
296300
function touch($file) { "" | Out-File $file -Encoding ASCII }
297301
function ff($name) {
298302
Get-ChildItem -recurse -filter "*${name}*" -ErrorAction SilentlyContinue | ForEach-Object {
@@ -301,21 +305,21 @@ function ff($name) {
301305
}
302306

303307
# Network Utilities
304-
function Get-PubIP { (Invoke-WebRequest http://ifconfig.me/ip).Content }
308+
function pubip { (Invoke-WebRequest http://ifconfig.me/ip).Content }
305309

306310
# Open WinUtil full-release
307311
function winutil {
308-
irm https://christitus.com/win | iex
312+
Invoke-Expression (Invoke-RestMethod https://christitus.com/win)
309313
}
310314

311315
# Open WinUtil dev-release
312316
function winutildev {
313-
# If function "WinUtilDev_Override" is defined in profile.ps1 file
317+
# If function "WinUtilDev_Override" is defined in profile.ps1 file
314318
# then call it instead.
315319
if (Get-Command -Name "WinUtilDev_Override" -ErrorAction SilentlyContinue) {
316320
WinUtilDev_Override
317321
} else {
318-
irm https://christitus.com/windev | iex
322+
Invoke-Expression (Invoke-RestMethod https://christitus.com/windev)
319323
}
320324
}
321325

@@ -372,10 +376,6 @@ function uptime {
372376
}
373377
}
374378

375-
function reload-profile {
376-
& $profile
377-
}
378-
379379
function unzip ($file) {
380380
Write-Output("Extracting", $file, "to", $pwd)
381381
$fullFile = Get-ChildItem -Path $pwd -Filter $file | ForEach-Object { $_.FullName }
@@ -602,7 +602,8 @@ Set-PSReadLineOption -AddToHistoryHandler {
602602

603603
# Fix Set-PredictionSource for Desktop
604604
function Set-PredictionSource {
605-
# If "Set-PredictionSource_Override" is defined in profile.ps1 file, call it instead.
605+
# If "Set-PredictionSource_Override" is defined in profile.ps1 file
606+
# then call it instead.
606607
if (Get-Command -Name "Set-PredictionSource_Override" -ErrorAction SilentlyContinue) {
607608
Set-PredictionSource_Override
608609
} elseif ($PSVersionTable.PSEdition -eq "Core") {
@@ -643,8 +644,10 @@ $scriptblock = {
643644
}
644645
Register-ArgumentCompleter -Native -CommandName dotnet -ScriptBlock $scriptblock
645646

647+
# If function "Get-Theme_Override" is defined in profile.ps1 file
648+
# then call it instead.
646649
if (Get-Command -Name "Get-Theme_Override" -ErrorAction SilentlyContinue) {
647-
Get-Theme_Override;
650+
Get-Theme_Override
648651
} else {
649652
# Oh My Posh initialization with local theme fallback and auto-download
650653
$localThemePath = Join-Path (Get-ProfileDir) "cobalt2.omp.json"
@@ -687,6 +690,7 @@ $($PSStyle.Foreground.Yellow)=======================$($PSStyle.Reset)
687690
$($PSStyle.Foreground.Green)Update-Profile$($PSStyle.Reset) - Checks for profile updates from a remote repository and updates if necessary.
688691
$($PSStyle.Foreground.Green)Update-PowerShell$($PSStyle.Reset) - Checks for the latest PowerShell release and updates if a new version is available.
689692
$($PSStyle.Foreground.Green)Edit-Profile$($PSStyle.Reset) - Opens the current user's profile for editing using the configured editor.
693+
$($PSStyle.Foreground.Green)Invoke-Profile$($PSStyle.Reset) - Runs the current user's profile to reload settings.
690694
691695
$($PSStyle.Foreground.Cyan)Git Shortcuts$($PSStyle.Reset)
692696
$($PSStyle.Foreground.Yellow)=======================$($PSStyle.Reset)
@@ -708,7 +712,7 @@ $($PSStyle.Foreground.Green)ep$($PSStyle.Reset) - Opens the profile for editing.
708712
$($PSStyle.Foreground.Green)export$($PSStyle.Reset) <name> <value> - Sets an environment variable.
709713
$($PSStyle.Foreground.Green)ff$($PSStyle.Reset) <name> - Finds files recursively with the specified name.
710714
$($PSStyle.Foreground.Green)flushdns$($PSStyle.Reset) - Clears the DNS cache.
711-
$($PSStyle.Foreground.Green)Get-PubIP$($PSStyle.Reset) - Retrieves the public IP address of the machine.
715+
$($PSStyle.Foreground.Green)pubip$($PSStyle.Reset) - Retrieves the public IP address of the machine.
712716
$($PSStyle.Foreground.Green)grep$($PSStyle.Reset) <regex> [dir] - Searches for a regex pattern in files within the specified directory or from the pipeline input.
713717
$($PSStyle.Foreground.Green)hb$($PSStyle.Reset) <file> - Uploads the specified file's content to a hastebin-like service and returns the URL.
714718
$($PSStyle.Foreground.Green)head$($PSStyle.Reset) <path> [n] - Displays the first n lines of a file (default 10).
@@ -731,7 +735,6 @@ $($PSStyle.Foreground.Green)sysinfo$($PSStyle.Reset) - Displays detailed system
731735
$($PSStyle.Foreground.Green)flushdns$($PSStyle.Reset) - Clears the DNS cache.
732736
$($PSStyle.Foreground.Green)cpy$($PSStyle.Reset) <text> - Copies the specified text to the clipboard.
733737
$($PSStyle.Foreground.Green)pst$($PSStyle.Reset) - Retrieves text from the clipboard.
734-
$($PSStyle.Foreground.Green)reload-profile$($PSStyle.Reset) - Reloads the current user's PowerShell profile.
735738
$($PSStyle.Foreground.Green)sed$($PSStyle.Reset) <file> <find> <replace> - Replaces text in a file.
736739
$($PSStyle.Foreground.Green)sysinfo$($PSStyle.Reset) - Displays detailed system information.
737740
$($PSStyle.Foreground.Green)tail$($PSStyle.Reset) <path> [n] - Displays the last n lines of a file (default 10).

setup.ps1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,10 @@ if ((Test-Path -Path $PROFILE) -and (winget list --name "OhMyPosh" -e) -and ($fo
149149

150150
# Choco install
151151
try {
152-
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
152+
Set-ExecutionPolicy Bypass -Scope Process -Force
153+
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
154+
$chocoScript = (New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')
155+
Invoke-Expression $chocoScript
153156
}
154157
catch {
155158
Write-Error "Failed to install Chocolatey. Error: $_"

0 commit comments

Comments
 (0)