mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-03-05 20:49:04 -08:00
feat: remove functions to enable prompt features
This commit is contained in:
parent
4d1f8f4ea0
commit
35efd3cf00
|
@ -2,6 +2,7 @@ package cli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"oh-my-posh/engine"
|
||||||
"oh-my-posh/environment"
|
"oh-my-posh/environment"
|
||||||
"oh-my-posh/shell"
|
"oh-my-posh/shell"
|
||||||
|
|
||||||
|
@ -56,6 +57,10 @@ func runInit(shellName string) {
|
||||||
}
|
}
|
||||||
env.Init()
|
env.Init()
|
||||||
defer env.Close()
|
defer env.Close()
|
||||||
|
cfg := engine.LoadConfig(env)
|
||||||
|
shell.Transient = cfg.TransientPrompt != nil
|
||||||
|
shell.ErrorLine = cfg.ErrorLine != nil || cfg.ValidLine != nil
|
||||||
|
shell.Tooltips = len(cfg.Tooltips) > 0
|
||||||
if print {
|
if print {
|
||||||
init := shell.PrintInit(env)
|
init := shell.PrintInit(env)
|
||||||
fmt.Print(init)
|
fmt.Print(init)
|
||||||
|
|
|
@ -123,11 +123,6 @@ func loadConfig(env environment.Environment) *Config {
|
||||||
err = config.BindStruct("", &cfg)
|
err = config.BindStruct("", &cfg)
|
||||||
cfg.exitWithError(err)
|
cfg.exitWithError(err)
|
||||||
|
|
||||||
// initialize default values
|
|
||||||
if cfg.TransientPrompt == nil {
|
|
||||||
cfg.TransientPrompt = &Segment{}
|
|
||||||
}
|
|
||||||
|
|
||||||
return &cfg
|
return &cfg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package shell
|
||||||
import (
|
import (
|
||||||
_ "embed"
|
_ "embed"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"oh-my-posh/environment"
|
"oh-my-posh/environment"
|
||||||
|
@ -33,6 +34,12 @@ const (
|
||||||
noExe = "echo \"Unable to find Oh My Posh executable\""
|
noExe = "echo \"Unable to find Oh My Posh executable\""
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
Transient bool
|
||||||
|
ErrorLine bool
|
||||||
|
Tooltips bool
|
||||||
|
)
|
||||||
|
|
||||||
func getExecutablePath(env environment.Environment) (string, error) {
|
func getExecutablePath(env environment.Environment) (string, error) {
|
||||||
executable, err := os.Executable()
|
executable, err := os.Executable()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -102,6 +109,9 @@ func PrintInit(env environment.Environment) string {
|
||||||
func getShellInitScript(executable, configFile, script string) string {
|
func getShellInitScript(executable, configFile, script string) string {
|
||||||
script = strings.ReplaceAll(script, "::OMP::", executable)
|
script = strings.ReplaceAll(script, "::OMP::", executable)
|
||||||
script = strings.ReplaceAll(script, "::CONFIG::", configFile)
|
script = strings.ReplaceAll(script, "::CONFIG::", configFile)
|
||||||
|
script = strings.ReplaceAll(script, "::TRANSIENT::", strconv.FormatBool(Transient))
|
||||||
|
script = strings.ReplaceAll(script, "::ERROR_LINE::", strconv.FormatBool(ErrorLine))
|
||||||
|
script = strings.ReplaceAll(script, "::TOOLTIPS::", strconv.FormatBool(Tooltips))
|
||||||
return script
|
return script
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,7 @@ function _render_tooltip
|
||||||
commandline --function repaint
|
commandline --function repaint
|
||||||
end
|
end
|
||||||
|
|
||||||
function enable_poshtooltips
|
if test "::TOOLTIPS::" = "true"
|
||||||
bind \x20 _render_tooltip
|
bind \x20 _render_tooltip
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -76,6 +76,12 @@ function _render_transient
|
||||||
commandline --function execute
|
commandline --function execute
|
||||||
end
|
end
|
||||||
|
|
||||||
function enable_poshtransientprompt
|
if test "::TRANSIENT::" = "true"
|
||||||
bind \r _render_transient
|
bind \r _render_transient
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# legacy functions
|
||||||
|
function enable_poshtooltips
|
||||||
|
end
|
||||||
|
function enable_poshtransientprompt
|
||||||
|
end
|
||||||
|
|
|
@ -100,7 +100,7 @@ New-Module -Name "oh-my-posh-core" -ScriptBlock {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Enable-PoshTooltips {
|
if ("::TOOLTIPS::" -eq "true") {
|
||||||
Set-PSReadLineKeyHandler -Key SpaceBar -ScriptBlock {
|
Set-PSReadLineKeyHandler -Key SpaceBar -ScriptBlock {
|
||||||
[Microsoft.PowerShell.PSConsoleReadLine]::Insert(' ')
|
[Microsoft.PowerShell.PSConsoleReadLine]::Insert(' ')
|
||||||
$position = $host.UI.RawUI.CursorPosition
|
$position = $host.UI.RawUI.CursorPosition
|
||||||
|
@ -116,7 +116,7 @@ New-Module -Name "oh-my-posh-core" -ScriptBlock {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Enable-PoshTransientPrompt {
|
if ("::TRANSIENT::" -eq "true") {
|
||||||
Set-PSReadLineKeyHandler -Key Enter -ScriptBlock {
|
Set-PSReadLineKeyHandler -Key Enter -ScriptBlock {
|
||||||
$previousOutputEncoding = [Console]::OutputEncoding
|
$previousOutputEncoding = [Console]::OutputEncoding
|
||||||
try {
|
try {
|
||||||
|
@ -145,7 +145,7 @@ New-Module -Name "oh-my-posh-core" -ScriptBlock {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Enable-PoshLineError {
|
if ("::ERROR_LINE::" -eq "true") {
|
||||||
$validLine = @(Start-Utf8Process $script:OMPExecutable @("print", "valid", "--config=$env:POSH_THEME", "--shell=$script:ShellName")) -join "`n"
|
$validLine = @(Start-Utf8Process $script:OMPExecutable @("print", "valid", "--config=$env:POSH_THEME", "--shell=$script:ShellName")) -join "`n"
|
||||||
$errorLine = @(Start-Utf8Process $script:OMPExecutable @("print", "error", "--config=$env:POSH_THEME", "--shell=$script:ShellName")) -join "`n"
|
$errorLine = @(Start-Utf8Process $script:OMPExecutable @("print", "error", "--config=$env:POSH_THEME", "--shell=$script:ShellName")) -join "`n"
|
||||||
Set-PSReadLineOption -PromptText $validLine, $errorLine
|
Set-PSReadLineOption -PromptText $validLine, $errorLine
|
||||||
|
@ -344,6 +344,11 @@ Example:
|
||||||
# set secondary prompt
|
# set secondary prompt
|
||||||
Set-PSReadLineOption -ContinuationPrompt (@(Start-Utf8Process $script:OMPExecutable @("print", "secondary", "--config=$env:POSH_THEME", "--shell=$script:ShellName")) -join "`n")
|
Set-PSReadLineOption -ContinuationPrompt (@(Start-Utf8Process $script:OMPExecutable @("print", "secondary", "--config=$env:POSH_THEME", "--shell=$script:ShellName")) -join "`n")
|
||||||
|
|
||||||
|
# legacy functions
|
||||||
|
function Enable-PoshTooltips {}
|
||||||
|
function Enable-PoshTransientPrompt {}
|
||||||
|
function Enable-PoshLineError {}
|
||||||
|
|
||||||
Export-ModuleMember -Function @(
|
Export-ModuleMember -Function @(
|
||||||
"Set-PoshContext"
|
"Set-PoshContext"
|
||||||
"Enable-PoshTooltips"
|
"Enable-PoshTooltips"
|
||||||
|
|
|
@ -60,9 +60,9 @@ function self-insert() {
|
||||||
zle .self-insert
|
zle .self-insert
|
||||||
}
|
}
|
||||||
|
|
||||||
function enable_poshtooltips() {
|
if [[ "::TOOLTIPS::" = "true" ]]; then
|
||||||
zle -N self-insert
|
zle -N self-insert
|
||||||
}
|
fi
|
||||||
|
|
||||||
_posh-zle-line-init() {
|
_posh-zle-line-init() {
|
||||||
[[ $CONTEXT == start ]] || return 0
|
[[ $CONTEXT == start ]] || return 0
|
||||||
|
@ -91,6 +91,10 @@ _posh-zle-line-init() {
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
function enable_poshtransientprompt() {
|
if [[ "::TRANSIENT::" = "true" ]]; then
|
||||||
zle -N zle-line-init _posh-zle-line-init
|
zle -N zle-line-init _posh-zle-line-init
|
||||||
}
|
fi
|
||||||
|
|
||||||
|
# legacy functions for backwards compatibility
|
||||||
|
function enable_poshtooltips() {}
|
||||||
|
function enable_poshtransientprompt() {}
|
||||||
|
|
|
@ -20,7 +20,8 @@ There are two config settings you need to tweak:
|
||||||
- `error_line`: displays when the line is faulty
|
- `error_line`: displays when the line is faulty
|
||||||
|
|
||||||
You can use go [text/template][go-text-template] templates extended with [sprig][sprig] to enrich the text.
|
You can use go [text/template][go-text-template] templates extended with [sprig][sprig] to enrich the text.
|
||||||
Environment variables are available, just like the [`console_title_template`][console-title] functionality.
|
All [template][templates] functionality is available, even reusing [cross segment template properties][cstp] from
|
||||||
|
the previous primary prompt run.
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
|
@ -49,35 +50,7 @@ The configuration has the following properties:
|
||||||
|
|
||||||
- background: `string` [color][colors]
|
- background: `string` [color][colors]
|
||||||
- foreground: `string` [color][colors]
|
- foreground: `string` [color][colors]
|
||||||
- template: `string` - a go [text/template][go-text-template] template extended with [sprig][sprig] utilizing the
|
- template: `string` - a fully featured [template][templates] - defaults to ` `
|
||||||
properties below - defaults to ` `
|
|
||||||
|
|
||||||
## Template ([info][templates])
|
|
||||||
|
|
||||||
- `.Root`: `boolean` - is the current user root/admin or not
|
|
||||||
- `.PWD`: `string` - the current working directory
|
|
||||||
- `.Folder`: `string` - the current working folder
|
|
||||||
- `.Shell`: `string` - the current shell name
|
|
||||||
- `.UserName`: `string` - the current user name
|
|
||||||
- `.HostName`: `string` - the host name
|
|
||||||
- `.Env.VarName`: `string` - Any environment variable where `VarName` is the environment variable name
|
|
||||||
|
|
||||||
## Enable the feature
|
|
||||||
|
|
||||||
Invoke Oh My Posh in your `$PROFILE` and add the following line below.
|
|
||||||
|
|
||||||
```powershell
|
|
||||||
oh-my-posh init pwsh --config $env:POSH_THEMES_PATH/jandedobbeleer.omp.json | Invoke-Expression
|
|
||||||
// highlight-start
|
|
||||||
Enable-PoshLineError
|
|
||||||
// highlight-end
|
|
||||||
```
|
|
||||||
|
|
||||||
:::caution
|
|
||||||
If you import **PSReadLine** separately, make sure to import it before the `Enable-PoshLineError` command.
|
|
||||||
:::
|
|
||||||
|
|
||||||
Restart your shell or reload your `$PROFILE` using `. $PROFILE` for the changes to take effect.
|
|
||||||
|
|
||||||
[colors]: /docs/configuration/colors
|
[colors]: /docs/configuration/colors
|
||||||
[go-text-template]: https://golang.org/pkg/text/template/
|
[go-text-template]: https://golang.org/pkg/text/template/
|
||||||
|
@ -85,3 +58,4 @@ Restart your shell or reload your `$PROFILE` using `. $PROFILE` for the changes
|
||||||
[console-title]: /docs/configuration/title#console-title-template
|
[console-title]: /docs/configuration/title#console-title-template
|
||||||
[psreadline]: https://github.com/PowerShell/PSReadLine
|
[psreadline]: https://github.com/PowerShell/PSReadLine
|
||||||
[templates]: /docs/configuration/templates
|
[templates]: /docs/configuration/templates
|
||||||
|
[cstp]: /docs/configuration/templates#cross-segment-template-properties
|
||||||
|
|
|
@ -53,58 +53,4 @@ This configuration will render a right-aligned git segment when you type `git` o
|
||||||
A tip should not include any leading or trailing space but an interpolated one can be used, e.g., `g s`.
|
A tip should not include any leading or trailing space but an interpolated one can be used, e.g., `g s`.
|
||||||
Keep in mind that this is a blocking call, meaning that if the segment renders slow, you can't type until it's visible. Optimizations in this space are being explored.
|
Keep in mind that this is a blocking call, meaning that if the segment renders slow, you can't type until it's visible. Optimizations in this space are being explored.
|
||||||
|
|
||||||
## Enable the feature
|
|
||||||
|
|
||||||
<Tabs
|
|
||||||
defaultValue="pwsh"
|
|
||||||
groupId="shell"
|
|
||||||
values={[
|
|
||||||
{ label: 'powershell', value: 'pwsh', },
|
|
||||||
{ label: 'zsh', value: 'zsh', },
|
|
||||||
{ label: 'fish', value: 'fish', },
|
|
||||||
]
|
|
||||||
}>
|
|
||||||
<TabItem value="pwsh">
|
|
||||||
|
|
||||||
Import/invoke Oh My Posh in your `$PROFILE` and add the following line below:
|
|
||||||
|
|
||||||
```powershell
|
|
||||||
Enable-PoshTooltips
|
|
||||||
```
|
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
```powershell
|
|
||||||
# $PROFILE
|
|
||||||
oh-my-posh init pwsh --config ~\wildertheme.json | Invoke-Expression
|
|
||||||
Enable-PoshTooltips
|
|
||||||
```
|
|
||||||
|
|
||||||
Restart your shell or reload your `$PROFILE` using `. $PROFILE` for the changes to take effect.
|
|
||||||
|
|
||||||
</TabItem>
|
|
||||||
<TabItem value="zsh">
|
|
||||||
|
|
||||||
Invoke Oh My Posh in `.zshrc` and add the following line below:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
enable_poshtooltips
|
|
||||||
```
|
|
||||||
|
|
||||||
Restart your shell or reload `.zshrc` using `exec zsh` for the changes to take effect.
|
|
||||||
|
|
||||||
</TabItem>
|
|
||||||
<TabItem value="fish">
|
|
||||||
|
|
||||||
Invoke Oh My Posh in `~/.config/fish/config.fish` and add the following line below:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
enable_poshtooltips
|
|
||||||
```
|
|
||||||
|
|
||||||
Restart your shell or reload fish using `exec fish` for the changes to take effect.
|
|
||||||
|
|
||||||
</TabItem>
|
|
||||||
</Tabs>
|
|
||||||
|
|
||||||
[clink]: https://chrisant996.github.io/clink/
|
[clink]: https://chrisant996.github.io/clink/
|
||||||
|
|
|
@ -13,7 +13,8 @@ This feature only works in `fish`, `zsh`, `powershell` and `cmd` for the time be
|
||||||
|
|
||||||
Transient prompt, when enabled, replaces the prompt with a simpler one to allow more screen real estate.
|
Transient prompt, when enabled, replaces the prompt with a simpler one to allow more screen real estate.
|
||||||
You can use go [text/template][go-text-template] templates extended with [sprig][sprig] to enrich the text.
|
You can use go [text/template][go-text-template] templates extended with [sprig][sprig] to enrich the text.
|
||||||
Environment variables are available, just like the [`console_title_template`][console-title] functionality.
|
All [template][templates] functionality is available, even reusing [cross segment template properties][cstp] from
|
||||||
|
the previous primary prompt run.
|
||||||
|
|
||||||
Typically, your prompt will simply leave the prompt on the screen when you execute a command (or press enter) like so:
|
Typically, your prompt will simply leave the prompt on the screen when you execute a command (or press enter) like so:
|
||||||
|
|
||||||
|
@ -48,86 +49,17 @@ The configuration has the following properties:
|
||||||
- foreground_templates: foreground [color templates][color-templates]
|
- foreground_templates: foreground [color templates][color-templates]
|
||||||
- background: `string` [color][colors]
|
- background: `string` [color][colors]
|
||||||
- background_templates: background [color templates][color-templates]
|
- background_templates: background [color templates][color-templates]
|
||||||
- template: `string` - a go [text/template][go-text-template] template extended with [sprig][sprig] utilizing the
|
- template: `string` - a fully featured [template][templates] - defaults to `{{ .Shell }}> `
|
||||||
properties below - defaults to `{{ .Shell }}> `
|
|
||||||
|
|
||||||
## Template ([info][templates])
|
|
||||||
|
|
||||||
- `.Root`: `boolean` - is the current user root/admin or not
|
|
||||||
- `.PWD`: `string` - the current working directory
|
|
||||||
- `.Folder`: `string` - the current working folder
|
|
||||||
- `.Shell`: `string` - the current shell name
|
|
||||||
- `.UserName`: `string` - the current user name
|
|
||||||
- `.HostName`: `string` - the host name
|
|
||||||
- `.Code`: `int` - the last exit code
|
|
||||||
- `.Env.VarName`: `string` - Any environment variable where `VarName` is the environment variable name
|
|
||||||
|
|
||||||
## Enable the feature
|
## Enable the feature
|
||||||
|
|
||||||
<Tabs
|
Oh My posh handles enabling the feature automatically for all shells except `cmd` when the config contains a
|
||||||
defaultValue="pwsh"
|
transient prompt configuration. For `cmd`, you can run the command below once to enable the feature permanently:
|
||||||
groupId="shell"
|
|
||||||
values={[
|
|
||||||
{ label: 'powershell', value: 'pwsh', },
|
|
||||||
{ label: 'cmd', value: 'cmd', },
|
|
||||||
{ label: 'zsh', value: 'zsh', },
|
|
||||||
{ label: 'fish', value: 'fish', },
|
|
||||||
]
|
|
||||||
}>
|
|
||||||
<TabItem value="pwsh">
|
|
||||||
|
|
||||||
|
|
||||||
Invoke Oh My Posh in your `$PROFILE` and add the following line below.
|
|
||||||
|
|
||||||
```powershell
|
|
||||||
oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH/jandedobbeleer.omp.json" | Invoke-Expression
|
|
||||||
// highlight-start
|
|
||||||
Enable-PoshTransientPrompt
|
|
||||||
// highlight-end
|
|
||||||
```
|
|
||||||
|
|
||||||
:::caution
|
|
||||||
If you import **PSReadLine** separately, make sure to import it before the `Enable-PoshTransientPrompt` command.
|
|
||||||
:::
|
|
||||||
|
|
||||||
Restart your shell or reload your `$PROFILE` using `. $PROFILE` for the changes to take effect.
|
|
||||||
|
|
||||||
</TabItem>
|
|
||||||
<TabItem value="cmd">
|
|
||||||
|
|
||||||
You can run the command below to enable the feature permanently:
|
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
clink set prompt.transient always
|
clink set prompt.transient always
|
||||||
```
|
```
|
||||||
|
|
||||||
Restart your shell for the changes to take effect.
|
|
||||||
|
|
||||||
</TabItem>
|
|
||||||
<TabItem value="zsh">
|
|
||||||
|
|
||||||
Invoke Oh My Posh in `.zshrc` and add the following line below:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
enable_poshtransientprompt
|
|
||||||
```
|
|
||||||
|
|
||||||
Restart your shell or reload `.zshrc` using `exec zsh` for the changes to take effect.
|
|
||||||
|
|
||||||
</TabItem>
|
|
||||||
<TabItem value="fish">
|
|
||||||
|
|
||||||
Invoke Oh My Posh in `~/.config/fish/config.fish` and add the following line below:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
enable_poshtransientprompt
|
|
||||||
```
|
|
||||||
|
|
||||||
Restart your shell or reload fish using `exec fish` for the changes to take effect.
|
|
||||||
|
|
||||||
</TabItem>
|
|
||||||
</Tabs>
|
|
||||||
|
|
||||||
[colors]: /docs/configuration/colors
|
[colors]: /docs/configuration/colors
|
||||||
[go-text-template]: https://golang.org/pkg/text/template/
|
[go-text-template]: https://golang.org/pkg/text/template/
|
||||||
[console-title]: /docs/configuration/title#console-title-template
|
[console-title]: /docs/configuration/title#console-title-template
|
||||||
|
@ -135,3 +67,4 @@ Restart your shell or reload fish using `exec fish` for the changes to take effe
|
||||||
[clink]: https://chrisant996.github.io/clink/
|
[clink]: https://chrisant996.github.io/clink/
|
||||||
[templates]: /docs/configuration/templates
|
[templates]: /docs/configuration/templates
|
||||||
[color-templates]: /docs/configuration/colors#color-templates
|
[color-templates]: /docs/configuration/colors#color-templates
|
||||||
|
[cstp]: /docs/configuration/templates#cross-segment-template-properties
|
||||||
|
|
Loading…
Reference in a new issue