fix(pwsh): correct encoding for config export

resolves #425
This commit is contained in:
Jan De Dobbeleer 2021-02-18 09:48:13 +01:00
parent de498044c9
commit 9b137827e1
4 changed files with 16 additions and 12 deletions

View file

@ -339,14 +339,7 @@ available options first, by starting with the [configuration guide][configuratio
You can output the current theme to its `JSON` representation which can be used to tweak and store as your custom theme.
```powershell
Write-PoshTheme
```
Due to a bug in PowerShell, if you want to use `Out-File` directly to write the current theme to a new file, use the `oem`
encoding to ensure the symbols are outputted correctly.
```powershell
Write-PoshTheme | Out-File -FilePath ~/.mytheme.omp.json -Encoding oem
Export-PoshTheme -FilePath ~/.mytheme.omp.json
```
Once you're done editing, adjust your `$PROFILE` to use your newly created theme.

View file

@ -61,7 +61,7 @@ If you see one you like, set it, then export its config so you can customize/ext
```powershell
Set-PoshPrompt -Theme jandedobbeleer
Write-PoshTheme | Out-File -FilePath ~/.go-my-posh.json -Encoding oem
Export-PoshTheme | Out-File -FilePath ~/.go-my-posh.json -Encoding oem
```
Adjust the config (`~/.go-my-posh.json`) to your liking by going through the [configuration][configuration] guide.

View file

@ -31,7 +31,7 @@
# Aliases to export from this module
AliasesToExport = '*'
# Functions to export from this module
FunctionsToExport = @('Get-PoshThemes', 'Set-PoshPrompt', 'Write-PoshTheme', 'Set-PoshContext', 'Get-PoshInfoForV2Users')
FunctionsToExport = @('Get-PoshThemes', 'Set-PoshPrompt', 'Export-PoshTheme', 'Set-PoshContext', 'Get-PoshInfoForV2Users')
# 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 = @{

View file

@ -92,10 +92,21 @@ function Get-PoshThemes {
Write-Host ("=" * $consoleWidth)
}
function Write-PoshTheme {
function Export-PoshTheme {
param(
[Parameter(Mandatory = $true)]
[string]
$FilePath
)
$config = $global:PoshSettings.Theme
$poshCommand = Get-PoshCommand
& $poshCommand -config $config -print-config
# Save current encoding and swap for UTF8
$originalOutputEncoding = [Console]::OutputEncoding
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
& $poshCommand -config $config -print-config | Out-File -FilePath $FilePath
# Restore initial encoding
[Console]::OutputEncoding = $originalOutputEncoding
}
# Helper function to create argument completion results