Direct naar hoofdinhoud

Algemeen

Onofficiële Beta-vertaling

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.

informatie

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.

{
"$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"
}
}
]
}
]
}

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.

let op

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.

tip

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

NameTypeDefaultDescription
final_spacebooleanwhen true adds a space at the end of the prompt
pwdstringnotify terminal of current working directory, values can be osc99, osc7 or osc51 depending on your terminal. Supports templates
terminal_backgroundstringcolor - 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_colorstringcolor - accent color, used as a fallback when the accent color is not supported
varmap[string]anyconfig variables to use in templates. Can be any value
shell_integrationbooleanfalseenable shell integration using FinalTerm's OSC sequences. Works in bash, cmd (Clink v1.14.25+), fish, powershell and zsh
enable_cursor_positioningbooleanfalseenable fetching the cursor position in bash and zsh to allow automatic hiding of leading newlines when at the top of the shell
patch_pwsh_bleedbooleanfalsepatch 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)
upgradeUpgradeenable auto upgrade or the upgrade notice. See Upgrade
iterm_features[]stringfalseenable iTerm2 specific features:
  • prompt_mark: add the iterm2_prompt_mark function for supported shells
  • current_dir: expose the current directory for iTerm2
  • remote_host: expose the current remote and user for iTerm2
mapsMapsa list of custom text mappings
asyncbooleanfalseload 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
versionint4the config version, currently at 4
extendsstringthe configuration to extend from

Kaarten

NameTypeDescription
user_nameobjecttext replacement mapping for user names
host_nameobjecttext replacement mapping for host names
shell_nameobjecttext replacement mapping for shell names. This modifies the .Shell global property.
{
"maps": {
"user_name": {
"jan": "🚀",
"root": "⚡"
},
"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.