Skip to content

Commit

Permalink
Make extensions more cross-platform-friendly
Browse files Browse the repository at this point in the history
If there exists a command `ls` in your PATH, then `ls` in PowerShell
doesn't seem to be expanded to `Get-ChildItem`. This breaks certain
extensions. This commit expands the `ls` alias in extensions to avoid
this issue.
  • Loading branch information
egerlach committed Jan 8, 2023
1 parent 8ae6c01 commit 37db862
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function Get-AppInstallLocation {
$dirs = $Env:ProgramFiles, "$Env:ProgramFiles\*\*"
if (Get-ProcessorBits 64) { $dirs += ${ENV:ProgramFiles(x86)}, "${ENV:ProgramFiles(x86)}\*\*" }
Write-Verbose "Trying Program Files with 2 levels depth: $dirs"
$location = (ls $dirs | ? {$_.PsIsContainer}) -match $AppNamePattern | select -First 1 | % {$_.FullName}
$location = (Get-ChildItem $dirs | ? {$_.PsIsContainer}) -match $AppNamePattern | select -First 1 | % {$_.FullName}
if (is_dir $location) { return strip $location }

Write-Verbose "Trying native commands on PATH"
Expand All @@ -69,7 +69,7 @@ function Get-AppInstallLocation {

$appPaths = "\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths"
Write-Verbose "Trying Registry: $appPaths"
$location = (ls "HKCU:\$appPaths", "HKLM:\$appPaths") -match $AppNamePattern | select -First 1
$location = (Get-ChildItem "HKCU:\$appPaths", "HKLM:\$appPaths") -match $AppNamePattern | select -First 1
if ($location) { $location = Split-Path $location }
if (is_dir $location) { return strip $location }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# Include file names that start with capital letters, ignore others
$ScriptRoot = Split-Path $MyInvocation.MyCommand.Definition

$pre = ls Function:\*
ls "$ScriptRoot\*.ps1" | ? { $_.Name -cmatch '^[A-Z]+' } | % { . $_ }
$post = ls Function:\*
$pre = Get-ChildItem Function:\*
Get-ChildItem "$ScriptRoot\*.ps1" | ? { $_.Name -cmatch '^[A-Z]+' } | % { . $_ }
$post = Get-ChildItem Function:\*
$funcs = compare $pre $post | select -Expand InputObject | select -Expand Name
$funcs | ? { $_ -cmatch '^[A-Z]+'} | % { Export-ModuleMember -Function $_ }

Expand Down

0 comments on commit 37db862

Please sign in to comment.