feat: add themes to scoop

This commit is contained in:
Jan De Dobbeleer 2020-11-01 17:22:00 +01:00 committed by Jan De Dobbeleer
parent eea21ac005
commit 0f30953212
4 changed files with 19 additions and 106 deletions

View file

@ -123,7 +123,7 @@ jobs:
run: | run: |
$fileHash = Get-FileHash themes.zip -Algorithm SHA256 $fileHash = Get-FileHash themes.zip -Algorithm SHA256
$fileHash.Hash | Out-File -Encoding 'UTF8' themes.zip.sha256 $fileHash.Hash | Out-File -Encoding 'UTF8' themes.zip.sha256
Write-Output "::set-output name=hash_${{ matrix.os }}::$($fileHash.Hash)" Write-Output "::set-output name=hash_themes::$($fileHash.Hash)"
- name: Upload Themes - name: Upload Themes
id: upload-themes id: upload-themes
uses: actions/upload-release-asset@v1 uses: actions/upload-release-asset@v1
@ -160,7 +160,7 @@ jobs:
- name: Pack and push - name: Pack and push
run: ./deploy.ps1 -BinVersion ${{ needs.release.outputs.version }} -ModuleVersion ${{ needs.release.outputs.version }} -Repository PSGallery -RepositoryAPIKey $env:PSGALLERY_KEY run: ./deploy.ps1 -BinVersion ${{ needs.release.outputs.version }} -ModuleVersion ${{ needs.release.outputs.version }} -Repository PSGallery -RepositoryAPIKey $env:PSGALLERY_KEY
scoop: scoop:
needs: [release, artifacts] needs: [release, artifacts, themes]
if: ${{ needs.release.outputs.skipped == 'false' }} if: ${{ needs.release.outputs.skipped == 'false' }}
runs-on: ubuntu-latest runs-on: ubuntu-latest
defaults: defaults:
@ -171,7 +171,7 @@ jobs:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Update Template - name: Update Template
run: ./build.ps1 -Version ${{ needs.release.outputs.version }} -LinuxSHA ${{ needs.artifacts.outputs.hash_linux }} -WindowsSHA ${{ needs.artifacts.outputs.hash_windows }} run: ./build.ps1 -Version ${{ needs.release.outputs.version }} -LinuxSHA ${{ needs.artifacts.outputs.hash_linux }} -WindowsSHA ${{ needs.artifacts.outputs.hash_windows }} -ThemesSHA ${{ needs.themes.outputs.hash_themes }}
- name: Upload Scoop JSON - name: Upload Scoop JSON
id: upload-scoop-json id: upload-scoop-json
uses: actions/upload-release-asset@v1 uses: actions/upload-release-asset@v1

View file

@ -8,7 +8,10 @@ Param
$LinuxSHA, $LinuxSHA,
[parameter(Mandatory = $true)] [parameter(Mandatory = $true)]
[string] [string]
$WindowsSHA $WindowsSHA,
[parameter(Mandatory = $true)]
[string]
$ThemesSHA
) )
$content = Get-Content '.\oh-my-posh.json' -Raw $content = Get-Content '.\oh-my-posh.json' -Raw
@ -17,4 +20,5 @@ $content = $content.Replace('<HASH_LINUX>', $LinuxSHA)
$content = $content.Replace('<HASH_WINDOWS>', $WindowsSHA) $content = $content.Replace('<HASH_WINDOWS>', $WindowsSHA)
$fileHash = Get-FileHash post-install.ps1 -Algorithm SHA256 $fileHash = Get-FileHash post-install.ps1 -Algorithm SHA256
$content = $content.Replace('<HASH_INSTALL_SCRIPT>', $fileHash.Hash) $content = $content.Replace('<HASH_INSTALL_SCRIPT>', $fileHash.Hash)
$content = $content.Replace('<HASH_THEMES>', $ThemesSHA)
$content | Out-File -Encoding 'UTF8' '.\oh-my-posh.json' $content | Out-File -Encoding 'UTF8' '.\oh-my-posh.json'

View file

@ -9,13 +9,15 @@
"url": [ "url": [
"https://github.com/JanDeDobbeleer/oh-my-posh3/releases/download/v<VERSION>/posh-linux-amd64", "https://github.com/JanDeDobbeleer/oh-my-posh3/releases/download/v<VERSION>/posh-linux-amd64",
"https://github.com/JanDeDobbeleer/oh-my-posh3/releases/download/v<VERSION>/posh-windows-amd64.exe", "https://github.com/JanDeDobbeleer/oh-my-posh3/releases/download/v<VERSION>/posh-windows-amd64.exe",
"https://github.com/JanDeDobbeleer/oh-my-posh3/releases/download/v<VERSION>/post-install.ps1" "https://github.com/JanDeDobbeleer/oh-my-posh3/releases/download/v<VERSION>/post-install.ps1",
"https://github.com/JanDeDobbeleer/oh-my-posh3/releases/download/v<VERSION>/themes.zip"
], ],
"hash": [ "hash": [
"<HASH_LINUX>", "<HASH_LINUX>",
"<HASH_WINDOWS>", "<HASH_WINDOWS>",
"<HASH_INSTALL_SCRIPT>" "<HASH_INSTALL_SCRIPT>",
"<HASH_THEMES>"
], ],
"bin": ["posh-linux-amd64", "posh-windows-amd64.exe"], "extract_to": "themes",
"post_install": "& \"$dir/post-install.ps1\"" "bin": ["posh-linux-amd64", "posh-windows-amd64.exe"]
} }

