Desired State Configuration
Oh My Posh supports Desired State Configuration (DSC) for declarative configuration management, enabling automated deployment and consistent configuration across multiple systems.
Conceptโ
Oh My Posh DSC builds on the traditional Oh My Posh configuration approach by adding automation and orchestration capabilities. Instead of manually configuring your prompt, you can define the desired state declaratively and let DSC ensure your system matches that state.
DSC works with resources that represent different aspects of your Oh My Posh setup:
- Configuration Resource: Manages your Oh My Posh configuration files
- Shell Resource: Handles shell initialization and integration
- Font Resource: Tracks installed Nerd Fonts
These resources can be used standalone through the CLI or integrated with orchestration tools like WinGet and Microsoft DSC for automated deployments.
Overviewโ
DSC support in Oh My Posh provides:
- Declarative configuration: Define the desired state of your Oh My Posh setup
- Automated deployment: Configure Oh My Posh as part of system provisioning workflows
- Shell integration: Automatically configure shell initialization for bash, zsh, fish, PowerShell, and more
- Font management: Track installed Nerd Fonts through DSC state
- Orchestration support: Integration with WinGet and Microsoft DSC tools
DSC functionality is available through the oh-my-posh CLI and can be used standalone or with orchestration tools.
DSC Resourcesโ
Oh My Posh provides the following DSC resources:
Configuration Resourceโ
Manages Oh My Posh configuration files.
Operations: 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
Shell Resourceโ
Manages shell initialization and integration.
Operations: 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"}]}'
Font Resourceโ
Tracks Nerd Fonts installed through Oh My Posh.
Operations: get, export, schema
# Get installed fonts
oh-my-posh font dsc get
# Get font schema
oh-my-posh font dsc schema
Direct CLI Usageโ
You can use the DSC commands directly from the command line for configuration management.
Managing Configurationsโ
Get Stateโ
Retrieve the current configuration state:
oh-my-posh config dsc get
Example output:
{
"states": [
{
"format": "json",
"source": "~/mytheme.omp.json"
}
]
}
Set Stateโ
Apply a new configuration state:
oh-my-posh config dsc set --state '{"states":[{"source":"~/mytheme.omp.json","format":"json"}]}'
This creates or updates the configuration file at the specified location with the provided format.
Schemaโ
Get the JSON schema for the configuration resource:
oh-my-posh config dsc schema
Use this to understand the structure and available options for configuration states.
Managing shell Integrationโ
Bashโ
Configure Oh My Posh initialization for 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"}]}'
This automatically updates your .bashrc or .bash_profile with the Oh My Posh initialization command.
Zshโ
Configure Oh My Posh initialization for 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"}]}'
This automatically updates your .zshrc with the Oh My Posh initialization command.
PowerShellโ
Configure Oh My Posh initialization for 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"}]}'
This automatically updates your PowerShell profile with the Oh My Posh initialization command.
Fishโ
Configure Oh My Posh initialization for 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"}]}'
This automatically updates your fish config.fish with the Oh My Posh initialization command.
Orchestration with WinGetโ
WinGet configuration enables you to install Oh My Posh and apply configuration in a single declarative file.
Basic WinGet configurationโ
Create a configuration file to install and configure Oh My Posh:
$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
Apply the configuration:
winget configure oh-my-posh-setup.yaml
Complete setup with configuration and shellโ
This example installs Oh My Posh, adds your configuration, and initializes PowerShell:
$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
Apply with:
winget configure oh-my-posh-complete.yaml
Multi-shell configurationโ
Initialize multiple shells with different configurations:
$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 with Microsoft DSCโ
Microsoft DSC (dsc) provides cross-platform configuration management capabilities. Oh My Posh provides native DSC
resources that can be used in DSC configuration documents.
Example DSC configurationโ
Create a configuration document for Oh My Posh:
$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
Apply the configuration using the dsc CLI:
dsc config set --document oh-my-posh-dsc.yaml
Complete configuration with multiple shellsโ
$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
Resource Typesโ
Oh My Posh provides the following DSC resource types:
OhMyPosh/Configโ
Manages Oh My Posh configuration files.
Properties:
states(array): List of configuration statessource(string): Path to the configuration fileformat(string): Format of the configuration file (json,yaml,toml)
OhMyPosh/Shellโ
Manages shell initialization.
Properties:
states(array): List of shell configurationsname(string): Shell name (bash,zsh,pwsh,fish, etc.)command(string): Oh My Posh initialization command
OhMyPosh/Fontโ
Tracks installed Nerd Fonts. This resource is read-only and automatically populated when fonts are installed through Oh My Posh.
Configuration State Managementโ
DSC state is stored in the Oh My Posh cache and persists across sessions. This enables:
- State tracking: Oh My Posh remembers configurations set through DSC
- Idempotency: Running the same DSC command multiple times produces the same result
- State validation: Query current state before making changes
Advanced Usageโ
Multiple configurationsโ
You can manage multiple configuration files:
oh-my-posh config dsc set --state '{
"states": [
{"source":"~/work.omp.json","format":"json"},
{"source":"~/personal.omp.json","format":"json"}
]
}'
Shell-Specific Initializationโ
Initialize multiple shells with different configuration:
# 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"}]}'
Supported shellsโ
DSC shell configuration supports the following shells:
- bash: Configures
.bashrcor.bash_profile - zsh: Configures
.zshrc - fish: Configures
~/.config/fish/config.fish - pwsh: Configures PowerShell profile (
$PROFILE) - nu: Configures
~/.config/nushell/config.nu - elvish: Configures
.elvish/rc.elv - xonsh: Configures
.xonshrc
The shell integration automatically:
- Creates configuration files if they don't exist
- Updates existing Oh My Posh initialization commands
- Preserves shell-specific command syntax
- Maintains proper whitespace and formatting
See Alsoโ
- General configuration - Main configuration documentation
- Installation - Installing Oh My Posh
- Themes - Available themes
- WinGet configuration - WinGet DSC documentation
- Microsoft DSC - Microsoft DSC documentation