mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-27 03:49:40 -08:00
feat: secondary prompt
This commit is contained in:
parent
cb70ed4b41
commit
dec5691435
|
@ -31,7 +31,7 @@ You need to extend or create a custom theme with your prompt overrides. For exam
|
|||
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
|
||||
"blocks": {
|
||||
...
|
||||
}
|
||||
},
|
||||
"valid_line": {
|
||||
"background": "transparent",
|
||||
"foreground": "#ffffff",
|
||||
|
|
54
docs/docs/config-secondary-prompt.md
Normal file
54
docs/docs/config-secondary-prompt.md
Normal file
|
@ -0,0 +1,54 @@
|
|||
---
|
||||
id: config-secondary-prompt
|
||||
title: Secondary prompt
|
||||
sidebar_label: Secondary prompt
|
||||
---
|
||||
|
||||
:::info
|
||||
This feature only works in `powershell`, `zsh` and `bash` for the time being.
|
||||
:::
|
||||
|
||||
The secondary prompt is displayed when a command text spans multiple lines. The default is `> `.
|
||||
|
||||
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.
|
||||
|
||||
## Configuration
|
||||
|
||||
You need to extend or create a custom theme with your secondary prompt override. For example:
|
||||
|
||||
```json
|
||||
{
|
||||
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
|
||||
"blocks": {
|
||||
...
|
||||
},
|
||||
"secondary_prompt": {
|
||||
"background": "transparent",
|
||||
"foreground": "#ffffff",
|
||||
"template": "-> "
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The configuration has the following properties:
|
||||
|
||||
- background: `string` [color][colors]
|
||||
- foreground: `string` [color][colors]
|
||||
- template: `string` - A go [text/template][go-text-template] template extended with [sprig][sprig] utilizing the
|
||||
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
|
||||
|
||||
[go-text-template]: https://golang.org/pkg/text/template/
|
||||
[sprig]: https://masterminds.github.io/sprig/
|
||||
[console-title]: /docs/config-title#console-title-template
|
||||
[templates]: /docs/config-templates
|
|
@ -33,7 +33,7 @@ You need to extend or create a custom theme with your transient prompt. For exam
|
|||
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
|
||||
"blocks": {
|
||||
...
|
||||
}
|
||||
},
|
||||
"transient_prompt": {
|
||||
"background": "transparent",
|
||||
"foreground": "#ffffff",
|
||||
|
|
|
@ -26,6 +26,7 @@ module.exports = {
|
|||
"config-title",
|
||||
"config-colors",
|
||||
"config-templates",
|
||||
"config-secondary-prompt",
|
||||
"config-transient",
|
||||
"config-line-error",
|
||||
"config-tooltips",
|
||||
|
|
|
@ -42,6 +42,7 @@ type Config struct {
|
|||
TransientPrompt *ExtraPrompt `json:"transient_prompt,omitempty"`
|
||||
ValidLine *ExtraPrompt `json:"valid_line,omitempty"`
|
||||
ErrorLine *ExtraPrompt `json:"error_line,omitempty"`
|
||||
SecondaryPrompt *ExtraPrompt `json:"secondary_prompt,omitempty"`
|
||||
Palette color.Palette `json:"palette,omitempty"`
|
||||
|
||||
format string
|
||||
|
|
|
@ -272,6 +272,7 @@ const (
|
|||
Transient ExtraPromptType = iota
|
||||
Valid
|
||||
Error
|
||||
Secondary
|
||||
)
|
||||
|
||||
func (e *Engine) RenderExtraPrompt(promptType ExtraPromptType) string {
|
||||
|
@ -283,6 +284,8 @@ func (e *Engine) RenderExtraPrompt(promptType ExtraPromptType) string {
|
|||
prompt = e.Config.ValidLine
|
||||
case Error:
|
||||
prompt = e.Config.ErrorLine
|
||||
case Secondary:
|
||||
prompt = e.Config.SecondaryPrompt
|
||||
}
|
||||
if prompt == nil {
|
||||
return ""
|
||||
|
@ -294,6 +297,8 @@ func (e *Engine) RenderExtraPrompt(promptType ExtraPromptType) string {
|
|||
switch promptType { // nolint: exhaustive
|
||||
case Transient:
|
||||
return "{{ .Shell }}> "
|
||||
case Secondary:
|
||||
return "> "
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
|
@ -312,10 +317,14 @@ func (e *Engine) RenderExtraPrompt(promptType ExtraPromptType) string {
|
|||
case zsh:
|
||||
// escape double quotes contained in the prompt
|
||||
str, _ := e.Writer.String()
|
||||
prompt := fmt.Sprintf("PS1=\"%s\"", strings.ReplaceAll(str, "\"", "\"\""))
|
||||
prompt += "\nRPROMPT=\"\""
|
||||
return prompt
|
||||
case pwsh, powershell5, winCMD:
|
||||
if promptType == Transient {
|
||||
prompt := fmt.Sprintf("PS1=\"%s\"", strings.ReplaceAll(str, "\"", "\"\""))
|
||||
// empty RPROMPT
|
||||
prompt += "\nRPROMPT=\"\""
|
||||
return prompt
|
||||
}
|
||||
return str
|
||||
case pwsh, powershell5, winCMD, bash:
|
||||
str, _ := e.Writer.String()
|
||||
return str
|
||||
}
|
||||
|
|
|
@ -9,7 +9,10 @@ if [[ ! -d "/tmp" ]]; then
|
|||
TIMER_START="${HOME}/.${USER}.start.$$"
|
||||
fi
|
||||
|
||||
# start timer on command start
|
||||
PS0='$(::OMP:: --millis > "$TIMER_START")'
|
||||
# set secondary prompt
|
||||
PS2="$(::OMP:: --config="$POSH_THEME" --shell=bash --print-secondary)"
|
||||
|
||||
function _omp_hook() {
|
||||
local ret=$?
|
||||
|
|
|
@ -31,6 +31,10 @@ if (Test-Path $omp_config) {
|
|||
Remove-Variable omp_value -Confirm:$false
|
||||
Remove-Variable omp_config -Confirm:$false
|
||||
|
||||
# set secondary prompt
|
||||
$secondaryPrompt = @(&"::OMP::" --config="$Env:POSH_THEME" --print-secondary 2>&1) -join "`n"
|
||||
Set-PSReadLineOption -ContinuationPrompt $secondaryPrompt
|
||||
|
||||
function global:Set-PoshContext {}
|
||||
|
||||
function global:Get-PoshContext {
|
||||
|
|
|
@ -2,6 +2,9 @@ export POSH_THEME="::CONFIG::"
|
|||
export POWERLINE_COMMAND="oh-my-posh"
|
||||
export CONDA_PROMPT_MODIFIER=false
|
||||
|
||||
# set secondary prompt
|
||||
PS2="$(::OMP:: --config="$POSH_THEME" --shell=zsh --print-secondary)"
|
||||
|
||||
function _omp-preexec() {
|
||||
omp_start_time=$(::OMP:: --millis)
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ type Args struct {
|
|||
PrintConfig *bool
|
||||
PrintShell *bool
|
||||
PrintTransient *bool
|
||||
PrintSecondary *bool
|
||||
PrintValid *bool
|
||||
PrintError *bool
|
||||
Config *string
|
||||
|
|
|
@ -141,6 +141,10 @@ func main() {
|
|||
"print-error",
|
||||
false,
|
||||
"Print the failed prompt"),
|
||||
PrintSecondary: flag.Bool(
|
||||
"print-secondary",
|
||||
false,
|
||||
"Print the secondary prompt"),
|
||||
}
|
||||
flag.Parse()
|
||||
if *args.Version {
|
||||
|
@ -229,6 +233,10 @@ func main() {
|
|||
fmt.Print(eng.RenderExtraPrompt(engine.Error))
|
||||
return
|
||||
}
|
||||
if *args.PrintSecondary {
|
||||
fmt.Print(eng.RenderExtraPrompt(engine.Secondary))
|
||||
return
|
||||
}
|
||||
if len(*args.Command) != 0 {
|
||||
fmt.Print(eng.RenderTooltip(*args.Command))
|
||||
return
|
||||
|
|
|
@ -2051,6 +2051,11 @@
|
|||
"title": "Error Prompt Setting",
|
||||
"description": "https://ohmyposh.dev/docs/config-prompt-override"
|
||||
},
|
||||
"secondary_prompt": {
|
||||
"$ref": "#/definitions/extra_prompt",
|
||||
"title": "Secondary Prompt Setting",
|
||||
"description": "https://ohmyposh.dev/docs/config-secondary-prompt"
|
||||
},
|
||||
"palette": {
|
||||
"type": "object",
|
||||
"title": "Palette",
|
||||
|
|
Loading…
Reference in a new issue