mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-01-15 13:17:53 -08:00
parent
7c9cddf8f2
commit
17572d7f3f
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
||||
<Tabs
|
||||
defaultValue="powershell"
|
||||
groupId="shell"
|
||||
values={[
|
||||
{ label: 'powershell', value: 'powershell', },
|
||||
{ label: 'zsh', value: 'zsh', },
|
||||
{ label: 'bash', value: 'bash', },
|
||||
{ label: 'fish', value: 'fish', },
|
||||
]
|
||||
}>
|
||||
<TabItem value="powershell">
|
||||
|
||||
```powershell
|
||||
function Set-EnvVar {
|
||||
|
@ -41,6 +56,36 @@ function Set-EnvVar {
|
|||
New-Alias -Name 'Set-PoshContext' -Value 'Set-EnvVar' -Scope Global -Force
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
<TabItem value="zsh">
|
||||
|
||||
```bash
|
||||
function set_poshcontext() {
|
||||
export POSH=$(date)
|
||||
}
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
<TabItem value="bash">
|
||||
|
||||
```bash
|
||||
function set_poshcontext() {
|
||||
export POSH=$(date)
|
||||
}
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
<TabItem value="fish">
|
||||
|
||||
```shell
|
||||
function set_poshcontext
|
||||
set --export POSH $(date)
|
||||
end
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
:::
|
||||
|
||||
## Template logic
|
||||
|
|
Loading…
Reference in a new issue