mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-03-05 20:49:04 -08:00
feat(pkg): add PowerShell package
This commit is contained in:
parent
c4d1c75781
commit
f3582d229e
26
.github/workflows/release.yml
vendored
26
.github/workflows/release.yml
vendored
|
@ -13,17 +13,10 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
outputs:
|
outputs:
|
||||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||||
|
version: ${{ steps.changelog.outputs.version }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
- name: Get next version
|
|
||||||
id: version
|
|
||||||
run: |
|
|
||||||
curl -L https://github.com/idc101/git-mkver/releases/download/v$MKVER/git-mkver-darwin-amd64-$MKVER.tar.gz | tar xvz
|
|
||||||
sudo mv git-mkver /usr/local/bin
|
|
||||||
echo "::set-output name=version::$(git mkver next)"
|
|
||||||
env:
|
|
||||||
MKVER: "1.1.1"
|
|
||||||
- name: Create changelog
|
- name: Create changelog
|
||||||
id: changelog
|
id: changelog
|
||||||
uses: TriPSs/conventional-changelog-action@v3
|
uses: TriPSs/conventional-changelog-action@v3
|
||||||
|
@ -32,7 +25,6 @@ jobs:
|
||||||
skip-version-file: "true"
|
skip-version-file: "true"
|
||||||
output-file: "false"
|
output-file: "false"
|
||||||
skip-commit: "true"
|
skip-commit: "true"
|
||||||
fallback-version: ${{ steps.version.outputs.version }}
|
|
||||||
- name: Create Github Release
|
- name: Create Github Release
|
||||||
id: create_release
|
id: create_release
|
||||||
uses: actions/create-release@v1
|
uses: actions/create-release@v1
|
||||||
|
@ -93,3 +85,19 @@ jobs:
|
||||||
asset_path: ./src/github.com/${{ github.repository }}/${{ matrix.ARTIFACT }}
|
asset_path: ./src/github.com/${{ github.repository }}/${{ matrix.ARTIFACT }}
|
||||||
asset_name: ${{ matrix.ARTIFACT }}
|
asset_name: ${{ matrix.ARTIFACT }}
|
||||||
asset_content_type: application/octet-stream
|
asset_content_type: application/octet-stream
|
||||||
|
powershell:
|
||||||
|
needs: [release, artifacts]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
shell: pwsh
|
||||||
|
working-directory: ${{ github.workspace }}/src/github.com/${{ github.repository }}/packages/powershell/go-my-posh
|
||||||
|
env:
|
||||||
|
PSGALLERY_KEY: ${{ secrets.PSGALLERY_KEY }}
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
path: ./src/github.com/${{ github.repository }}
|
||||||
|
- name: Pack and push
|
||||||
|
run: ./deploy.ps1 -BinVersion ${{ needs.release.outputs.version }} -ModuleVersion ${{ needs.release.outputs.version }} -Repository PSGallery -RepositoryAPIKey $env:PSGALLERY_KEY
|
||||||
|
|
39
.vscode/launch.json
vendored
39
.vscode/launch.json
vendored
|
@ -1,18 +1,25 @@
|
||||||
{
|
{
|
||||||
// Use IntelliSense to learn about possible attributes.
|
// Use IntelliSense to learn about possible attributes.
|
||||||
// Hover to view descriptions of existing attributes.
|
// Hover to view descriptions of existing attributes.
|
||||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": "Launch",
|
"name": "PowerShell Launch Current File",
|
||||||
"type": "go",
|
"type": "PowerShell",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"mode": "auto",
|
"script": "${file}",
|
||||||
"program": "${workspaceFolder}/main.go",
|
"cwd": "${file}"
|
||||||
"cwd": "${workspaceFolder}",
|
},
|
||||||
"env": {},
|
{
|
||||||
"args": []
|
"name": "Launch",
|
||||||
}
|
"type": "go",
|
||||||
]
|
"request": "launch",
|
||||||
|
"mode": "auto",
|
||||||
|
"program": "${workspaceFolder}/main.go",
|
||||||
|
"cwd": "${workspaceFolder}",
|
||||||
|
"env": {},
|
||||||
|
"args": []
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
30
packages/powershell/go-my-posh/README.md
Normal file
30
packages/powershell/go-my-posh/README.md
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
# PowerShell package
|
||||||
|
|
||||||
|
The goal of this module is to wrap the `go-my-posh` binaries into a PowerShell module and allow easy installation
|
||||||
|
and ease of use when setting the prompt.
|
||||||
|
|
||||||
|
## Testing
|
||||||
|
|
||||||
|
## Create local package repository to validate changes locally
|
||||||
|
|
||||||
|
### Create the repository
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
Register-PSRepository -Name 'LocalRepo' -SourceLocation 'C:\Repo' -PublishLocation 'C:\Repo' -InstallationPolicy Trusted
|
||||||
|
```
|
||||||
|
|
||||||
|
## Make changes and publish to your local repository
|
||||||
|
|
||||||
|
For ease testing, up the version number when using the build script, that way you are always able to update the module.
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
deploy.ps1 -BinVersion 0.1.0 -ModuleVersion 0.0.2 -Repository LocalRepo
|
||||||
|
```
|
||||||
|
|
||||||
|
## Validate changes
|
||||||
|
|
||||||
|
Install/Update the module from your local repository and validate the changes.
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
Install-Module go-my-posh -Repository LocalRepo -Force
|
||||||
|
```
|
37
packages/powershell/go-my-posh/deploy.ps1
Normal file
37
packages/powershell/go-my-posh/deploy.ps1
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
Param
|
||||||
|
(
|
||||||
|
[parameter(Mandatory=$true)]
|
||||||
|
[string]
|
||||||
|
$BinVersion,
|
||||||
|
[parameter(Mandatory=$true)]
|
||||||
|
[string]
|
||||||
|
$ModuleVersion,
|
||||||
|
[parameter(Mandatory=$true)]
|
||||||
|
[string]
|
||||||
|
$Repository,
|
||||||
|
[parameter(Mandatory=$false)]
|
||||||
|
[string]
|
||||||
|
$RepositoryAPIKey
|
||||||
|
)
|
||||||
|
|
||||||
|
# set the actual version number
|
||||||
|
(Get-Content '.\go-my-posh.psd1' -Raw).Replace('0.0.0.1', $ModuleVersion) | Out-File -Encoding 'UTF8' '.\go-my-posh.psd1'
|
||||||
|
# copy all themes into the module folder
|
||||||
|
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-darwin-amd64", "posh-linux-amd64" | ForEach-Object -Process {
|
||||||
|
$download = "https://github.com/jandedobbeleer/go-my-posh/releases/download/v$BinVersion/$_"
|
||||||
|
Invoke-WebRequest $download -Out "./bin/$_"
|
||||||
|
}
|
||||||
|
# publish the module
|
||||||
|
if ($RepositoryAPIKey) {
|
||||||
|
Publish-Module -Path . -Repository $Repository -NuGetApiKey $RepositoryAPIKey -Verbose
|
||||||
|
} else {
|
||||||
|
Publish-Module -Path . -Repository $Repository -Verbose
|
||||||
|
}
|
||||||
|
# reset module version (for local testing only as we don't want PR's with changed version numbers all the time)
|
||||||
|
(Get-Content '.\go-my-posh.psd1' -Raw).Replace($ModuleVersion, '0.0.0.1') | Out-File -Encoding 'UTF8' '.\go-my-posh.psd1'
|
||||||
|
Remove-Item "./bin" -Recurse -Force
|
||||||
|
Remove-Item "./Themes" -Recurse -Force
|
||||||
|
|
109
packages/powershell/go-my-posh/go-my-posh.psd1
Normal file
109
packages/powershell/go-my-posh/go-my-posh.psd1
Normal file
|
@ -0,0 +1,109 @@
|
||||||
|
#
|
||||||
|
# Module manifest for module 'go-my-posh'
|
||||||
|
#
|
||||||
|
# Generated by: Jan De Dobbeleer
|
||||||
|
#
|
||||||
|
# Generated on: 11-Sep-20
|
||||||
|
#
|
||||||
|
@{
|
||||||
|
# Version number of this module.
|
||||||
|
ModuleVersion = '0.0.0.1'
|
||||||
|
# Script module or binary module file associated with this manifest.
|
||||||
|
RootModule = 'go-my-posh.psm1'
|
||||||
|
# ID used to uniquely identify this module
|
||||||
|
GUID = '60288db4-a58e-4c79-b50d-dba631950ecc'
|
||||||
|
# Company or vendor of this module
|
||||||
|
CompanyName = 'IT Depends'
|
||||||
|
# Author of this module
|
||||||
|
Author = 'Jan De Dobbeleer'
|
||||||
|
# Copyright statement for this module
|
||||||
|
Copyright = '(c) 2020 Jan De Dobbeleer. All rights reserved.'
|
||||||
|
# Description of the functionality provided by this module
|
||||||
|
Description = 'A prompt theme engine for any shell'
|
||||||
|
# Minimum version of the Windows PowerShell engine required by this module
|
||||||
|
PowerShellVersion = '6.0'
|
||||||
|
# List of all files packaged with this module
|
||||||
|
FileList = @()
|
||||||
|
# Cmdlets to export from this module
|
||||||
|
CmdletsToExport = @()
|
||||||
|
# Variables to export from this module
|
||||||
|
VariablesToExport = @()
|
||||||
|
# Aliases to export from this module
|
||||||
|
AliasesToExport = '*'
|
||||||
|
# Functions to export from this module
|
||||||
|
FunctionsToExport = @('Get-PoshThemes', 'Set-PoshPrompt', 'Write-PoshTheme')
|
||||||
|
# Private data to pass to the module specified in RootModule. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
|
||||||
|
PrivateData = @{
|
||||||
|
PSData = @{
|
||||||
|
# Tags applied to this module. These help with module discovery in online galleries.
|
||||||
|
Tags = @('git', 'agnoster', 'theme', 'zsh', 'posh-git', 'prompt', 'paradox', 'robbyrussel', 'oh-my-posh')
|
||||||
|
# A URL to the license for this module.
|
||||||
|
LicenseUri = 'https://github.com/JanDeDobbeleer/go-my-posh/blob/master/COPYING'
|
||||||
|
# A URL to the main website for this project.
|
||||||
|
ProjectUri = 'https://github.com/JanDeDobbeleer/go-my-posh'
|
||||||
|
} # End of PSData hashtable
|
||||||
|
} # End of PrivateData hashtable
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
120
packages/powershell/go-my-posh/go-my-posh.psm1
Normal file
120
packages/powershell/go-my-posh/go-my-posh.psm1
Normal file
|
@ -0,0 +1,120 @@
|
||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
Generates the prompt before each line in the console
|
||||||
|
#>
|
||||||
|
|
||||||
|
$global:PoshSettings = New-Object -TypeName PSObject -Property @{
|
||||||
|
Theme = "$PSScriptRoot\Themes\jandedobbeleer.json"
|
||||||
|
}
|
||||||
|
|
||||||
|
function Get-PoshCommand {
|
||||||
|
$poshCommand = "$PSScriptRoot/bin/posh-windows-amd64.exe"
|
||||||
|
if ($IsMacOS) {
|
||||||
|
$poshCommand = "$PSScriptRoot/bin/posh-darwin-amd64"
|
||||||
|
}
|
||||||
|
if ($IsLinux) {
|
||||||
|
$poshCommand = "$PSScriptRoot/bin/posh-linux-amd64"
|
||||||
|
}
|
||||||
|
return $poshCommand
|
||||||
|
}
|
||||||
|
|
||||||
|
# Set the right binary to executable before doing anything else
|
||||||
|
if (!$IsWindows) {
|
||||||
|
$executable = Get-PoshCommand
|
||||||
|
Invoke-Expression -Command "chmod +x $executable"
|
||||||
|
}
|
||||||
|
|
||||||
|
function Set-PoshPrompt {
|
||||||
|
param(
|
||||||
|
[Parameter(Mandatory = $true)]
|
||||||
|
[string]
|
||||||
|
$Theme
|
||||||
|
)
|
||||||
|
|
||||||
|
$themePath = ""
|
||||||
|
if (Test-Path "$PSScriptRoot/Themes/$Theme.json") {
|
||||||
|
$themePath = "$PSScriptRoot/Themes/$Theme.json"
|
||||||
|
}
|
||||||
|
elseif (Test-Path $Theme) {
|
||||||
|
$themePath = $Theme
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Write-Error -Message "Unable to locate theme, please verify the name and/or location"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
$global:PoshSettings.Theme = $themePath
|
||||||
|
|
||||||
|
[ScriptBlock]$Prompt = {
|
||||||
|
$realLASTEXITCODE = $global:LASTEXITCODE
|
||||||
|
$poshCommand = Get-PoshCommand
|
||||||
|
$config = $global:PoshSettings.Theme
|
||||||
|
Invoke-Expression -Command "$poshCommand -config $config -error $realLASTEXITCODE"
|
||||||
|
$global:LASTEXITCODE = $realLASTEXITCODE
|
||||||
|
Remove-Variable realLASTEXITCODE -Confirm:$false
|
||||||
|
}
|
||||||
|
Set-Item -Path Function:prompt -Value $Prompt -Force
|
||||||
|
}
|
||||||
|
|
||||||
|
function Get-PoshThemes {
|
||||||
|
$esc = [char]27
|
||||||
|
$consoleWidth = $Host.UI.RawUI.WindowSize.Width
|
||||||
|
$logo = @'
|
||||||
|
__ _ __
|
||||||
|
/ / | | \ \
|
||||||
|
/ / __ _ ___ _ __ ___ _ _ _ __ ___ ___| |__ \ \
|
||||||
|
< < / _` |/ _ \ | '_ ` _ \| | | | | '_ \ / _ \/ __| '_ \ > >
|
||||||
|
\ \ | (_| | (_) | | | | | | | |_| | | |_) | (_) \__ \ | | | / /
|
||||||
|
\_\ \__, |\___/ |_| |_| |_|\__, | | .__/ \___/|___/_| |_| /_/
|
||||||
|
__/ | __/ | | |
|
||||||
|
|___/ |___/ |_|
|
||||||
|
|
||||||
|
'@
|
||||||
|
Write-Host $logo
|
||||||
|
$poshCommand = Get-PoshCommand
|
||||||
|
Get-ChildItem -Path "$PSScriptRoot\Themes\*" -Include '*.json' | Sort-Object Name | ForEach-Object -Process {
|
||||||
|
Write-Host ("=" * $consoleWidth)
|
||||||
|
Write-Host "$esc[1m$($_.BaseName)$esc[0m"
|
||||||
|
Write-Host ""
|
||||||
|
Invoke-Expression -Command "$poshCommand -config $($_.FullName)"
|
||||||
|
Write-Host ""
|
||||||
|
}
|
||||||
|
Write-Host ("=" * $consoleWidth)
|
||||||
|
}
|
||||||
|
|
||||||
|
function Write-PoshTheme {
|
||||||
|
$poshCommand = Get-PoshCommand
|
||||||
|
Invoke-Expression -Command "$poshCommand -print-config"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Helper function to create argument completion results
|
||||||
|
function New-CompletionResult {
|
||||||
|
param(
|
||||||
|
[Parameter(Mandatory)]
|
||||||
|
[string]$CompletionText,
|
||||||
|
[string]$ListItemText = $CompletionText,
|
||||||
|
[System.Management.Automation.CompletionResultType]$CompletionResultType = [System.Management.Automation.CompletionResultType]::ParameterValue,
|
||||||
|
[string]$ToolTip = $CompletionText
|
||||||
|
)
|
||||||
|
|
||||||
|
New-Object System.Management.Automation.CompletionResult $CompletionText, $ListItemText, $CompletionResultType, $ToolTip
|
||||||
|
}
|
||||||
|
|
||||||
|
function ThemeCompletion {
|
||||||
|
param(
|
||||||
|
$commandName,
|
||||||
|
$parameterName,
|
||||||
|
$wordToComplete,
|
||||||
|
$commandAst,
|
||||||
|
$fakeBoundParameter
|
||||||
|
)
|
||||||
|
$themes = Get-ChildItem -Path "$PSScriptRoot\Themes\*" -Include '*.json' | Sort-Object Name | Select-Object -Property BaseName
|
||||||
|
$themes |
|
||||||
|
Where-Object { $_.BaseName.ToLower().StartsWith($wordToComplete.ToLower()); } |
|
||||||
|
Select-Object -Unique -ExpandProperty BaseName |
|
||||||
|
ForEach-Object { New-CompletionResult -CompletionText $_ }
|
||||||
|
}
|
||||||
|
|
||||||
|
Register-ArgumentCompleter `
|
||||||
|
-CommandName Set-PoshPrompt `
|
||||||
|
-ParameterName Theme `
|
||||||
|
-ScriptBlock $function:ThemeCompletion
|
Loading…
Reference in a new issue