mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-02-02 05:41:10 -08:00
feat(pwsh): download executable from module
This commit is contained in:
parent
9f200a8930
commit
d422325f98
|
@ -30,6 +30,13 @@ Import-Module oh-my-posh
|
||||||
```
|
```
|
||||||
:::
|
:::
|
||||||
|
|
||||||
|
After installation, import Oh My Posh in your `$PROFILE`. Restart your shell and Oh My Posh will start downloading
|
||||||
|
a compatible version of the executable (this is kept in sync on update).
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
Import-Module oh-my-posh
|
||||||
|
```
|
||||||
|
|
||||||
## List all themes
|
## List all themes
|
||||||
|
|
||||||
To display every available theme in the current directory, use the following
|
To display every available theme in the current directory, use the following
|
||||||
|
|
|
@ -18,12 +18,6 @@ Param
|
||||||
(Get-Content '.\oh-my-posh.psd1' -Raw).Replace('0.0.0.1', $ModuleVersion) | Out-File -Encoding 'UTF8' '.\oh-my-posh.psd1'
|
(Get-Content '.\oh-my-posh.psd1' -Raw).Replace('0.0.0.1', $ModuleVersion) | Out-File -Encoding 'UTF8' '.\oh-my-posh.psd1'
|
||||||
# copy all themes into the module folder
|
# copy all themes into the module folder
|
||||||
Copy-Item -Path "../../../themes" -Destination "./themes" -Recurse
|
Copy-Item -Path "../../../themes" -Destination "./themes" -Recurse
|
||||||
# fetch all the binaries from the version's GitHub release
|
|
||||||
New-Item -Path "./" -Name "bin" -ItemType "directory"
|
|
||||||
"posh-windows-amd64.exe", "posh-windows-386.exe", "posh-windows-arm64.exe", "posh-darwin-amd64", "posh-linux-amd64", "posh-linux-arm", "posh-linux-arm64" | ForEach-Object -Process {
|
|
||||||
$download = "https://github.com/jandedobbeleer/oh-my-posh/releases/download/v$BinVersion/$_"
|
|
||||||
Invoke-WebRequest $download -Out "./bin/$_"
|
|
||||||
}
|
|
||||||
# publish the module
|
# publish the module
|
||||||
if ($RepositoryAPIKey) {
|
if ($RepositoryAPIKey) {
|
||||||
Publish-Module -Path . -Repository $Repository -NuGetApiKey $RepositoryAPIKey -Verbose
|
Publish-Module -Path . -Repository $Repository -NuGetApiKey $RepositoryAPIKey -Verbose
|
||||||
|
@ -32,6 +26,4 @@ if ($RepositoryAPIKey) {
|
||||||
}
|
}
|
||||||
# reset module version (for local testing only as we don't want PR's with changed version numbers all the time)
|
# reset module version (for local testing only as we don't want PR's with changed version numbers all the time)
|
||||||
(Get-Content '.\oh-my-posh.psd1' -Raw).Replace($ModuleVersion, '0.0.0.1') | Out-File -Encoding 'UTF8' '.\oh-my-posh.psd1'
|
(Get-Content '.\oh-my-posh.psd1' -Raw).Replace($ModuleVersion, '0.0.0.1') | Out-File -Encoding 'UTF8' '.\oh-my-posh.psd1'
|
||||||
Remove-Item "./bin" -Recurse -Force
|
|
||||||
Remove-Item "./themes" -Recurse -Force
|
Remove-Item "./themes" -Recurse -Force
|
||||||
|
|
||||||
|
|
|
@ -17,48 +17,96 @@ https://ohmyposh.dev/docs/faq#powershell-running-in-constrainedlanguage-mode
|
||||||
$env:POSH_CONSTRAINED_LANGUAGE = 1
|
$env:POSH_CONSTRAINED_LANGUAGE = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
function Get-PoshCommand {
|
function Get-PoshDownloadUrl {
|
||||||
|
param(
|
||||||
|
[Parameter(Mandatory = $true)]
|
||||||
|
[string]
|
||||||
|
$Version
|
||||||
|
)
|
||||||
|
|
||||||
|
$executable = ""
|
||||||
if ($IsMacOS) {
|
if ($IsMacOS) {
|
||||||
return "$PSScriptRoot/bin/posh-darwin-amd64"
|
$executable = "posh-darwin-amd64"
|
||||||
}
|
}
|
||||||
if ($IsLinux) {
|
elseif ($IsLinux) {
|
||||||
# this is rather hacky but there's no other way for the time being
|
# this is rather hacky but there's no other way for the time being
|
||||||
$arch = uname -m
|
$arch = uname -m
|
||||||
if ($arch -eq 'aarch64') {
|
if ($arch -eq 'aarch64') {
|
||||||
return "$PSScriptRoot/bin/posh-linux-arm64"
|
$executable = "posh-linux-arm64"
|
||||||
}
|
}
|
||||||
if ($arch -eq 'armv7l') {
|
elseif ($arch -eq 'armv7l') {
|
||||||
return "$PSScriptRoot/bin/posh-linux-arm"
|
$executable = "posh-linux-arm"
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$executable = "posh-linux-amd64"
|
||||||
}
|
}
|
||||||
return "$PSScriptRoot/bin/posh-linux-amd64"
|
|
||||||
}
|
}
|
||||||
$arch = (Get-CimInstance -Class Win32_Processor -Property Architecture).Architecture
|
else {
|
||||||
switch ($arch) {
|
$arch = (Get-CimInstance -Class Win32_Processor -Property Architecture).Architecture
|
||||||
0 { return "$PSScriptRoot/bin/posh-windows-386.exe" } # x86
|
switch ($arch) {
|
||||||
5 { return "$PSScriptRoot/bin/posh-windows-arm64.exe" } # ARM
|
0 { $executable = "posh-windows-386.exe" } # x86
|
||||||
9 { return "$PSScriptRoot/bin/posh-windows-amd64.exe" } # x64
|
5 { $executable = "posh-windows-arm64.exe" } # ARM
|
||||||
12 { return "$PSScriptRoot/bin/posh-windows-amd64.exe" } # x64 emulated on Surface Pro X
|
9 { $executable = "posh-windows-amd64.exe" } # x64
|
||||||
|
12 { $executable = "posh-windows-amd64.exe" } # x64 emulated on Surface Pro X
|
||||||
|
}
|
||||||
}
|
}
|
||||||
throw "Oh My Posh: Unsupported architecture: $arch"
|
if ($executable -eq "") {
|
||||||
|
throw "oh-my-posh: Unsupported architecture: $arch"
|
||||||
|
}
|
||||||
|
return "https://github.com/jandedobbeleer/oh-my-posh/releases/download/v$Version/$executable"
|
||||||
}
|
}
|
||||||
|
|
||||||
function Set-ExecutablePermissions {
|
function Get-PoshExecutable {
|
||||||
|
param(
|
||||||
|
[Parameter(Mandatory = $true)]
|
||||||
|
[string]
|
||||||
|
$Url,
|
||||||
|
[Parameter(Mandatory = $true)]
|
||||||
|
[string]
|
||||||
|
$Destination
|
||||||
|
)
|
||||||
|
|
||||||
|
Invoke-WebRequest $Url -Out $Destination
|
||||||
|
if (-Not (Test-Path $executable)) {
|
||||||
|
# This should only happen with a corrupt installation
|
||||||
|
throw "Executable at $executable was not found, please try importing oh-my-posh again."
|
||||||
|
}
|
||||||
# Set the right binary to executable before doing anything else
|
# Set the right binary to executable before doing anything else
|
||||||
# Permissions don't need to be set on Windows
|
# Permissions don't need to be set on Windows
|
||||||
if ($PSVersionTable.PSEdition -ne "Core" -or $IsWindows) {
|
if ($PSVersionTable.PSEdition -ne "Core" -or $IsWindows) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
$executable = Get-PoshCommand
|
|
||||||
if (-Not (Test-Path $executable)) {
|
|
||||||
# This should only happen with a corrupt installation
|
|
||||||
Write-Warning "Executable at $executable was not found"
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
chmod a+x $executable 2>&1
|
chmod a+x $executable 2>&1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Get-PoshCommand {
|
||||||
|
$extension = ""
|
||||||
|
if ($PSVersionTable.PSEdition -ne "Core" -or $IsWindows) {
|
||||||
|
$extension = ".exe"
|
||||||
|
}
|
||||||
|
return "$((Get-Item $MyInvocation.MyCommand.ScriptBlock.Module.ModuleBase).Parent)/oh-my-posh$extension"
|
||||||
|
}
|
||||||
|
|
||||||
|
function Sync-PoshExecutable {
|
||||||
|
$executable = Get-PoshCommand
|
||||||
|
$moduleVersion = Split-Path -Leaf $MyInvocation.MyCommand.ScriptBlock.Module.ModuleBase
|
||||||
|
if (-not (Test-Path $executable)) {
|
||||||
|
Write-Host "Downloading oh-my-posh executable"
|
||||||
|
$url = Get-PoshDownloadUrl -Version $moduleVersion
|
||||||
|
Get-PoshExecutable -Url $url -Destination $executable
|
||||||
|
return
|
||||||
|
}
|
||||||
|
$poshVersion = & $executable --version
|
||||||
|
if ($poshVersion -eq $moduleVersion) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
Write-Host "Updating oh-my-posh executable to $moduleVersion"
|
||||||
|
$url = Get-PoshDownloadUrl -Version $moduleVersion
|
||||||
|
Get-PoshExecutable -Url $url -Destination $executable
|
||||||
|
}
|
||||||
|
|
||||||
|
Sync-PoshExecutable
|
||||||
|
|
||||||
function Set-PoshPrompt {
|
function Set-PoshPrompt {
|
||||||
param(
|
param(
|
||||||
[Parameter(Mandatory = $false)]
|
[Parameter(Mandatory = $false)]
|
||||||
|
@ -192,8 +240,6 @@ function ThemeCompletion {
|
||||||
ForEach-Object { New-CompletionResult -CompletionText $_ }
|
ForEach-Object { New-CompletionResult -CompletionText $_ }
|
||||||
}
|
}
|
||||||
|
|
||||||
Set-ExecutablePermissions
|
|
||||||
|
|
||||||
Register-ArgumentCompleter `
|
Register-ArgumentCompleter `
|
||||||
-CommandName Set-PoshPrompt `
|
-CommandName Set-PoshPrompt `
|
||||||
-ParameterName Theme `
|
-ParameterName Theme `
|
||||||
|
|
Loading…
Reference in a new issue