Skip to content

Commit

Permalink
add URL support for OhMyPosh
Browse files Browse the repository at this point in the history
  • Loading branch information
jpawlowski committed Aug 17, 2024
1 parent 32b4054 commit 3c10d4d
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 53 deletions.
3 changes: 2 additions & 1 deletion src/powershell-extended/NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ This feature comes with a custom [Oh My Posh](https://ohmyposh.dev/) theme to ad

You may [change the theme](https://ohmyposh.dev/docs/themes) to one of the preinstalled ones by setting the container environment
variables `PSPROFILE_POSH_THEME` (for the PowerShell host) and/or `PSPROFILE_VSCODE_POSH_THEME` (for the VSCode PowerShell
Extension) to the name of the desired theme. You may also put your own theme into the `~/.config/oh-my-posh/themes` folder.
Extension) to the name of the desired theme. You may also put your own theme into the `~/.config/oh-my-posh/themes` folder,
or set the environment variable to a URL to have the theme downloaded automatically.

> **Note**: Most themes require installing a [Nerd Font](https://ohmyposh.dev/docs/installation/fonts) on your host
> system (not the Dev Container) and changing your font settings in VSCode. The VSCode default font _Cascadia Mono_
Expand Down
18 changes: 9 additions & 9 deletions src/powershell-extended/PROFILE.AllUsersAllHosts.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ try {
if ($IsWindows) { return } # This global profile is for *nix only

#region Script Variables =======================================================
$__PSProfileEnvPathOriginal = [Environment]::GetEnvironmentVariable('PATH')
$__PSProfileEnvTermProgram = [Environment]::GetEnvironmentVariable('TERM_PROGRAM')
$__PSProfileEnvPathOriginal = [System.Environment]::GetEnvironmentVariable('PATH')
$__PSProfileEnvTermProgram = [System.Environment]::GetEnvironmentVariable('TERM_PROGRAM')

$__PSProfileEnvAliasDirForce = [System.Environment]::GetEnvironmentVariable('PSPROFILE_ALIAS_DIR_FORCE')
$__PSProfileEnvAliasDirHidden = [System.Environment]::GetEnvironmentVariable('PSPROFILE_ALIAS_DIR_HIDDEN')
Expand All @@ -68,8 +68,8 @@ try {
# Mark first run notice as displayed after 10s to avoid problems with fast terminal refreshes hiding it
$null = Start-ThreadJob -Name FirstRunNoticeAlreadyDisplayed -ScriptBlock {
Start-Sleep -Seconds 10
$null = New-Item -ItemType Directory -Force -Path "$env:HOME/.config/vscode-dev-containers"
$null = New-Item -ItemType File -Force -Path "$env:HOME/.config/vscode-dev-containers/first-run-notice-already-displayed"
$null = New-Item -ItemType Directory -Force -Path "${HOME}/.config/vscode-dev-containers"
$null = New-Item -ItemType File -Force -Path "${HOME}/.config/vscode-dev-containers/first-run-notice-already-displayed"
}
}

Expand All @@ -81,24 +81,24 @@ try {

#region Environment Variables ==================================================
# Add local bin directory to PATH if not already present
if ($__PSProfileEnvPathOriginal.Split(':') -notcontains "${HOME}/.local/bin") { [Environment]::SetEnvironmentVariable('PATH', "${__PSProfileOriginalPath}:${HOME}/.local/bin") }
if ($__PSProfileEnvPathOriginal.Split(':') -notcontains "${HOME}/.local/bin") { [System.Environment]::SetEnvironmentVariable('PATH', "${__PSProfileOriginalPath}:${HOME}/.local/bin") }

# Set the USER environment variable if not already set
if ($null -eq [Environment]::GetEnvironmentVariable('USER') -and $null -eq [Environment]::GetEnvironmentVariable('USERNAME')) { [Environment]::SetEnvironmentVariable('USER', (& $(& which whoami))) }
if ($null -eq [System.Environment]::GetEnvironmentVariable('USER') -and $null -eq [System.Environment]::GetEnvironmentVariable('USERNAME')) { [System.Environment]::SetEnvironmentVariable('USER', (& $(& which whoami))) }

# Set the default git editor if not already set
if (
$null -eq [Environment]::GetEnvironmentVariable('GIT_EDITOR') -and
$null -eq [System.Environment]::GetEnvironmentVariable('GIT_EDITOR') -and
$null -eq $(try { git config --get core.editor } catch { $Error.Clear(); $null })
) {
# Check if the terminal program is vscode
if ($__PSProfileEnvTermProgram -match '^(vscode|codespaces)$') {
# Check if code-insiders is available and code is not available
if ((Get-Command -Name 'code-insiders' -ErrorAction Ignore) -and $null -eq (Get-Command -Name 'code' -ErrorAction Ignore)) {
[Environment]::SetEnvironmentVariable('GIT_EDITOR', 'code-insiders --wait')
[System.Environment]::SetEnvironmentVariable('GIT_EDITOR', 'code-insiders --wait')
}
else {
[Environment]::SetEnvironmentVariable('GIT_EDITOR', 'code --wait')
[System.Environment]::SetEnvironmentVariable('GIT_EDITOR', 'code --wait')
}
}
}
Expand Down
30 changes: 16 additions & 14 deletions src/powershell-extended/PROFILE.Functions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function __PSProfile-Write-ProfileLoadMessage {
[switch]$Force
)

if ($Force -or ($env:POWERSHELL_HIDE_PROFILE_LOAD_MESSAGES -ne $true -and (__PSProfile-Assert-IsUserInteractiveShell))) {
if ($Force -or ([System.Environment]::GetEnvironmentVariable('POWERSHELL_HIDE_PROFILE_LOAD_MESSAGES') -ne $true -and (__PSProfile-Assert-IsUserInteractiveShell))) {
$writeHostParams = @{
Object = $Message
ForegroundColor = $ForegroundColor
Expand Down Expand Up @@ -359,23 +359,25 @@ function __PSProfile-Enable-OhMyPosh-Theme {
#>
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseApprovedVerbs', '')]
param(
[string]$Theme = 'devcontainers.minimal'
[string]$Theme = 'devcontainers.minimal.omp.json'
)

# Let codespaces always be an alias for devcontainers
$Theme = [regex]::Replace($Theme, 'codespaces', 'devcontainers')
if ($Theme -notmatch '^https?://') {
# Let codespaces always be an alias for devcontainers
$Theme = [regex]::Replace($Theme, 'codespaces', 'devcontainers')

# Ensure the theme file has the correct extension
if ($Theme -notmatch '\.omp\.json$') { $Theme = "$Theme.omp.json" }
# Ensure the theme file has the correct extension
if ($Theme -notmatch '\.omp\.[^\.]+$') { $Theme = "$Theme.omp.json" }

# Find path to theme file
if ($Theme -notmatch '^/') {
if ([System.IO.File]::Exists("$env:HOME/.config/oh-my-posh/themes/$Theme")) {
$Theme = "$env:HOME/.config/oh-my-posh/themes/$Theme"
}
else {
if (-not $env:POSH_THEMES_PATH) { $env:POSH_THEMES_PATH = "$env:HOME/.cache/oh-my-posh/themes" }
$Theme = "$env:POSH_THEMES_PATH/$Theme"
# Find path to theme file
if ($Theme -notmatch '^/') {
if ([System.IO.File]::Exists("${HOME}/.config/oh-my-posh/themes/$Theme")) {
$Theme = "${HOME}/.config/oh-my-posh/themes/$Theme"
}
else {
if (-not [System.Environment]::GetEnvironmentVariable('POSH_THEMES_PATH')) { [System.Environment]::SetEnvironmentVariable('POSH_THEMES_PATH', "${HOME}/.cache/oh-my-posh/themes") }
$Theme = "${HOME}/.cache/oh-my-posh/themes/$Theme"
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/powershell-extended/devcontainer-feature.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
"PSPROFILE_AUTOUPDATE_MODULEHELP": "true",
"PSPROFILE_PSREADLINE_PREDICTION_SOURCE": "HistoryAndPlugin",
"PSPROFILE_PSREADLINE_PREDICTION_VIEWSTYLE": "InlineView",
"PSPROFILE_POSH_THEME": "devcontainers.minimal",
"PSPROFILE_POSH_THEME": "devcontainers.minimal.omp.json",
"PSPROFILE_TERMINAL_COMPLETION_GIT": "true",
"PSPROFILE_TERMINAL_COMPLETION_POSH": "false",
"PSPROFILE_TERMINAL_COMPLETION_PREDICTOR": "true",
Expand All @@ -123,7 +123,7 @@
"PSPROFILE_VSCODE_AUTOUPDATE_MODULEHELP": "false",
"PSPROFILE_VSCODE_PSREADLINE_PREDICTION_SOURCE": "HistoryAndPlugin",
"PSPROFILE_VSCODE_PSREADLINE_PREDICTION_VIEWSTYLE": "InlineView",
"PSPROFILE_VSCODE_POSH_THEME": "devcontainers.minimal",
"PSPROFILE_VSCODE_POSH_THEME": "devcontainers.minimal.omp.json",
"PSPROFILE_VSCODE_TERMINAL_COMPLETION_GIT": "true",
"PSPROFILE_VSCODE_TERMINAL_COMPLETION_POSH": "false",
"PSPROFILE_VSCODE_TERMINAL_COMPLETION_PREDICTOR": "true",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,34 @@ try {
__PSProfile-Write-ProfileLoadMessage '💻 Applying shared configurations for all terminals.' -ForegroundColor DarkCyan

#region Import Modules =====================================================
if ([Environment]::GetEnvironmentVariable('PSPROFILE_TERMINAL_COMPLETION_GIT') -eq $true) { __PSProfile-Import-ModuleAndInstallIfMissing -Name posh-git }
if ([Environment]::GetEnvironmentVariable('PSPROFILE_TERMINAL_COMPLETION_PSFZF') -eq $true -and $null -ne (Get-Command -Name fzf -CommandType Application -ErrorAction Ignore)) { __PSProfile-Import-ModuleAndInstallIfMissing -Name PSFzf }
if ([Environment]::GetEnvironmentVariable('PSPROFILE_TERMINAL_COMPLETION_PREDICTOR') -eq $true) { __PSProfile-Import-ModuleAndInstallIfMissing -Name CompletionPredictor }
if ([Environment]::GetEnvironmentVariable('PSPROFILE_TERMINAL_COMPLETION_PREDICTOR_AZ') -eq $true) { if (Get-Module -Name Az.Accounts -ListAvailable) { __PSProfile-Import-ModuleAndInstallIfMissing -Name Az.Tools.Predictor } }
if ([Environment]::GetEnvironmentVariable('PSPROFILE_TERMINAL_Z') -eq $true) { __PSProfile-Import-ModuleAndInstallIfMissing -Name z }
if ([Environment]::GetEnvironmentVariable('PSPROFILE_TERMINAL_ICONS') -eq $true) { __PSProfile-Import-ModuleAndInstallIfMissing -Name Terminal-Icons }
if ([System.Environment]::GetEnvironmentVariable('PSPROFILE_TERMINAL_COMPLETION_GIT') -eq $true) { __PSProfile-Import-ModuleAndInstallIfMissing -Name posh-git }
if ([System.Environment]::GetEnvironmentVariable('PSPROFILE_TERMINAL_COMPLETION_PSFZF') -eq $true -and $null -ne (Get-Command -Name fzf -CommandType Application -ErrorAction Ignore)) { __PSProfile-Import-ModuleAndInstallIfMissing -Name PSFzf }
if ([System.Environment]::GetEnvironmentVariable('PSPROFILE_TERMINAL_COMPLETION_PREDICTOR') -eq $true) { __PSProfile-Import-ModuleAndInstallIfMissing -Name CompletionPredictor }
if ([System.Environment]::GetEnvironmentVariable('PSPROFILE_TERMINAL_COMPLETION_PREDICTOR_AZ') -eq $true) { if (Get-Module -Name Az.Accounts -ListAvailable) { __PSProfile-Import-ModuleAndInstallIfMissing -Name Az.Tools.Predictor } }
if ([System.Environment]::GetEnvironmentVariable('PSPROFILE_TERMINAL_Z') -eq $true) { __PSProfile-Import-ModuleAndInstallIfMissing -Name z }
if ([System.Environment]::GetEnvironmentVariable('PSPROFILE_TERMINAL_ICONS') -eq $true) { __PSProfile-Import-ModuleAndInstallIfMissing -Name Terminal-Icons }
#endregion Import Modules --------------------------------------------------

#region PSReadLine predictor plugins =======================================
$__PSProfilePSReadLineOptions = @{}
$__PSProfileEnvPSReadlinePredictionSource = [Environment]::GetEnvironmentVariable('PSPROFILE_PSREADLINE_PREDICTION_SOURCE')
$__PSProfileEnvPSReadlinePredictionViewStyle = [Environment]::GetEnvironmentVariable('PSPROFILE_PSREADLINE_PREDICTION_VIEWSTYLE')
$__PSProfileEnvPSReadlinePredictionSource = [System.Environment]::GetEnvironmentVariable('PSPROFILE_PSREADLINE_PREDICTION_SOURCE')
$__PSProfileEnvPSReadlinePredictionViewStyle = [System.Environment]::GetEnvironmentVariable('PSPROFILE_PSREADLINE_PREDICTION_VIEWSTYLE')
if ($null -ne $__PSProfileEnvPSReadlinePredictionSource) { $__PSProfilePSReadLineOptions.PredictionSource = $__PSProfileEnvPSReadlinePredictionSource }
if ($null -ne $__PSProfileEnvPSReadlinePredictionViewStyle) { $__PSProfilePSReadLineOptions.PredictionViewStyle = $__PSProfileEnvPSReadlinePredictionViewStyle }
if ($__PSProfilePSReadLineOptions.Count -gt 0) { Set-PSReadLineOption @__PSProfilePSReadLineOptions }
#endregion PSReadLine ------------------------------------------------------

#region Environment ========================================================
$__PSProfileEnvAutoUpdateModuleHelp = [Environment]::GetEnvironmentVariable('PSPROFILE_AUTOUPDATE_MODULEHELP')
$__PSProfileEnvAutoUpdateModuleHelp = [System.Environment]::GetEnvironmentVariable('PSPROFILE_AUTOUPDATE_MODULEHELP')
if ($null -eq $__PSProfileEnvAutoUpdateModuleHelp -or $__PSProfileEnvAutoUpdateModuleHelp -eq $true) { __PSProfile-Update-Help }
#endregion Environment -----------------------------------------------------

#region Oh My Posh =========================================================
$__PSProfileEnvOhMyPoshDisableUpgradeNotice = [Environment]::GetEnvironmentVariable('PSPROFILE_POSH_DISABLE_UPGRADE_NOTICE')
$__PSProfileEnvOhMyPoshTheme = [Environment]::GetEnvironmentVariable('PSPROFILE_POSH_THEME')
$__PSProfileEnvOhMyPoshDisableUpgradeNotice = [System.Environment]::GetEnvironmentVariable('PSPROFILE_POSH_DISABLE_UPGRADE_NOTICE')
$__PSProfileEnvOhMyPoshTheme = [System.Environment]::GetEnvironmentVariable('PSPROFILE_POSH_THEME')
if ($null -eq $__PSProfileEnvOhMyPoshDisableUpgradeNotice -or $__PSProfileEnvOhMyPoshDisableUpgradeNotice -eq $true) { __PSProfile-Set-OhMyPosh-UpdateNotice -Disable }
if ($null -ne $__PSProfileEnvOhMyPoshTheme) { __PSProfile-Enable-OhMyPosh-Theme -ThemeName $__PSProfileEnvOhMyPoshTheme } else { __PSProfile-Enable-OhMyPosh-Theme }
if ([Environment]::GetEnvironmentVariable('PSPROFILE_TERMINAL_COMPLETION_POSH') -eq $true -and $null -ne [Environment]::GetEnvironmentVariable('POSH_PID')) { oh-my-posh completion powershell | Out-String | Invoke-Expression }
if ([System.Environment]::GetEnvironmentVariable('PSPROFILE_TERMINAL_COMPLETION_POSH') -eq $true -and $null -ne [System.Environment]::GetEnvironmentVariable('POSH_PID')) { oh-my-posh completion powershell | Out-String | Invoke-Expression }
#endregion Oh My Posh ------------------------------------------------------

#region Custom Profile =====================================================
Expand Down Expand Up @@ -99,7 +99,7 @@ try {
[regex]::Replace(
(
[regex]::Replace(
[Environment]::GetEnvironmentVariable('TERM_PROGRAM'),
[System.Environment]::GetEnvironmentVariable('TERM_PROGRAM'),
'\.[^\.]*$',
''
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,33 +40,33 @@ try {
__PSProfile-Write-ProfileLoadMessage "📝 Applying configurations for $($PSStyle.Bold)PowerShell Extension$($PSStyle.BoldOff)." -ForegroundColor DarkCyan

#region Import Modules =====================================================
if ([Environment]::GetEnvironmentVariable('PSPROFILE_VSCODE_TERMINAL_COMPLETION_GIT') -eq $true) { __PSProfile-Import-ModuleAndInstallIfMissing -Name posh-git }
if ([Environment]::GetEnvironmentVariable('PSPROFILE_VSCODE_TERMINAL_COMPLETION_PSFZF') -eq $true -and $null -ne (Get-Command -Name fzf -CommandType Application -ErrorAction Ignore)) { __PSProfile-Import-ModuleAndInstallIfMissing -Name PSFzf }
if ([Environment]::GetEnvironmentVariable('PSPROFILE_VSCODE_TERMINAL_COMPLETION_PREDICTOR') -eq $true) { __PSProfile-Import-ModuleAndInstallIfMissing -Name CompletionPredictor }
if ([Environment]::GetEnvironmentVariable('PSPROFILE_VSCODE_TERMINAL_COMPLETION_PREDICTOR_AZ') -eq $true) { if (Get-Module -Name Az.Accounts -ListAvailable) { __PSProfile-Import-ModuleAndInstallIfMissing -Name Az.Tools.Predictor } }
if ([Environment]::GetEnvironmentVariable('PSPROFILE_VSCODE_TERMINAL_Z') -eq $true) { __PSProfile-Import-ModuleAndInstallIfMissing -Name z }
if ([Environment]::GetEnvironmentVariable('PSPROFILE_VSCODE_TERMINAL_ICONS') -eq $true) { __PSProfile-Import-ModuleAndInstallIfMissing -Name Terminal-Icons }
if ([System.Environment]::GetEnvironmentVariable('PSPROFILE_VSCODE_TERMINAL_COMPLETION_GIT') -eq $true) { __PSProfile-Import-ModuleAndInstallIfMissing -Name posh-git }
if ([System.Environment]::GetEnvironmentVariable('PSPROFILE_VSCODE_TERMINAL_COMPLETION_PSFZF') -eq $true -and $null -ne (Get-Command -Name fzf -CommandType Application -ErrorAction Ignore)) { __PSProfile-Import-ModuleAndInstallIfMissing -Name PSFzf }
if ([System.Environment]::GetEnvironmentVariable('PSPROFILE_VSCODE_TERMINAL_COMPLETION_PREDICTOR') -eq $true) { __PSProfile-Import-ModuleAndInstallIfMissing -Name CompletionPredictor }
if ([System.Environment]::GetEnvironmentVariable('PSPROFILE_VSCODE_TERMINAL_COMPLETION_PREDICTOR_AZ') -eq $true) { if (Get-Module -Name Az.Accounts -ListAvailable) { __PSProfile-Import-ModuleAndInstallIfMissing -Name Az.Tools.Predictor } }
if ([System.Environment]::GetEnvironmentVariable('PSPROFILE_VSCODE_TERMINAL_Z') -eq $true) { __PSProfile-Import-ModuleAndInstallIfMissing -Name z }
if ([System.Environment]::GetEnvironmentVariable('PSPROFILE_VSCODE_TERMINAL_ICONS') -eq $true) { __PSProfile-Import-ModuleAndInstallIfMissing -Name Terminal-Icons }
#endregion Import Modules --------------------------------------------------

#region PSReadLine Predictor plugins =======================================
$__PSProfilePSReadLineOptions = @{}
$__PSProfileEnvPSReadlinePredictionSource = [Environment]::GetEnvironmentVariable('PSPROFILE_VSCODE_PSREADLINE_PREDICTION_SOURCE')
$__PSProfileEnvPSReadlinePredictionViewStyle = [Environment]::GetEnvironmentVariable('PSPROFILE_VSCODE_PSREADLINE_PREDICTION_VIEWSTYLE')
$__PSProfileEnvPSReadlinePredictionSource = [System.Environment]::GetEnvironmentVariable('PSPROFILE_VSCODE_PSREADLINE_PREDICTION_SOURCE')
$__PSProfileEnvPSReadlinePredictionViewStyle = [System.Environment]::GetEnvironmentVariable('PSPROFILE_VSCODE_PSREADLINE_PREDICTION_VIEWSTYLE')
if ($null -ne $__PSProfileEnvPSReadlinePredictionSource) { $__PSProfilePSReadLineOptions.PredictionSource = $__PSProfileEnvPSReadlinePredictionSource }
if ($null -ne $__PSProfileEnvPSReadlinePredictionViewStyle) { $__PSProfilePSReadLineOptions.PredictionViewStyle = $__PSProfileEnvPSReadlinePredictionViewStyle }
if ($__PSProfilePSReadLineOptions.Count -gt 0) { Set-PSReadLineOption @__PSProfilePSReadLineOptions }
#endregion PSReadLine ------------------------------------------------------

#region Environment ========================================================
if ([Environment]::GetEnvironmentVariable('PSPROFILE_VSCODE_AUTOUPDATE_MODULEHELP') -eq $true) { __PSProfile-Update-Help }
if ([System.Environment]::GetEnvironmentVariable('PSPROFILE_VSCODE_AUTOUPDATE_MODULEHELP') -eq $true) { __PSProfile-Update-Help }
#endregion Environment -----------------------------------------------------

#region Oh My Posh =========================================================
$__PSProfileEnvOhMyPoshDisableUpgradeNotice = [Environment]::GetEnvironmentVariable('PSPROFILE_POSH_DISABLE_UPGRADE_NOTICE')
$__PSProfileEnvOhMyPoshTheme = [Environment]::GetEnvironmentVariable('PSPROFILE_VSCODE_POSH_THEME')
$__PSProfileEnvOhMyPoshDisableUpgradeNotice = [System.Environment]::GetEnvironmentVariable('PSPROFILE_POSH_DISABLE_UPGRADE_NOTICE')
$__PSProfileEnvOhMyPoshTheme = [System.Environment]::GetEnvironmentVariable('PSPROFILE_VSCODE_POSH_THEME')
if ($null -eq $__PSProfileEnvOhMyPoshDisableUpgradeNotice -or $__PSProfileEnvOhMyPoshDisableUpgradeNotice -eq $true) { __PSProfile-Set-OhMyPosh-UpdateNotice -Disable }
if ($null -ne $__PSProfileEnvOhMyPoshTheme) { __PSProfile-Enable-OhMyPosh-Theme -ThemeName $__PSProfileEnvOhMyPoshTheme } else { __PSProfile-Enable-OhMyPosh-Theme }
if ([Environment]::GetEnvironmentVariable('PSPROFILE_VSCODE_TERMINAL_COMPLETION_POSH') -eq $true -and $null -ne [Environment]::GetEnvironmentVariable('POSH_PID')) { oh-my-posh completion powershell | Out-String | Invoke-Expression }
if ([System.Environment]::GetEnvironmentVariable('PSPROFILE_VSCODE_TERMINAL_COMPLETION_POSH') -eq $true -and $null -ne [System.Environment]::GetEnvironmentVariable('POSH_PID')) { oh-my-posh completion powershell | Out-String | Invoke-Expression }
#endregion Oh My Posh ------------------------------------------------------

#region Custom Profile =====================================================
Expand Down
Loading

0 comments on commit 3c10d4d

Please sign in to comment.