Aller au contenu principal

Configuration d'État Désiré

Traduction Bêta Non Officielle

Cette page a été traduite par PageTurner AI (bêta). Non approuvée officiellement par le projet. Vous avez trouvé une erreur ? Signaler un problème →

Oh My Posh prend en charge la Configuration d'État Désiré (DSC) pour une gestion déclarative des configurations, permettant des déploiements automatisés et une configuration cohérente sur plusieurs systèmes.

Concept

L'approche DSC d'Oh My Posh enrichit la configuration traditionnelle en ajoutant des capacités d'automatisation et d'orchestration. Plutôt que de configurer manuellement votre invite, vous définissez l'état désiré de manière déclarative et laissez DSC garantir que votre système correspond à cet état.

DSC fonctionne avec des ressources représentant différents aspects de votre configuration Oh My Posh :

  • Ressource Configuration : Gère vos fichiers de configuration Oh My Posh

  • Ressource Shell : Gère l'initialisation et l'intégration du shell

  • Ressource Police : Suit les polices Nerd Fonts installées

Ces ressources peuvent être utilisées indépendamment via la CLI ou intégrées à des outils d'orchestration comme WinGet et Microsoft DSC pour des déploiements automatisés.

Vue d'ensemble

La prise en charge DSC dans Oh My Posh offre :

  • Configuration déclarative : Définissez l'état désiré de votre configuration Oh My Posh

  • Déploiement automatisé : Configurez Oh My Posh dans les flux de provisionnement système

  • Intégration au shell : Configure automatiquement l'initialisation pour bash, zsh, fish, PowerShell et autres

  • Gestion des polices : Suit les polices Nerd Fonts installées via l'état DSC

  • Support d'orchestration : Intégration avec WinGet et les outils Microsoft DSC

La fonctionnalité DSC est disponible via la CLI oh-my-posh et peut être utilisée seule ou avec des outils d'orchestration.

Ressources DSC

Oh My Posh fournit les ressources DSC suivantes :

Ressource Configuration

Gère les fichiers de configuration de Oh My Posh.

Opérations : get, set, export, schema

# Get current configuration state
oh-my-posh config dsc get

# Apply a configuration
oh-my-posh config dsc set --state '{"states":[{"source":"~/mytheme.omp.json","format":"json"}]}'

# Get configuration schema
oh-my-posh config dsc schema

Ressource Shell

Gère l'initialisation et l'intégration du shell.

Opérations : get, set, export, schema

# Get current shell configurations
oh-my-posh init bash dsc get

# Configure shell initialization
oh-my-posh init bash dsc set --state '{"states":[{"name":"bash","command":"oh-my-posh init bash --config ~/mytheme.omp.json"}]}'

Ressource Police

Suivi des polices Nerd Fonts installées via Oh My Posh.

Opérations : get, export, schema

# Get installed fonts
oh-my-posh font dsc get

# Get font schema
oh-my-posh font dsc schema

Utilisation directe en CLI

Vous pouvez utiliser les commandes DSC directement en ligne de commande pour la gestion des configurations.

Gestion des configurations

Obtenir l'état

Récupérer l'état de configuration actuel :

oh-my-posh config dsc get

Exemple de sortie :

{
"states": [
{
"format": "json",
"source": "~/mytheme.omp.json"
}
]
}

Définir l'état

Appliquer un nouvel état de configuration :

oh-my-posh config dsc set --state '{"states":[{"source":"~/mytheme.omp.json","format":"json"}]}'

Cela crée ou met à jour le fichier de configuration à l'emplacement spécifié avec le format fourni.

Schéma

Obtenir le schéma JSON pour la ressource de configuration :

oh-my-posh config dsc schema

Utilisez-le pour comprendre la structure et les options disponibles des états de configuration.

Gestion de l'intégration au shell

Bash

Configurer l'initialisation d'Oh My Posh pour bash :

# Get current state
oh-my-posh init bash dsc get

# Set initialization
oh-my-posh init bash dsc set --state '{"states":[{"name":"bash","command":"oh-my-posh init bash --config ~/mytheme.omp.json"}]}'

