mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-01-28 11:31:04 -08:00
parent
7c9cddf8f2
commit
17572d7f3f
|
@ -12,6 +12,11 @@ function _omp_start_timer() {
|
||||||
::OMP:: get millis
|
::OMP:: get millis
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# template function for context loading
|
||||||
|
function set_poshcontext() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
function _omp_hook() {
|
function _omp_hook() {
|
||||||
local ret=$?
|
local ret=$?
|
||||||
local omp_stack_count=$((${#DIRSTACK[@]} - 1))
|
local omp_stack_count=$((${#DIRSTACK[@]} - 1))
|
||||||
|
@ -21,6 +26,7 @@ function _omp_hook() {
|
||||||
omp_elapsed=$((omp_now-omp_start_time))
|
omp_elapsed=$((omp_now-omp_start_time))
|
||||||
omp_start_time=""
|
omp_start_time=""
|
||||||
fi
|
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')"
|
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
|
return $ret
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,11 @@ set --global CONDA_PROMPT_MODIFIER false
|
||||||
set --global omp_tooltip_command ""
|
set --global omp_tooltip_command ""
|
||||||
set --global omp_transient 0
|
set --global omp_transient 0
|
||||||
|
|
||||||
|
# template function for context loading
|
||||||
|
function set_poshcontext
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
function fish_prompt
|
function fish_prompt
|
||||||
set --local omp_status_cache_temp $status
|
set --local omp_status_cache_temp $status
|
||||||
# clear from cursor to end of screen as
|
# clear from cursor to end of screen as
|
||||||
|
@ -28,7 +33,7 @@ function fish_prompt
|
||||||
if set --query status_generation
|
if set --query status_generation
|
||||||
set --global --export omp_last_status_generation $status_generation
|
set --global --export omp_last_status_generation $status_generation
|
||||||
end
|
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
|
::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
|
end
|
||||||
|
|
||||||
|
@ -94,6 +99,8 @@ end
|
||||||
|
|
||||||
# legacy functions
|
# legacy functions
|
||||||
function enable_poshtooltips
|
function enable_poshtooltips
|
||||||
|
return
|
||||||
end
|
end
|
||||||
function enable_poshtransientprompt
|
function enable_poshtransientprompt
|
||||||
|
return
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,6 +5,11 @@ export CONDA_PROMPT_MODIFIER=false
|
||||||
# set secondary prompt
|
# set secondary prompt
|
||||||
PS2="$(::OMP:: print secondary --config="$POSH_THEME" --shell=zsh)"
|
PS2="$(::OMP:: print secondary --config="$POSH_THEME" --shell=zsh)"
|
||||||
|
|
||||||
|
# template function for context loading
|
||||||
|
function set_poshcontext() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
function prompt_ohmyposh_preexec() {
|
function prompt_ohmyposh_preexec() {
|
||||||
omp_start_time=$(::OMP:: get millis)
|
omp_start_time=$(::OMP:: get millis)
|
||||||
}
|
}
|
||||||
|
@ -17,6 +22,7 @@ function prompt_ohmyposh_precmd() {
|
||||||
omp_now=$(::OMP:: get millis --shell=zsh)
|
omp_now=$(::OMP:: get millis --shell=zsh)
|
||||||
omp_elapsed=$(($omp_now-$omp_start_time))
|
omp_elapsed=$(($omp_now-$omp_start_time))
|
||||||
fi
|
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")"
|
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_start_time
|
||||||
unset omp_now
|
unset omp_now
|
||||||
|
|
|
@ -4,6 +4,9 @@ title: Templates
|
||||||
sidebar_label: 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.
|
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
|
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.
|
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 |
|
| `.Env.VarName` | `string` | Any environment variable where `VarName` is the environment variable name |
|
||||||
|
|
||||||
:::tip
|
:::tip
|
||||||
If you're using PowerShell, you can override a function to populate environment variables before the
|
For the shells below, you can override a function to execute some logic before the prompt is rendered.
|
||||||
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
|
```powershell
|
||||||
function Set-EnvVar {
|
function Set-EnvVar {
|
||||||
|
@ -41,6 +56,36 @@ function Set-EnvVar {
|
||||||
New-Alias -Name 'Set-PoshContext' -Value 'Set-EnvVar' -Scope Global -Force
|
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
|
## Template logic
|
||||||
|
|
Loading…
Reference in a new issue