fix(pwsh): store the executable inside user HOME folder

This commit is contained in:
Jan De Dobbeleer 2022-01-14 22:01:16 +01:00 committed by Jan De Dobbeleer
parent 2ea2e633b8
commit 37e96ef968

View file

@ -1,17 +1,11 @@
$env:POSH_PATH = "$((Get-Item $MyInvocation.MyCommand.ScriptBlock.Module.ModuleBase).Parent.FullName)" function Set-PoshRootPath {
$env:POSH_THEMES_PATH = $env:POSH_PATH + "/themes" $child = ".oh-my-posh"
$env:PATH = $env:POSH_PATH + [System.IO.Path]::PathSeparator + $env:PATH $path = Join-Path -Path $HOME -ChildPath $child
$env:POSH_PATH = $path
if ($ExecutionContext.SessionState.LanguageMode -ne "ConstrainedLanguage") { if (Test-Path -Path $path) {
[console]::InputEncoding = [console]::OutputEncoding = New-Object System.Text.UTF8Encoding return
} }
else { New-Item -Path $HOME -Name $child -ItemType "directory"
Write-Host "[WARNING] ConstrainedLanguage mode detected, unable to set console to UTF-8.
When using PowerShell in ConstrainedLanguage mode, please set the
console mode manually to UTF-8. See here for more information:
https://ohmyposh.dev/docs/faq#powershell-running-in-constrainedlanguage-mode
"
$env:POSH_CONSTRAINED_LANGUAGE_MODE = $true
} }
function Get-PoshDownloadUrl { function Get-PoshDownloadUrl {
@ -77,11 +71,10 @@ function Get-PoshExecutable {
} }
function Get-PoshCommand { function Get-PoshCommand {
$extension = ""
if ($PSVersionTable.PSEdition -ne "Core" -or $IsWindows) { if ($PSVersionTable.PSEdition -ne "Core" -or $IsWindows) {
$extension = ".exe" return Join-Path -Path $env:POSH_PATH -ChildPath "oh-my-posh.exe"
} }
return "$((Get-Item $MyInvocation.MyCommand.ScriptBlock.Module.ModuleBase).Parent.FullName)/oh-my-posh$extension" return Join-Path -Path $env:POSH_PATH -ChildPath "oh-my-posh"
} }
function Sync-PoshThemes { function Sync-PoshThemes {
@ -125,25 +118,11 @@ function Sync-PoshArtifacts {
Sync-PoshThemes -Version $Version Sync-PoshThemes -Version $Version
} }
try { Set-PoshRootPath
$moduleVersion = Split-Path -Leaf $MyInvocation.MyCommand.ScriptBlock.Module.ModuleBase $env:PATH = $env:POSH_PATH + [System.IO.Path]::PathSeparator + $env:PATH
Sync-PoshArtifacts -Version $moduleVersion $env:POSH_THEMES_PATH = Join-Path -Path $env:POSH_PATH -ChildPath "themes"
} $moduleVersion = Split-Path -Leaf $MyInvocation.MyCommand.ScriptBlock.Module.ModuleBase
catch { Sync-PoshArtifacts -Version $moduleVersion
$message = @'
Oh My Posh is unable to download and store the latest version.
In case you installed using AllUsers and are a non-admin user,
please run the following command as an administrator:
Import-Module oh-my-posh
Original Error:
'@
Write-Host $message
Write-Host $_
exit 1
}
# Legacy functions # Legacy functions