Cela met automatiquement à jour votre .bashrc ou .bash_profile avec la commande d'initialisation Oh My Posh.

Zsh

Configurer l'initialisation d'Oh My Posh pour zsh :

# Get current state
oh-my-posh init zsh dsc get

# Set initialization
oh-my-posh init zsh dsc set --state '{"states":[{"name":"zsh","command":"oh-my-posh init zsh --config ~/mytheme.omp.json"}]}'

Cela met automatiquement à jour votre .zshrc avec la commande d'initialisation Oh My Posh.

PowerShell

Configurer l'initialisation d'Oh My Posh pour PowerShell :

# Get current state
oh-my-posh init pwsh dsc get

# Set initialization
oh-my-posh init pwsh dsc set --state '{"states":[{"name":"pwsh","command":"oh-my-posh init pwsh --config ~/mytheme.omp.json"}]}'

Cela met automatiquement à jour votre profil PowerShell avec la commande d'initialisation Oh My Posh.

Fish

Configurez l'initialisation de Oh My Posh pour fish :

# Get current state
oh-my-posh init fish dsc get

# Set initialization
oh-my-posh init fish dsc set --state '{"states":[{"name":"fish","command":"oh-my-posh init fish --config ~/mytheme.omp.json"}]}'

Cette commande met automatiquement à jour votre fichier config.fish avec la commande d'initialisation de Oh My Posh.

Orchestration avec WinGet

La configuration WinGet permet d'installer Oh My Posh et d'appliquer une configuration via un seul fichier déclaratif.

Configuration WinGet de base

Créez un fichier de configuration pour installer et configurer Oh My Posh :

oh-my-posh-setup.yaml
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/v3/config/document.json
metadata:
winget:
processor: dscv3
resources:
- name: Install Oh My Posh
type: Microsoft.WinGet.DSC/WinGetPackage
properties:
id: JanDeDobbeleer.OhMyPosh
source: winget

Appliquez la configuration :

winget configure oh-my-posh-setup.yaml

Configuration complète avec thème et shell

Cet exemple installe Oh My Posh, ajoute votre configuration et initialise PowerShell :

oh-my-posh-complete.yaml
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/v3/config/document.json
metadata:
winget:
processor: dscv3
resources:
- name: Install Oh My Posh
type: Microsoft.WinGet.DSC/WinGetPackage
properties:
id: JanDeDobbeleer.OhMyPosh
source: winget

- name: Add Oh My Posh configuration
type: OhMyPosh/Config
properties:
states:
- source: ~/mytheme.omp.json
format: json

- name: Initialize PowerShell
type: OhMyPosh/Shell
properties:
states:
- name: pwsh
command: oh-my-posh init pwsh --config ~/mytheme.omp.json

Appliquez avec :

winget configure oh-my-posh-complete.yaml

Configuration multi-shell

Initialisez plusieurs shells avec différentes configurations :

oh-my-posh-multi-shell.yaml
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/v3/config/document.json
metadata:
winget:
processor: dscv3
resources:
- name: Install Oh My Posh
type: Microsoft.WinGet.DSC/WinGetPackage
properties:
id: JanDeDobbeleer.OhMyPosh
source: winget

- name: Add work configuration
type: OhMyPosh/Config
properties:
states:
- source: ~/work-theme.omp.json
format: json

- name: Add personal configuration
type: OhMyPosh/Config
properties:
states:
- source: ~/personal-theme.omp.json
format: json

- name: Initialize PowerShell with work configuration
type: OhMyPosh/Shell
properties:
states:
- name: pwsh
command: oh-my-posh init pwsh --config ~/work-theme.omp.json

- name: Initialize Bash with personal configuration
type: OhMyPosh/Shell
properties:
states:
- name: bash
command: oh-my-posh init bash --config ~/personal-theme.omp.json

Orchestration avec Microsoft DSC

Microsoft DSC (dsc) offre des capacités de gestion de configuration multiplateforme. Oh My Posh fournit des ressources DSC natives utilisables dans les documents de configuration DSC.

Exemple de configuration DSC

Créez un document de configuration pour Oh My Posh :

