website/docs/dsc.md
Oh My Posh supports Desired State Configuration (DSC) for declarative configuration management, enabling automated deployment and consistent configuration across multiple systems.
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:
These resources can be used standalone through the CLI or integrated with orchestration tools like WinGet and Microsoft DSC for automated deployments.
DSC support in Oh My Posh provides:
DSC functionality is available through the oh-my-posh CLI and can be used standalone or with orchestration tools.
Oh My Posh provides the following DSC resources:
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
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"}]}'
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
You can use the DSC commands directly from the command line for configuration management.
Retrieve the current configuration state:
oh-my-posh config dsc get
Example output:
{
"states": [
{
"format": "json",
"source": "~/mytheme.omp.json"
}
]
}
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.
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.
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.
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.
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.
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.
WinGet configuration enables you to install Oh My Posh and apply configuration in a single declarative file.
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
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
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
Microsoft DSC (dsc) provides cross-platform configuration management capabilities. Oh My Posh provides native DSC
resources that can be used in DSC configuration documents.
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
$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
Oh My Posh provides the following DSC resource types:
Manages Oh My Posh configuration files.
Properties:
states (array): List of configuration states
source (string): Path to the configuration fileformat (string): Format of the configuration file (json, yaml, toml)Manages shell initialization.
Properties:
states (array): List of shell configurations
name (string): Shell name (bash, zsh, pwsh, fish, etc.)command (string): Oh My Posh initialization commandTracks installed Nerd Fonts. This resource is read-only and automatically populated when fonts are installed through Oh My Posh.
DSC state is stored in the Oh My Posh cache and persists across sessions. This enables:
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"}
]
}'
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"}]}'
DSC shell configuration supports the following shells:
.bashrc or .bash_profile.zshrc~/.config/fish/config.fish$PROFILE)~/.config/nushell/config.nu.elvish/rc.elv.xonshrcThe shell integration automatically: