oh my posh config for nu

This commit is contained in:
Daniel Bulant 2025-04-06 21:50:30 +02:00
parent c65071f9e8
commit 7190dc59f1
No known key found for this signature in database
8 changed files with 485 additions and 7 deletions

View file

@ -805,4 +805,7 @@ export-env {
} }
] ]
} }
# load oh-my-posh config
source ~/.oh-my-posh.nu
} }

View file

@ -0,0 +1,159 @@
version = 2
final_space = true
console_title_template = '{{ .Shell }} in {{ .Folder }}'
[[blocks]]
type = 'prompt'
alignment = 'left'
[[blocks.segments]]
type = 'session'
style = 'diamond'
leading_diamond = ''
trailing_diamond = ''
template = ' {{ if .SSHSession }} {{ end }}{{ .UserName }} '
background = 'p:yellow'
foreground = 'p:black'
[[blocks.segments]]
type = 'path'
style = 'powerline'
powerline_symbol = ''
template = '  {{ path .Path .Location }} '
background = 'p:orange'
foreground = 'p:white'
[blocks.segments.properties]
style = 'folder'
[[blocks.segments]]
type = 'git'
style = 'powerline'
powerline_symbol = ''
foreground_templates = ['{{ if or (.Working.Changed) (.Staging.Changed) }}p:black{{ end }}', '{{ if and (gt .Ahead 0) (gt .Behind 0) }}p:white{{ end }}', '{{ if gt .Ahead 0 }}p:white{{ end }}']
background_templates = ['{{ if or (.Working.Changed) (.Staging.Changed) }}p:yellow{{ end }}', '{{ if and (gt .Ahead 0) (gt .Behind 0) }}p:red{{ end }}', '{{ if gt .Ahead 0 }}#49416D{{ end }}', '{{ if gt .Behind 0 }}#7A306C{{ end }}']
template = ' {{ if .UpstreamURL }}{{ url .UpstreamIcon .UpstreamURL }} {{ end }}{{ .HEAD }}{{if .BranchStatus }} {{ .BranchStatus }}{{ end }}{{ if .Working.Changed }}  {{ .Working.String }}{{ end }}{{ if .Staging.Changed }}  {{ .Staging.String }}{{ end }} '
background = 'p:green'
foreground = 'p:black'
[blocks.segments.properties]
branch_max_length = 25
fetch_status = true
fetch_upstream_icon = true
[[blocks.segments]]
type = 'root'
style = 'powerline'
powerline_symbol = ''
template = '  '
background = 'p:yellow'
foreground = 'p:white'
[[blocks.segments]]
type = 'status'
style = 'diamond'
background_templates = ['{{ if gt .Code 0 }}p:red{{ end }}']
leading_diamond = '<transparent,background></>'
trailing_diamond = ''
template = ' {{ if gt .Code 0 }}{{ else }}{{ end }} '
background = 'p:blue'
foreground = 'p:white'
[blocks.segments.properties]
always_enabled = true
[[blocks]]
type = 'rprompt'
[[blocks.segments]]
type = 'node'
style = 'plain'
template = ' '
background = 'transparent'
foreground = 'p:green'
[blocks.segments.properties]
display_mode = 'files'
fetch_package_manager = false
home_enabled = false
[[blocks.segments]]
type = 'go'
style = 'plain'
template = ' '
background = 'transparent'
foreground = 'p:blue'
[blocks.segments.properties]
fetch_version = false
[[blocks.segments]]
type = 'python'
style = 'plain'
template = ' '
background = 'transparent'
foreground = 'p:yellow'
[blocks.segments.properties]
display_mode = 'files'
fetch_version = false
fetch_virtual_env = false
[[blocks.segments]]
type = 'shell'
style = 'plain'
template = 'in <p:blue><b>{{ .Name }}</b></> '
background = 'transparent'
foreground = 'p:white'
[[blocks.segments]]
type = 'time'
style = 'plain'
template = 'at <p:blue><b>{{ .CurrentDate | date "15:04:05" }}</b></>'
background = 'transparent'
foreground = 'p:white'
[[tooltips]]
type = 'aws'
tips = ['aws']
style = 'diamond'
leading_diamond = ''
trailing_diamond = ''
template = '  {{ .Profile }}{{ if .Region }}@{{ .Region }}{{ end }} '
background = 'p:orange'
foreground = 'p:white'
[tooltips.properties]
display_default = true
[[tooltips]]
type = 'az'
tips = ['az']
style = 'diamond'
leading_diamond = ''
trailing_diamond = ''
template = '  {{ .Name }} '
background = 'p:blue'
foreground = 'p:white'
[tooltips.properties]
display_default = true
[transient_prompt]
template = '<p:yellow,transparent></><,p:yellow> {{ .Folder }} </><p:yellow,transparent></> '
background = 'transparent'
foreground = 'p:black'
[secondary_prompt]
template = '<p:yellow,transparent></><,p:yellow> > </><p:yellow,transparent></> '
background = 'transparent'
foreground = 'p:black'
[palette]
black = '#262B44'
blue = '#4B95E9'
green = '#59C9A5'
orange = '#F07623'
red = '#D81E5B'
white = '#E0DEF4'
yellow = '#F3AE35'

View file

@ -0,0 +1,249 @@
{
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
"blocks": [
{
"alignment": "left",
"segments": [
{
"background": "#d3d7cf",
"foreground": "#5277C3",
"leading_diamond": "\u256d\u2500\ue0b2",
"style": "diamond",
"template": " {{ if .WSL }}WSL at {{ end }}{{.Icon}} ",
"type": "os"
},
{
"background": "#3465a4",
"foreground": "#e4e4e4",
"powerline_symbol": "\ue0b0",
"properties": {
"home_icon": "~",
"style": "full"
},
"style": "powerline",
"template": " \uf07c {{ .Path }} ",
"type": "path"
},
{
"background": "#4e9a06",
"background_templates": [
"{{ if or (.Working.Changed) (.Staging.Changed) }}#c4a000{{ end }}",
"{{ if and (gt .Ahead 0) (gt .Behind 0) }}#f26d50{{ end }}",
"{{ if gt .Ahead 0 }}#89d1dc{{ end }}",
"{{ if gt .Behind 0 }}#4e9a06{{ end }}"
],
"foreground": "#000000",
"powerline_symbol": "\ue0b0",
"properties": {
"branch_icon": "\uf126 ",
"fetch_stash_count": true,
"fetch_status": true,
"fetch_upstream_icon": true
},
"style": "powerline",
"template": " {{ .UpstreamIcon }}{{ .HEAD }}{{if .BranchStatus }} {{ .BranchStatus }}{{ end }}{{ if .Working.Changed }} \uf044 {{ .Working.String }}{{ end }}{{ if and (.Working.Changed) (.Staging.Changed) }} |{{ end }}{{ if .Staging.Changed }} \uf046 {{ .Staging.String }}{{ end }}{{ if gt .StashCount 0 }} \ueb4b {{ .StashCount }}{{ end }} ",
"type": "git"
}
],
"type": "prompt"
},
{
"alignment": "right",
"segments": [
{
"type": "rust",
"style": "powerline",
"powerline_symbol": "\ue0b2",
"invert_powerline": true,
"properties": {
"fetch_version": true
},
"foreground": "#193549",
"background": "#99908a",
"template": "  {{ .Full }} \ue718 "
},
{
"background": "#689f63",
"foreground": "#ffffff",
"invert_powerline": true,
"powerline_symbol": "\ue0b2",
"properties": {
"fetch_version": true
},
"style": "powerline",
"template": " {{ if .PackageManagerIcon }}{{ .PackageManagerIcon }} {{ end }}{{ .Full }} \ue718 ",
"type": "node"
},
{
"background": "#1976d2",
"foreground": "#ffffff",
"invert_powerline": true,
"powerline_symbol": "\ue0b2",
"properties": {
"fetch_version": true
},
"style": "powerline",
"template": " {{ .Full }} \ue718 ",
"type": "svelte"
},
{
"background": "#00acd7",
"foreground": "#111111",
"invert_powerline": true,
"powerline_symbol": "\ue0b2",
"properties": {
"fetch_version": true
},
"style": "powerline",
"template": " {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }} \ue627 ",
"type": "go"
},
{
"background": "#4063D8",
"foreground": "#111111",
"invert_powerline": true,
"powerline_symbol": "\ue0b2",
"properties": {
"fetch_version": true
},
"style": "powerline",
"template": " {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }} \ue624 ",
"type": "julia"
},
{
"background": "#FFDE57",
"foreground": "#111111",
"invert_powerline": true,
"powerline_symbol": "\ue0b2",
"properties": {
"display_mode": "files",
"fetch_virtual_env": false
},
"style": "powerline",
"template": " {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }} \ue235 ",
"type": "python"
},
{
"background": "#AE1401",
"foreground": "#ffffff",
"invert_powerline": true,
"powerline_symbol": "\ue0b2",
"properties": {
"display_mode": "files",
"fetch_version": true
},
"style": "powerline",
"template": " {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }} \ue791 ",
"type": "ruby"
},
{
"background": "#FEAC19",
"foreground": "#ffffff",
"invert_powerline": true,
"powerline_symbol": "\ue0b2",
"properties": {
"display_mode": "files",
"fetch_version": false
},
"style": "powerline",
"template": " {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }} \uf0e7",
"type": "azfunc"
},
{
"background_templates": [
"{{if contains \"default\" .Profile}}#FFA400{{end}}",
"{{if contains \"jan\" .Profile}}#f1184c{{end}}"
],
"foreground": "#ffffff",
"invert_powerline": true,
"powerline_symbol": "\ue0b2",
"properties": {
"display_default": false
},
"style": "powerline",
"template": " {{ .Profile }}{{ if .Region }}@{{ .Region }}{{ end }} \ue7ad ",
"type": "aws"
},
{
"background": "#ffff66",
"foreground": "#111111",
"invert_powerline": true,
"powerline_symbol": "\ue0b2",
"style": "powerline",
"template": " \uf0ad ",
"type": "root"
},
{
"type": "nix-shell",
"style": "powerline",
"invert_powerline": true,
"powerline_symbol": "\ue0b2",
"foreground": "#000000",
"background": "#7EBAE4",
"template": "  {{ .Type }} "
},
{
"background": "#c4a000",
"foreground": "#000000",
"invert_powerline": true,
"powerline_symbol": "\ue0b2",
"style": "powerline",
"template": " {{ .FormattedMs }} \uf252 ",
"type": "executiontime"
},
{
"background": "#000000",
"background_templates": [
"{{ if gt .Code 0 }}#cc2222{{ end }}"
],
"foreground": "#d3d7cf",
"invert_powerline": true,
"powerline_symbol": "\ue0b2",
"properties": {
"always_enabled": true
},
"style": "powerline",
"template": " {{ if gt .Code 0 }}{{ reason .Code }}{{ else }}\uf42e{{ end }} ",
"type": "status"
},
{
"background": "#d3d7cf",
"foreground": "#000000",
"invert_powerline": true,
"style": "diamond",
"template": " {{ .CurrentDate | date .Format }} \uf017 ",
"trailing_diamond": "\ue0b0\u2500\u256e",
"type": "time"
}
],
"type": "prompt"
},
{
"alignment": "left",
"newline": true,
"segments": [
{
"foreground": "#d3d7cf",
"style": "plain",
"template": "\u2570\u2500",
"type": "text"
}
],
"type": "prompt"
},
{
"segments": [
{
"foreground": "#d3d7cf",
"style": "plain",
"template": "\u2500\u256f",
"type": "text"
}
],
"type": "rprompt"
}
],
"console_title_template": "{{ .Shell }} in {{ .Folder }}",
"final_space": true,
"version": 3
}

68
.oh-my-posh.nu Executable file
View file

@ -0,0 +1,68 @@
# make sure we have the right prompt render correctly
if ($env.config? | is-not-empty) {
$env.config = ($env.config | upsert render_right_prompt_on_last_line true)
}
$env.POWERLINE_COMMAND = 'oh-my-posh'
$env.POSH_THEME = '/home/dan/.config/oh-my-posh/powerlevel10k_rainbow.omp.json'
$env.PROMPT_INDICATOR = ""
$env.POSH_SESSION_ID = (echo "ed3af1b9-5277-4c80-9fbe-daaaf73eabb3")
$env.POSH_SHELL_VERSION = (version | get version)
let _omp_executable: string = (which oh-my-posh | first | get path)
# PROMPTS
def --wrapped _omp_get_prompt [
type: string,
...args: string
] {
mut execution_time = -1
mut no_status = true
# We have to do this because the initial value of `$env.CMD_DURATION_MS` is always `0823`, which is an official setting.
# See https://github.com/nushell/nushell/discussions/6402#discussioncomment-3466687.
if $env.CMD_DURATION_MS != '0823' {
$execution_time = $env.CMD_DURATION_MS
$no_status = false
}
(
^$_omp_executable print $type
--save-cache
--shell=nu
$"--shell-version=($env.POSH_SHELL_VERSION)"
$"--status=($env.LAST_EXIT_CODE)"
$"--no-status=($no_status)"
$"--execution-time=($execution_time)"
$"--terminal-width=((term size).columns)"
...$args
)
}
$env.PROMPT_MULTILINE_INDICATOR = (
^$_omp_executable print secondary
--shell=nu
$"--shell-version=($env.POSH_SHELL_VERSION)"
)
$env.PROMPT_COMMAND = {||
# hack to set the cursor line to 1 when the user clears the screen
# this obviously isn't bulletproof, but it's a start
mut clear = false
if $nu.history-enabled {
$clear = (history | is-empty) or ((history | last 1 | get 0.command) == "clear")
}
if ($env.SET_POSHCONTEXT? | is-not-empty) {
do --env $env.SET_POSHCONTEXT
}
_omp_get_prompt primary $"--cleared=($clear)"
}
$env.PROMPT_COMMAND_RIGHT = {|| _omp_get_prompt right }
$env.TRANSIENT_PROMPT_COMMAND = {|| _omp_get_prompt transient }
# nix updates may be delayed, just depend on them instead of notices
# ^$_omp_executable notice

View file

@ -127,7 +127,7 @@
isNormalUser = true; isNormalUser = true;
description = "John"; description = "John";
extraGroups = [ "networkmanager" "wheel" "docker" "fuse" "video" "wireshark" "gamemode" "scanner" "lp"]; extraGroups = [ "networkmanager" "wheel" "docker" "fuse" "video" "wireshark" "gamemode" "scanner" "lp"];
shell = pkgs.fish; shell = pkgs.nushell;
packages = with pkgs; [ packages = with pkgs; [
kdePackages.kate kdePackages.kate
zen-browser.packages."${system}".specific zen-browser.packages."${system}".specific

View file

@ -1,4 +1,5 @@
echo "Copying configurations" echo "Copying configurations"
cp .config/* ~/.config/ -r cp .config/* ~/.config/ -r
cp .default-python-packages ~ cp .default-python-packages ~
cp .oh-my-posh.nu ~

View file

@ -249,8 +249,8 @@ in
# configFile.source = ./.config/nushell/base-config.nu; # configFile.source = ./.config/nushell/base-config.nu;
configFile.text = ''use base-config.nu''; configFile.text = ''use base-config.nu'';
shellAliases = { shellAliases = {
ns = "nix-shell --run nushell"; ns = "nix-shell --run nu";
nsp = "nix-shell --run nushell -p"; nsp = "nix-shell --run nu -p";
}; };
}; };
vscode = { vscode = {

View file

@ -1,7 +1,5 @@
#!/bin/bash #!/bin/bash
echo "Copying configurations" sh fast-copy.sh
cp .config/* ~/.config/ -r
cp .default-python-packages ~
if [ -z "$(which nh)" ]; then if [ -z "$(which nh)" ]; then
sudo cp *.nix /etc/nixos/ sudo cp *.nix /etc/nixos/
sudo nixos-rebuild switch --show-trace sudo nixos-rebuild switch --show-trace