oh-my-posh-dsc.yaml
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
resources:
- name: Add Oh My Posh configuration
type: OhMyPosh/Config
properties:
states:
- source: ~/mytheme.omp.json
format: json

- name: Initialize PowerShell
type: OhMyPosh/Shell
properties:
states:
- name: pwsh
command: oh-my-posh init pwsh --config ~/mytheme.omp.json

Appliquez la configuration avec la CLI dsc :

dsc config set --document oh-my-posh-dsc.yaml

Configuration complète avec plusieurs shells

oh-my-posh-complete-dsc.yaml
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
resources:
- name: Add primary configuration
type: OhMyPosh/Config
properties:
states:
- source: ~/primary-theme.omp.json
format: json

- name: Add secondary configuration
type: OhMyPosh/Config
properties:
states:
- source: ~/secondary-theme.omp.json
format: yaml

- name: Initialize PowerShell
type: OhMyPosh/Shell
properties:
states:
- name: pwsh
command: oh-my-posh init pwsh --config ~/primary-theme.omp.json

- name: Initialize Bash
type: OhMyPosh/Shell
properties:
states:
- name: bash
command: oh-my-posh init bash --config ~/primary-theme.omp.json

- name: Initialize Zsh
type: OhMyPosh/Shell
properties:
states:
- name: zsh
command: oh-my-posh init zsh --config ~/secondary-theme.omp.json

Types de ressources

Oh My Posh fournit les types de ressources DSC suivants :

OhMyPosh/Config

Gère les fichiers de configuration de Oh My Posh.

Propriétés :

  • states (tableau) : Liste des états de configuration
    • source (chaîne) : Chemin du fichier de configuration
    • format (chaîne) : Format du fichier (json, yaml, toml)

OhMyPosh/Shell

Gère l'initialisation des shells.

Propriétés :

  • states (tableau) : Liste des configurations shell
    • name (chaîne) : Nom du shell (bash, zsh, pwsh, fish, etc.)
    • command (chaîne) : Commande d'initialisation de Oh My Posh

OhMyPosh/Font

Suivi des polices Nerd installées. Cette ressource est en lecture seule et automatiquement mise à jour lorsque des polices sont installées via Oh My Posh.

Gestion des états de configuration

L'état DSC est stocké dans le cache de Oh My Posh et persiste entre les sessions. Cela permet :

  • Suivi des états : Oh My Posh mémorise les configurations définies via DSC

  • Idempotence : L'exécution répétée d'une même commande DSC produit le même résultat

  • Validation d'état : Consultation de l'état actuel avant modification

Utilisation avancée

Configurations multiples

Vous pouvez gérer plusieurs fichiers de configuration :

oh-my-posh config dsc set --state '{
"states": [
{"source":"~/work.omp.json","format":"json"},
{"source":"~/personal.omp.json","format":"json"}
]
}'

Initialisation spécifique par shell

Initialisez plusieurs shells avec différentes configurations :

# Bash with one configuration
oh-my-posh init bash dsc set --state '{"states":[{"name":"bash","command":"oh-my-posh init bash --config ~/bash-theme.omp.json"}]}'

# PowerShell with another configuration
oh-my-posh init pwsh dsc set --state '{"states":[{"name":"pwsh","command":"oh-my-posh init pwsh --config ~/pwsh-theme.omp.json"}]}'

Shells pris en charge

La configuration DSC des shells prend en charge :

  • bash : Configure .bashrc ou .bash_profile

  • zsh : Configure .zshrc

  • fish : Configure ~/.config/fish/config.fish

  • pwsh : Configure le profil PowerShell ($PROFILE)

  • nu : Configure ~/.config/nushell/config.nu

  • elvish : Configure .elvish/rc.elv

  • xonsh : Configure le fichier .xonshrc

L'intégration du shell effectue automatiquement les opérations suivantes :

  • Crée les fichiers de configuration s'ils n'existent pas

  • Met à jour les commandes d'initialisation d'Oh My Posh existantes

  • Préserve la syntaxe spécifique à chaque shell

  • Conserve l'espacement et la mise en forme appropriés

Voir aussi