Skip to content

Commit 554426b

Browse files
committed
some small changes to fix warnings of PSScriptAnalyzer
1 parent 32bdc93 commit 554426b

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

Microsoft.PowerShell_profile.ps1

Lines changed: 15 additions & 16 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
}
@@ -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,20 @@ 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
314-
# then call it instead.
317+
# If function "WinUtilDev_Override" is defined in profile.ps1 file, then call it instead.
315318
if (Get-Command -Name "WinUtilDev_Override" -ErrorAction SilentlyContinue) {
316319
WinUtilDev_Override
317320
} else {
318-
irm https://christitus.com/windev | iex
321+
Invoke-Expression (Invoke-RestMethod https://christitus.com/windev)
319322
}
320323
}
321324

@@ -372,10 +375,6 @@ function uptime {
372375
}
373376
}
374377

375-
function reload-profile {
376-
& $profile
377-
}
378-
379378
function unzip ($file) {
380379
Write-Output("Extracting", $file, "to", $pwd)
381380
$fullFile = Get-ChildItem -Path $pwd -Filter $file | ForEach-Object { $_.FullName }
@@ -683,6 +682,7 @@ $($PSStyle.Foreground.Yellow)=======================$($PSStyle.Reset)
683682
$($PSStyle.Foreground.Green)Update-Profile$($PSStyle.Reset) - Checks for profile updates from a remote repository and updates if necessary.
684683
$($PSStyle.Foreground.Green)Update-PowerShell$($PSStyle.Reset) - Checks for the latest PowerShell release and updates if a new version is available.
685684
$($PSStyle.Foreground.Green)Edit-Profile$($PSStyle.Reset) - Opens the current user's profile for editing using the configured editor.
685+
$($PSStyle.Foreground.Green)Invoke-Profile$($PSStyle.Reset) - Runs the current user's profile to reload settings.
686686
687687
$($PSStyle.Foreground.Cyan)Git Shortcuts$($PSStyle.Reset)
688688
$($PSStyle.Foreground.Yellow)=======================$($PSStyle.Reset)
@@ -704,7 +704,7 @@ $($PSStyle.Foreground.Green)ep$($PSStyle.Reset) - Opens the profile for editing.
704704
$($PSStyle.Foreground.Green)export$($PSStyle.Reset) <name> <value> - Sets an environment variable.
705705
$($PSStyle.Foreground.Green)ff$($PSStyle.Reset) <name> - Finds files recursively with the specified name.
706706
$($PSStyle.Foreground.Green)flushdns$($PSStyle.Reset) - Clears the DNS cache.
707-
$($PSStyle.Foreground.Green)Get-PubIP$($PSStyle.Reset) - Retrieves the public IP address of the machine.
707+
$($PSStyle.Foreground.Green)pubip$($PSStyle.Reset) - Retrieves the public IP address of the machine.
708708
$($PSStyle.Foreground.Green)grep$($PSStyle.Reset) <regex> [dir] - Searches for a regex pattern in files within the specified directory or from the pipeline input.
709709
$($PSStyle.Foreground.Green)hb$($PSStyle.Reset) <file> - Uploads the specified file's content to a hastebin-like service and returns the URL.
710710
$($PSStyle.Foreground.Green)head$($PSStyle.Reset) <path> [n] - Displays the first n lines of a file (default 10).
@@ -727,7 +727,6 @@ $($PSStyle.Foreground.Green)sysinfo$($PSStyle.Reset) - Displays detailed system
727727
$($PSStyle.Foreground.Green)flushdns$($PSStyle.Reset) - Clears the DNS cache.
728728
$($PSStyle.Foreground.Green)cpy$($PSStyle.Reset) <text> - Copies the specified text to the clipboard.
729729
$($PSStyle.Foreground.Green)pst$($PSStyle.Reset) - Retrieves text from the clipboard.
730-
$($PSStyle.Foreground.Green)reload-profile$($PSStyle.Reset) - Reloads the current user's PowerShell profile.
731730
$($PSStyle.Foreground.Green)sed$($PSStyle.Reset) <file> <find> <replace> - Replaces text in a file.
732731
$($PSStyle.Foreground.Green)sysinfo$($PSStyle.Reset) - Displays detailed system information.
733732
$($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)