Oh My Posh - segments for SAP devs
Oh-My-Posh is a prompt theme engine for any shell. Strictly speaking,
it is a way to make your terminal look awesome (theming) when displaying additional information
(like installed tool versions or CPU usage). And it is highly customizable. What more could you
want? Well, SAP development related stuff for your daily hard work enjoyable coding adventures.
Contextual information in the prompt is really handy if you have multiple environments and multiple
apps between which you jump quite often.
Recently, I was working on several segments related to SAP development and they are now available on Oh My Posh. From version >= 7.34.0 you can use a segment for:
- UI5 tooling version
- Cloud Foundry CLI version
- Cloud Foundry Target - shows the details of
cf target
, which org and space you are logged in - cds (SAP CAP) CLI version
The next segment will be for SAP HANA CLI and the environment used. It is ready but needs to be refactored to the latest changes in Oh My Posh.
How to use segments?
- Install/update Oh My Posh.
- Pick your theme and get the theme file for local modifications. These steps are very well documented, so I won't be rewriting them here.
Next, you can add the segments you want to the local theme file. Segments can be shown always or when some conditions are fulfilled (check the docs for details).
Here is what it can look like when manifest.yml and ui5.yaml files are present; I'm also logged into my BTP Cloud Foundry Trial account.
The complete file for the above, based on the nu4a theme:
{
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
"blocks":
[
{
"alignment": "left",
"segments":
[
{
"background": "#cfcfc4",
"background_templates":
["{{if .Root}}#ff3026{{else}}#cfcfc4{{end}}"],
"foreground": "#100e23",
"properties":
{
"display_host": false,
"template": "{{if .Root}} \uf0e7 {{.UserName}} {{else}} {{.UserName}} {{end}}",
},
"style": "powerline",
"type": "session",
},
{
"background": "#acacac",
"foreground": "#100e23",
"powerline_symbol": "\ue0b0",
"properties":
{
"folder_icon": "\ue5ff",
"folder_separator_icon": "\ue0b9",
"home_icon": "\uf7db",
"mapped_locations":
{ "C:\\Users": "\uf007", "C:\\Windows": "\ue62a" },
"mixed_threshold": 8,
"style": "mixed",
"template": " {{ .Path }} ",
},
"style": "powerline",
"type": "path",
},
{
"background": "#3feb56",
"foreground": "#193549",
"powerline_symbol": "\ue0b0",
"properties": { "template": " {{ .HEAD }}" },
"style": "powerline",
"type": "git",
},
{
"background": "#f5a834",
"foreground": "#100e23",
"powerline_symbol": "\ue0b0",
"properties":
{
"template": " \ufab6ui5 {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }} ",
},
"style": "powerline",
"type": "ui5tooling",
},
{
"background": "#a7cae1",
"foreground": "#100e23",
"powerline_symbol": "\ue0b0",
"properties":
{
"template": " \uf40a cf {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }} ",
"display_mode": "context",
},
"style": "powerline",
"type": "cf",
},
{
"background": "#a7cae1",
"foreground": "#100e23",
"powerline_symbol": "\ue0b0",
"properties":
{
"template": " \ue311 cds {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }} ",
"display_mode": "context",
},
"style": "powerline",
"type": "cds",
},
],
"type": "prompt",
},
{
"alignment": "right",
"segments":
[
{
"background": "#a7cae1",
"foreground": "#100e23",
"leading_diamond": "\ue0c2",
"properties": { "template": " \uf40a {{ .Org }}/{{ .Space }}" },
"style": "diamond",
"trailing_diamond": "\ue0c0",
"type": "cftarget",
},
{
"background": "#ff4040",
"foreground": "#ffffff",
"leading_diamond": "\ue0c2",
"properties": { "template": " \ue70f " },
"style": "diamond",
"trailing_diamond": "\ue0c0",
"type": "exit",
},
{
"background": "#2f2f2f",
"foreground": "#fafafa",
"leading_diamond": "\ue0b2",
"properties":
{ "style": "austin", "template": " {{ .FormattedMs }} " },
"style": "diamond",
"type": "executiontime",
},
],
"type": "rprompt",
},
],
"console_title": true,
"console_title_style": "template",
"console_title_template": "{{if .Root}} \u26a1 {{end}}{{.UserName}} \u2794 📁{{.Folder}}",
"final_space": true,
"version": 1,
}