mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-01-12 03:37:31 -08:00
refactor(tooltips): better invocation for pwsh
This commit is contained in:
parent
e16e6e34b7
commit
7bb0c9ae0b
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
|
@ -15,7 +15,7 @@
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"mode": "debug",
|
"mode": "debug",
|
||||||
"program": "${workspaceRoot}/src",
|
"program": "${workspaceRoot}/src",
|
||||||
"args": ["--config=/Users/jan/.jandedobbeleer.omp.json", "--tooltip=git"]
|
"args": ["--config=${workspaceRoot}/themes/jandedobbeleer.omp.json", "--command=git", "--shell=pwsh"]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Launch tests",
|
"name": "Launch tests",
|
||||||
|
|
|
@ -66,10 +66,10 @@ are being explored.
|
||||||
}>
|
}>
|
||||||
<TabItem value="pwsh">
|
<TabItem value="pwsh">
|
||||||
|
|
||||||
Import/invoke Oh My Posh in your `$PROFILE` and add the following setting:
|
Import/invoke Oh My Posh in your `$PROFILE` and add the following line below:
|
||||||
|
|
||||||
```pwsh
|
```pwsh
|
||||||
$Global:PoshSettings.EnableToolTips = $true
|
Enable-PoshTooltips
|
||||||
```
|
```
|
||||||
|
|
||||||
Restart your shell or reload your `$PROFILE` using `. $PROFILE` for the changes to take effect.
|
Restart your shell or reload your `$PROFILE` using `. $PROFILE` for the changes to take effect.
|
||||||
|
@ -77,7 +77,7 @@ Restart your shell or reload your `$PROFILE` using `. $PROFILE` for the changes
|
||||||
</TabItem>
|
</TabItem>
|
||||||
<TabItem value="zsh">
|
<TabItem value="zsh">
|
||||||
|
|
||||||
Invoke Oh My Posh in `.zshrc` and add the following setting:
|
Invoke Oh My Posh in `.zshrc` and add the following line below:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
enable_poshtooltips
|
enable_poshtooltips
|
||||||
|
|
|
@ -22,8 +22,7 @@ Set-DefaultEnvValue("AZ_ENABLED")
|
||||||
Set-DefaultEnvValue("POSH_GIT_ENABLED")
|
Set-DefaultEnvValue("POSH_GIT_ENABLED")
|
||||||
|
|
||||||
$global:PoshSettings = New-Object -TypeName PSObject -Property @{
|
$global:PoshSettings = New-Object -TypeName PSObject -Property @{
|
||||||
Theme = "";
|
Theme = "";
|
||||||
EnableToolTips = $false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# used to detect empty hit
|
# used to detect empty hit
|
||||||
|
@ -36,6 +35,13 @@ if (Test-Path $config) {
|
||||||
|
|
||||||
function global:Set-PoshContext {}
|
function global:Set-PoshContext {}
|
||||||
|
|
||||||
|
function global:Get-PoshContext {
|
||||||
|
$config = $global:PoshSettings.Theme
|
||||||
|
$cleanPWD = $PWD.ProviderPath.TrimEnd("\")
|
||||||
|
$cleanPSWD = $PWD.ToString().TrimEnd("\")
|
||||||
|
return $config, $cleanPWD, $cleanPSWD
|
||||||
|
}
|
||||||
|
|
||||||
function global:Initialize-ModuleSupport {
|
function global:Initialize-ModuleSupport {
|
||||||
if ($env:POSH_GIT_ENABLED -eq $true -and (Get-Module -Name "posh-git")) {
|
if ($env:POSH_GIT_ENABLED -eq $true -and (Get-Module -Name "posh-git")) {
|
||||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSProvideCommentHelp', '', Justification = 'Variable used later(not in this scope)')]
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSProvideCommentHelp', '', Justification = 'Variable used later(not in this scope)')]
|
||||||
|
@ -57,24 +63,6 @@ function global:Initialize-ModuleSupport {
|
||||||
}
|
}
|
||||||
catch {}
|
catch {}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Set the keyhandler to enable tooltips
|
|
||||||
if ($global:PoshSettings.EnableToolTips -eq $true) {
|
|
||||||
Set-PSReadlineKeyHandler -Key SpaceBar -ScriptBlock {
|
|
||||||
[Microsoft.PowerShell.PSConsoleReadLine]::Insert(' ')
|
|
||||||
$position = $host.UI.RawUI.CursorPosition
|
|
||||||
$omp = "::OMP::"
|
|
||||||
$config = $global:PoshSettings.Theme
|
|
||||||
$cleanPWD = $PWD.ProviderPath.TrimEnd("\")
|
|
||||||
$cleanPSWD = $PWD.ToString().TrimEnd("\")
|
|
||||||
$tooltip = $null
|
|
||||||
$cursor = $null
|
|
||||||
[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$tooltip, [ref]$cursor)
|
|
||||||
$standardOut = @(&$omp --pwd="$cleanPWD" --pswd="$cleanPSWD" --config="$config" --tooltip="$tooltip" 2>&1)
|
|
||||||
Write-Host $standardOut -NoNewline
|
|
||||||
$host.UI.RawUI.CursorPosition = $position
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[ScriptBlock]$Prompt = {
|
[ScriptBlock]$Prompt = {
|
||||||
|
@ -111,9 +99,7 @@ function global:Initialize-ModuleSupport {
|
||||||
$global:omp_lastHistoryId = $history.Id
|
$global:omp_lastHistoryId = $history.Id
|
||||||
}
|
}
|
||||||
$omp = "::OMP::"
|
$omp = "::OMP::"
|
||||||
$config = $global:PoshSettings.Theme
|
$config, $cleanPWD, $cleanPSWD = Get-PoshContext
|
||||||
$cleanPWD = $PWD.ProviderPath.TrimEnd("\")
|
|
||||||
$cleanPSWD = $PWD.ToString().TrimEnd("\")
|
|
||||||
$standardOut = @(&$omp --error="$errorCode" --pwd="$cleanPWD" --pswd="$cleanPSWD" --execution-time="$executionTime" --stack-count="$stackCount" --config="$config" 2>&1)
|
$standardOut = @(&$omp --error="$errorCode" --pwd="$cleanPWD" --pswd="$cleanPSWD" --execution-time="$executionTime" --stack-count="$stackCount" --config="$config" 2>&1)
|
||||||
# the output can be multiline, joining these ensures proper rendering by adding line breaks with `n
|
# the output can be multiline, joining these ensures proper rendering by adding line breaks with `n
|
||||||
$standardOut -join "`n"
|
$standardOut -join "`n"
|
||||||
|
@ -126,9 +112,7 @@ Set-Item -Path Function:prompt -Value $Prompt -Force
|
||||||
|
|
||||||
function global:Write-PoshDebug {
|
function global:Write-PoshDebug {
|
||||||
$omp = "::OMP::"
|
$omp = "::OMP::"
|
||||||
$config = $global:PoshSettings.Theme
|
$config, $cleanPWD, $cleanPSWD = Get-PoshContext
|
||||||
$cleanPWD = $PWD.ProviderPath.TrimEnd("\")
|
|
||||||
$cleanPSWD = $PWD.ToString().TrimEnd("\")
|
|
||||||
$standardOut = @(&$omp --error=1337 --pwd="$cleanPWD" --pswd="$cleanPSWD" --execution-time=9001 --config="$config" --debug 2>&1)
|
$standardOut = @(&$omp --error=1337 --pwd="$cleanPWD" --pswd="$cleanPSWD" --execution-time=9001 --config="$config" --debug 2>&1)
|
||||||
$standardOut -join "`n"
|
$standardOut -join "`n"
|
||||||
}
|
}
|
||||||
|
@ -197,9 +181,22 @@ function global:Export-PoshImage {
|
||||||
}
|
}
|
||||||
|
|
||||||
$omp = "::OMP::"
|
$omp = "::OMP::"
|
||||||
$config = $global:PoshSettings.Theme
|
$config, $cleanPWD, $cleanPSWD = Get-PoshContext
|
||||||
$cleanPWD = $PWD.ProviderPath.TrimEnd("\")
|
|
||||||
$cleanPSWD = $PWD.ToString().TrimEnd("\")
|
|
||||||
$standardOut = @(&$omp --config="$config" --pwd="$cleanPWD" --pswd="$cleanPSWD" --export-png --rprompt-offset="$RPromptOffset" --cursor-padding="$CursorPadding" $Author 2>&1)
|
$standardOut = @(&$omp --config="$config" --pwd="$cleanPWD" --pswd="$cleanPSWD" --export-png --rprompt-offset="$RPromptOffset" --cursor-padding="$CursorPadding" $Author 2>&1)
|
||||||
$standardOut -join "`n"
|
$standardOut -join "`n"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function global:Enable-PoshTooltips {
|
||||||
|
Set-PSReadlineKeyHandler -Key SpaceBar -ScriptBlock {
|
||||||
|
[Microsoft.PowerShell.PSConsoleReadLine]::Insert(' ')
|
||||||
|
$position = $host.UI.RawUI.CursorPosition
|
||||||
|
$omp = "::OMP::"
|
||||||
|
$config, $cleanPWD, $cleanPSWD = Get-PoshContext
|
||||||
|
$tooltip = $null
|
||||||
|
$cursor = $null
|
||||||
|
[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$tooltip, [ref]$cursor)
|
||||||
|
$standardOut = @(&$omp --pwd="$cleanPWD" --pswd="$cleanPSWD" --config="$config" --tooltip="$tooltip" 2>&1)
|
||||||
|
Write-Host $standardOut -NoNewline
|
||||||
|
$host.UI.RawUI.CursorPosition = $position
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue