Skip to content

Commit a103482

Browse files
committed
feat(pwsh): render hyperlink for theme name
render hyperlink for theme name and themes location in Get-PoshThemes bold attribute removed since it's not really working in windows terminal(microsoft/terminal#109)
1 parent e6cb3a5 commit a103482

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

packages/powershell/oh-my-posh/oh-my-posh.psm1

+26-3
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,30 @@ function Set-PoshPrompt {
7777
(& $poshCommand --init --shell=pwsh --config="$config") | Invoke-Expression
7878
}
7979

80+
<#
81+
.SYNOPSIS
82+
Returns an ansi formatted hyperlink
83+
if name not set, uri is used as the name of the hyperlink
84+
.EXAMPLE
85+
Get-Hyperlink
86+
#>
87+
function Get-Hyperlink {
88+
param(
89+
[Parameter(Mandatory)]
90+
[string]$uri,
91+
[string]$name
92+
)
93+
$esc = [char]27
94+
if ("" -eq $name) {
95+
$name = $uri
96+
}
97+
if ($env:WSL_DISTRO_NAME -ne $null){
98+
# wsl conversion if needed
99+
$uri= &wslpath -m $uri
100+
}
101+
return "$esc]8;;file://$uri$esc\$name$esc]8;;$esc\"
102+
}
103+
80104
<#
81105
.SYNOPSIS
82106
Display a preview or a list of installed themes.
@@ -91,7 +115,6 @@ function Get-PoshThemes() {
91115
[Parameter(Mandatory = $false, HelpMessage = "List themes path")]
92116
$list
93117
)
94-
$esc = [char]27
95118
$consoleWidth = $Host.UI.RawUI.WindowSize.Width
96119
$logo = @'
97120
__ _____ _ ___ ___ ______ _ __
@@ -112,15 +135,15 @@ function Get-PoshThemes() {
112135
else {
113136
$poshCommand = Get-PoshCommand
114137
$themes | ForEach-Object -Process {
115-
Write-Host "Theme: $esc[1m$($_.BaseName.Replace('.omp', ''))$esc[0m"
138+
Write-Host "Theme: $(Get-Hyperlink -uri $_.fullname -name $_.BaseName.Replace('.omp', ''))"
116139
Write-Host ""
117140
& $poshCommand -config $($_.FullName) -pwd $PWD
118141
Write-Host ""
119142
}
120143
}
121144
Write-Host ("-" * $consoleWidth)
122145
Write-Host ""
123-
Write-Host "Themes location: $PSScriptRoot\themes"
146+
Write-Host "Themes location: $(Get-Hyperlink -uri "$PSScriptRoot/themes")"
124147
Write-Host ""
125148
Write-Host "To change your theme, use the Set-PoshPrompt command. Example:"
126149
Write-Host " Set-PoshPrompt -Theme jandedobbeleer"

0 commit comments

Comments
 (0)