Skip to content

Commit

Permalink
feat: add themes to scoop
Browse files Browse the repository at this point in the history
  • Loading branch information
JanDeDobbeleer committed Nov 1, 2020
1 parent eea21ac commit 0f30953
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 106 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Expand Up @@ -123,7 +123,7 @@ jobs:
run: |
$fileHash = Get-FileHash themes.zip -Algorithm 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
id: upload-themes
uses: actions/upload-release-asset@v1
Expand Down Expand Up @@ -160,7 +160,7 @@ jobs:
- name: Pack and push
run: ./deploy.ps1 -BinVersion ${{ needs.release.outputs.version }} -ModuleVersion ${{ needs.release.outputs.version }} -Repository PSGallery -RepositoryAPIKey $env:PSGALLERY_KEY
scoop:
needs: [release, artifacts]
needs: [release, artifacts, themes]
if: ${{ needs.release.outputs.skipped == 'false' }}
runs-on: ubuntu-latest
defaults:
Expand All @@ -171,7 +171,7 @@ jobs:
- name: Checkout code
uses: actions/checkout@v2
- 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
id: upload-scoop-json
uses: actions/upload-release-asset@v1
Expand Down
6 changes: 5 additions & 1 deletion packages/scoop/build.ps1
Expand Up @@ -8,7 +8,10 @@ Param
$LinuxSHA,
[parameter(Mandatory = $true)]
[string]
$WindowsSHA
$WindowsSHA,
[parameter(Mandatory = $true)]
[string]
$ThemesSHA
)

$content = Get-Content '.\oh-my-posh.json' -Raw
Expand All @@ -17,4 +20,5 @@ $content = $content.Replace('<HASH_LINUX>', $LinuxSHA)
$content = $content.Replace('<HASH_WINDOWS>', $WindowsSHA)
$fileHash = Get-FileHash post-install.ps1 -Algorithm SHA256
$content = $content.Replace('<HASH_INSTALL_SCRIPT>', $fileHash.Hash)
$content = $content.Replace('<HASH_THEMES>', $ThemesSHA)
$content | Out-File -Encoding 'UTF8' '.\oh-my-posh.json'
10 changes: 6 additions & 4 deletions packages/scoop/oh-my-posh.json
Expand Up @@ -9,13 +9,15 @@
"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-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_LINUX>",
"<HASH_WINDOWS>",
"<HASH_INSTALL_SCRIPT>"
"<HASH_INSTALL_SCRIPT>",
"<HASH_THEMES>"
],
"bin": ["posh-linux-amd64", "posh-windows-amd64.exe"],
"post_install": "& \"$dir/post-install.ps1\""
"extract_to": "themes",
"bin": ["posh-linux-amd64", "posh-windows-amd64.exe"]
}
103 changes: 5 additions & 98 deletions packages/scoop/post-install.ps1
@@ -1,79 +1,4 @@
if (!(Test-Path $PROFILE)) {
$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 = @'
$logo = @'
__ _____ _ ___ ___ ______ _ __
/ / | _ | | | \/ | | ___ \ | | \ \
/ / | | | | |__ | . . |_ _ | |_/ /__ ___| |__ \ \
Expand All @@ -83,25 +8,7 @@ $title = @'
__/ |
|___/
'@
$choices = '&Yes', '&No'
$question = "Do you want to add Oh my Posh to $PROFILE ?"
$decision = $Host.UI.PromptForChoice($title, $question, $choices, 1)
Write-ExitIfNeeded -Decision $decision
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
Write-Host $logo
Write-Host ''
Write-Host 'Thanks for installing Oh my Posh.'
Write-Host 'Have a look at https://ohmyposh.dev/docs/installation for detailed instructions for your shell.'

0 comments on commit 0f30953

Please sign in to comment.