View file

@ -1,79 +1,4 @@
if (!(Test-Path $PROFILE)) { $logo = @'
$profileDir = Split-Path $PROFILE
if (!(Test-Path $profileDir)) {
New-Item -Path $profileDir -ItemType Directory | Out-Null
}
'' > $PROFILE
}
function Write-ExitIfNeeded {
param (
[parameter(Mandatory = $true)]
[int]
$Decision
)
if ($Decision -ne 0) {
Write-Host 'Thanks for installing Oh my Posh.'
Write-Host 'Have a look at https://ohmyposh.dev/docs/installation for instructions.'
exit 0
}
}
function Set-Prompt {
param (
[parameter(Mandatory = $true)]
[string]
$ProfilePath
)
$promptOverride = @'
function Get-PoshCommand {
$poshCommand = "posh-windows-amd64.exe"
if ($IsLinux) {
$poshCommand = "posh-linux-amd64"
}
return $poshCommand
}
[ScriptBlock]$Prompt = {
$realLASTEXITCODE = $global:LASTEXITCODE
if ($realLASTEXITCODE -isnot [int]) {
$realLASTEXITCODE = 0
}
$startInfo = New-Object System.Diagnostics.ProcessStartInfo
$startInfo.FileName = Get-PoshCommand
$startInfo.Arguments = "-pwd ""$PWD"" -error $realLASTEXITCODE"
$startInfo.Environment["TERM"] = "xterm-256color"
$startInfo.CreateNoWindow = $true
$startInfo.StandardOutputEncoding = [System.Text.Encoding]::UTF8
$startInfo.RedirectStandardOutput = $true
$startInfo.UseShellExecute = $false
if ($PWD.Provider.Name -eq "FileSystem") {
$startInfo.WorkingDirectory = "$PWD"
}
$process = New-Object System.Diagnostics.Process
$process.StartInfo = $startInfo
Set-PoshContext
$process.Start() | Out-Null
$standardOut = $process.StandardOutput.ReadToEnd()
$process.WaitForExit()
$standardOut
$global:LASTEXITCODE = $realLASTEXITCODE
Remove-Variable realLASTEXITCODE -Confirm:$false
}
Set-Item -Path Function:prompt -Value $Prompt -Force
'@
Add-Content -Path $ProfilePath -Value $promptOverride
Write-Host 'Thanks for installing Oh my Posh.'
Write-Host 'Have a look at the configuration posibilities at https://ohmyposh.dev'
}
if (-not (Test-Path $PROFILE)) {
Write-Host "The Powershell profile can't be found, have a look at https://ohmyposh.dev/docs/installation for instructions"
exit 0
}
$title = @'
__ _____ _ ___ ___ ______ _ __ __ _____ _ ___ ___ ______ _ __
/ / | _ | | | \/ | | ___ \ | | \ \ / / | _ | | | \/ | | ___ \ | | \ \
/ / | | | | |__ | . . |_ _ | |_/ /__ ___| |__ \ \ / / | | | | |__ | . . |_ _ | |_/ /__ ___| |__ \ \
@ -83,25 +8,7 @@ $title = @'
__/ | __/ |
|___/ |___/
'@ '@
$choices = '&Yes', '&No' Write-Host $logo
$question = "Do you want to add Oh my Posh to $PROFILE ?" Write-Host ''
$decision = $Host.UI.PromptForChoice($title, $question, $choices, 1) Write-Host 'Thanks for installing Oh my Posh.'
Write-ExitIfNeeded -Decision $decision Write-Host 'Have a look at https://ohmyposh.dev/docs/installation for detailed instructions for your shell.'
if (!(Get-Content $PROFILE)) {
Set-Prompt -ProfilePath $PROFILE
exit 0
}
$profileContent = (Get-Content $PROFILE).ToLower()
if ($profileContent -match 'function:prompt' -or $profileContent -match 'function prompt') {
$title = "$ProfilePath already contains a prompt function override."
$question = "Do you want to override it with Oh my Posh?"
$decision = $Host.UI.PromptForChoice($title, $question, $choices, 1)
Write-ExitIfNeeded -Decision $decision
}
elseif ($profileContent -match 'oh-my-posh') {
$title = "$ProfilePath already contains an Oh my Posh import statement."
$question = "Do you want to override it?"
$decision = $Host.UI.PromptForChoice($title, $question, $choices, 1)
Write-ExitIfNeeded -Decision $decision
}
Set-Prompt -ProfilePath $PROFILE