Algemeen
Deze pagina is vertaald door PageTurner AI (beta). Niet officieel goedgekeurd door het project. Een fout gevonden? Probleem melden →
Oh My Posh geeft je prompt weer op basis van de definitie van blocks (zoals Lego) die een of meer segments bevatten.
Een hele eenvoudige configuratie kan er zo uitzien. Het standaardformaat is json, maar we ondersteunen ook toml en yaml.
Er is een actueel schema beschikbaar dat helpt bij het automatisch aanvullen en valideren van je configuratie.
Er zijn enkele thema's beschikbaar die eigenlijk vooraf gedefinieerde configuraties zijn. Je kunt deze direct gebruiken of als startpunt nemen voor je eigen configuratie.
- json
- yaml
- toml
{
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
"final_space": true,
"version": 4,
"blocks": [
{
"type": "prompt",
"alignment": "left",
"segments": [
{
"type": "path",
"style": "powerline",
"powerline_symbol": "\uE0B0",
"foreground": "#ffffff",
"background": "#61AFEF",
"options": {
"style": "folder"
}
}
]
}
]
}
# yaml-language-server: $schema=https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json
final_space: true
version: 4
blocks:
- type: prompt
alignment: left
segments:
- type: path
style: powerline
powerline_symbol: ""
foreground: "#ffffff"
background: "#61AFEF"
options:
style: folder
"$schema" = "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json"
final_space = true
version = 4
[[blocks]]
type = "prompt"
alignment = "left"
[[blocks.segments]]
type = "path"
style = "powerline"
powerline_symbol = ""
foreground = "#ffffff"
background = "#61AFEF"
[blocks.segments.options]
style = "folder"
Met deze configuratie wordt een enkel powerline-segment weergegeven dat de naam toont van de map waarin je je momenteel bevindt.
Om deze configuratie in te stellen in combinatie met een Oh My Posh uitvoerbaar bestand, gebruik je de --config-vlag om
een pad in te stellen naar een bestand met de bovenstaande code. De --shell universal-vlag wordt gebruikt om de prompt zonder
escape-karakters af te drukken, zodat je de prompt ziet zoals deze zou worden getoond in een promptfunctie voor je shell.
De onderstaande opdracht maakt je configuratie niet permanent voor je shell, maar drukt de prompt af in je terminal. Als je je eigen configuratie permanent wilt gebruiken, pas dan je promptconfiguratie aan om je aangepaste configuratie te gebruiken.
oh-my-posh print primary --config sample.json --shell uni
Als alles goed gaat, zie je de prompt op de volgende regel afgedrukt. Als je veel vakjes met vraagtekens ziet, configureer je terminal dan om een ondersteund lettertype te gebruiken voordat je verdergaat.
De --config-vlag accepteert zowel een lokaal bestandspad als een extern gehost configuratiebestand.
Bijvoorbeeld, de volgende --config-vlag is geldig:
--config 'https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/jandedobbeleer.omp.json'
Instellingen
| Name | Type | Default | Description |
|---|---|---|---|
final_space | boolean | when true adds a space at the end of the prompt | |
pwd | string | notify terminal of current working directory, values can be osc99, osc7 or osc51 depending on your terminal. Supports templates | |
terminal_background | string | color - terminal background color, set to your terminal's background color when you notice black elements in Windows Terminal or the Visual Studio Code integrated terminal | |
accent_color | string | color - accent color, used as a fallback when the accent color is not supported | |
var | map[string]any | config variables to use in templates. Can be any value | |
shell_integration | boolean | false | enable shell integration using FinalTerm's OSC sequences. Works in bash, cmd (Clink v1.14.25+), fish, powershell and zsh |
enable_cursor_positioning | boolean | false | enable fetching the cursor position in bash and zsh to allow automatic hiding of leading newlines when at the top of the shell |
patch_pwsh_bleed | boolean | false | patch a PowerShell bug where the background colors bleed into the next line at the end of the buffer (can be removed when this is merged) |
upgrade | Upgrade | enable auto upgrade or the upgrade notice. See Upgrade | |
iterm_features | []string | false | enable iTerm2 specific features:
|
maps | Maps | a list of custom text mappings | |
async | boolean | false | load the prompt async. Will either load the standard prompt, or allow you to start typing right away. Supported for pwsh, powershell, zsh, bash and fish |
version | int | 4 | the config version, currently at 4 |
extends | string | the configuration to extend from |
Kaarten
| Name | Type | Description |
|---|---|---|
user_name | object | text replacement mapping for user names |
host_name | object | text replacement mapping for host names |
shell_name | object | text replacement mapping for shell names. This modifies the .Shell global property. |
- json
- yaml
- toml
{
"maps": {
"user_name": {
"jan": "🚀",
"root": "⚡"
},
"host_name": {
"laptop123": "work"
}
}
}
maps:
user_name:
jan: 🚀
root: ⚡
host_name:
laptop123: work
[maps.user_name]
jan = "🚀"
root = "⚡"
[maps.host_name]
laptop123 = "work"
Uitbreiden
De extends-sleutel laat je toe een bestaande configuratie uit te breiden. Dit is handig wanneer je wilt voortbouwen op een basisconfiguratie zonder
alle instellingen te dupliceren, zoals bij een thema. De waarde moet een pad zijn naar een ander configuratiebestand, dat lokaal of extern kan zijn.
Waarden vervangen doe je door de waarde in de nieuwe configuratie te herhalen. Als je bijvoorbeeld de accent_color in een basisconfiguratie wilt wijzigen,
kun je dit doen door de accent_color-sleutel in je nieuwe configuratie op te nemen. De nieuwe waarde overschrijft die van de basisconfiguratie.
Om segments en blocks te overschrijven, specifieer je het block met hetzelfde type en alignment als de basisconfiguratie. Vervolgens kun je segments
binnen dat block toevoegen of wijzigen. Segments worden gematcht op hun alias of type, zodat je nieuwe segments kunt toevoegen of bestaande kunt wijzigen
zonder de rest van de configuratie te beïnvloeden.
Voor geavanceerdere scenario's kun je ook de index specificeren van het block of segment dat je wilt overschrijven. Hierdoor kun je blocks of segments op
specifieke posities in de configuratie overschrijven. Let op dat de index 1-based is, dus het eerste block of segment heeft index 1.
JSON Schema Validatie
Zoals eerder vermeld, kunnen Oh My Posh-configuraties JSON Schema gebruiken om hun inhoud te valideren. Configuraties moeten een link bevatten naar het externe schemadocument dat de juiste structuur en inhoud voor verschillende elementen voorschrijft. Als je code-editor is ingesteld om JSON Schema te gebruiken, vergelijkt deze je configuratie met het externe document en geeft waarschuwingen bij afwijkingen.
Bijvoorbeeld, met de volgende code:
...
"segments": [
{
"type": "an_invalid_entry",
"template": "{{ if gt .Code 0 }}\uf134{{ end }}",
}
]
...
Er worden waarschuwingen gegenereerd voor het type, omdat an_invalid_entry niet in de lijst met toegestane waarden staat, en ook
voor het hele segmentitem (omsloten door {}), omdat het de vereiste style-sleutel mist. Maak gebruik van deze
waarschuwingen, en negeer ze op eigen risico.
Ondersteunde formaten
Oh My Posh ondersteunt drie bestandsformaten voor configuraties: json, yaml en toml.
Er bestaan verschillende converters om tussen deze formaten te converteren, maar die zijn niet perfect en vereisen handmatige aanpassingen. Let op dat de schema-implementatie voor json als volgt is:
{
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json"
}
Terwijl voor yaml:
# yaml-language-server: $schema=https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json
Converters zullen deze wijziging niet opvangen, dus je zult handmatig aanpassingen moeten doen.