Last active
February 26, 2024 04:46
-
-
Save gingters/e9f081321624e72d54e2c62748939b60 to your computer and use it in GitHub Desktop.
Local Feature to install Oh-My-Posh in a devcontainer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
// this file goes to .devcontainer/features/oh-my-posh/ | |
"name": "oh-my-posh", | |
"description": "oh-my-posh", | |
"version": "0.1.0", | |
"options": { | |
"defaultTemplate": { | |
"type": "string", | |
"default": "jandedobbeleer", | |
"description": "The default oh-my-posh theme to use" | |
} | |
}, | |
"dependsOn": { | |
"ghcr.io/devcontainers/features/common-utils:2": { | |
"installZsh": false, | |
"installOhMyZsh": false, | |
"installOhMyZshConfig": false | |
}, | |
"ghcr.io/devcontainers/features/powershell:1": { | |
"version": "7.4.1", | |
"modules": "posh-git,z,PSFzf,Terminal-Icons" | |
}, | |
}, | |
"installsAfter": [ | |
"ghcr.io/devcontainers/features/powershell" | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
// this file goes to .devcontainer/ | |
"name": "your devcontainer", | |
"image": "mcr.microsoft.com/devcontainers/base:ubuntu-22.04", | |
"features": { | |
"ghcr.io/devcontainers/features/common-utils:2": { | |
"installZsh": false, | |
"installOhMyZsh": false, | |
"installOhMyZshConfig": false | |
}, | |
"ghcr.io/devcontainers/features/powershell:1": { | |
"version": "7.4.1", | |
"modules": "posh-git,z,PSFzf,Terminal-Icons" | |
}, | |
"./features/oh-my-posh": { | |
// optional: select one of the templates | |
"defaultTemplate": "tokyo" | |
} | |
}, | |
"customizations": { | |
"vscode": { | |
"settings": { | |
// optional: make pwsh the default shell in VS code terminal | |
"terminal.integrated.shell.linux": "/opt/microsoft/powershell/7/pwsh" | |
}, | |
"extensions": [ | |
// optional | |
"ms-vscode.powershell", | |
] | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# this file goes to .devcontainer/features/oh-my-posh/ | |
# makre sure we have fzf installed | |
apt-get update && apt-get install -y fzf | |
# Install oh-my-posh: | |
curl -s https://ohmyposh.dev/install.sh | bash -s | |
# Copy oh-my-posh cache (and themes) from root to the vscode user: | |
mkdir -p "${_REMOTE_USER_HOME}/.cache/oh-my-posh" | |
cp -R "/root/.cache/oh-my-posh/" "${_REMOTE_USER_HOME}/.cache/" | |
chmod 777 -R ${_REMOTE_USER_HOME}/.cache | |
# Can be used to override the devcontainer prompt default theme: | |
POSH_THEME="${_REMOTE_USER_HOME}/.cache/oh-my-posh/themes/${DEFAULTTEMPLATE}.omp.json" | |
# Copy the pwsh profile file, but replace the selected theme while doing that: | |
mkdir -p "${_REMOTE_USER_HOME}/.config/powershell" | |
awk "{gsub(/%POSHTHEMEFILE%/, \"${POSH_THEME}\")}1" < Microsoft.PowerShell_profile.ps1 > "${_REMOTE_USER_HOME}/.config/powershell/Microsoft.PowerShell_profile.ps1" | |
# make the .config folder and all files accessible (again) | |
chmod 777 -R "${_REMOTE_USER_HOME}/.config" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this file goes to .devcontainer/features/oh-my-posh/ | |
Import-Module posh-git | |
Import-Module PSFzf -ArgumentList 'Ctrl+t', 'Ctrl+r' | |
Import-Module z | |
Import-Module Terminal-Icons | |
Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete | |
$env:POSH_GIT_ENABLED=$true | |
$env:POSH_THEME_FILE="%POSHTHEMEFILE%" | |
oh-my-posh prompt init pwsh --config $env:POSH_THEME_FILE | Invoke-Expression |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment