diff --git a/src/shell/scripts/omp.bash b/src/shell/scripts/omp.bash index f3fb7489..b189db1c 100644 --- a/src/shell/scripts/omp.bash +++ b/src/shell/scripts/omp.bash @@ -12,6 +12,11 @@ function _omp_start_timer() { ::OMP:: get millis } +# template function for context loading +function set_poshcontext() { + return +} + function _omp_hook() { local ret=$? local omp_stack_count=$((${#DIRSTACK[@]} - 1)) @@ -21,6 +26,7 @@ function _omp_hook() { omp_elapsed=$((omp_now-omp_start_time)) omp_start_time="" fi + set_poshcontext PS1="$(::OMP:: print primary --config="$POSH_THEME" --shell=bash --shell-version="$BASH_VERSION" --error="$ret" --execution-time="$omp_elapsed" --stack-count="$omp_stack_count" | tr -d '\0')" return $ret } diff --git a/src/shell/scripts/omp.fish b/src/shell/scripts/omp.fish index 6e4afe91..a850b6ca 100644 --- a/src/shell/scripts/omp.fish +++ b/src/shell/scripts/omp.fish @@ -4,6 +4,11 @@ set --global CONDA_PROMPT_MODIFIER false set --global omp_tooltip_command "" set --global omp_transient 0 +# template function for context loading +function set_poshcontext + return +end + function fish_prompt set --local omp_status_cache_temp $status # clear from cursor to end of screen as @@ -28,7 +33,7 @@ function fish_prompt if set --query status_generation set --global --export omp_last_status_generation $status_generation end - + set_poshcontext ::OMP:: print primary --config $POSH_THEME --shell fish --error $omp_status_cache --execution-time $omp_duration --stack-count $omp_stack_count --shell-version $FISH_VERSION end @@ -94,6 +99,8 @@ end # legacy functions function enable_poshtooltips + return end function enable_poshtransientprompt + return end diff --git a/src/shell/scripts/omp.zsh b/src/shell/scripts/omp.zsh index 566ad06b..96ea47e6 100644 --- a/src/shell/scripts/omp.zsh +++ b/src/shell/scripts/omp.zsh @@ -5,6 +5,11 @@ export CONDA_PROMPT_MODIFIER=false # set secondary prompt PS2="$(::OMP:: print secondary --config="$POSH_THEME" --shell=zsh)" +# template function for context loading +function set_poshcontext() { + return +} + function prompt_ohmyposh_preexec() { omp_start_time=$(::OMP:: get millis) } @@ -17,6 +22,7 @@ function prompt_ohmyposh_precmd() { omp_now=$(::OMP:: get millis --shell=zsh) omp_elapsed=$(($omp_now-$omp_start_time)) fi + set_poshcontext eval "$(::OMP:: print primary --config="$POSH_THEME" --error="$omp_last_error" --execution-time="$omp_elapsed" --stack-count="$omp_stack_count" --eval --shell=zsh --shell-version="$ZSH_VERSION")" unset omp_start_time unset omp_now diff --git a/website/docs/configuration/templates.mdx b/website/docs/configuration/templates.mdx index 6299b3b0..08eeb019 100644 --- a/website/docs/configuration/templates.mdx +++ b/website/docs/configuration/templates.mdx @@ -4,6 +4,9 @@ title: Templates sidebar_label: Templates --- +import Tabs from "@theme/Tabs"; +import TabItem from "@theme/TabItem"; + Every segment has a `template` property to tweak the text that is displayed. Under the hood, this uses go's [text/template][go-text-template] feature extended with [sprig][sprig] and offers a few standard properties to work with. @@ -31,8 +34,20 @@ offers a few standard properties to work with. | `.Env.VarName` | `string` | Any environment variable where `VarName` is the environment variable name | :::tip -If you're using PowerShell, you can override a function to populate environment variables before the -prompt is rendered. +For the shells below, you can override a function to execute some logic before the prompt is rendered. +This can be used to for example populate an environment variable with a specific context. + + + ```powershell function Set-EnvVar { @@ -41,6 +56,36 @@ function Set-EnvVar { New-Alias -Name 'Set-PoshContext' -Value 'Set-EnvVar' -Scope Global -Force ``` + + + +```bash +function set_poshcontext() { + export POSH=$(date) +} +``` + + + + +```bash +function set_poshcontext() { + export POSH=$(date) +} +``` + + + + +```shell +function set_poshcontext + set --export POSH $(date) +end +``` + + + + ::: ## Template logic