feat(cmd): transient prompt

This commit is contained in:
Jan De Dobbeleer 2021-11-18 13:29:56 +01:00 committed by Jan De Dobbeleer
parent 5ddb0d8896
commit 79c5ad845f
3 changed files with 27 additions and 4 deletions

View file

@ -8,7 +8,7 @@ import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem"; import TabItem from "@theme/TabItem";
:::info :::info
This feature only works in `zsh` and `powershell` for the time being. This feature only works in `zsh`, `powershell` and `cmd` for the time being.
::: :::
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.
@ -66,6 +66,7 @@ properties below. Defaults to `{{ .Shell }}> `
groupId="shell" groupId="shell"
values={[ values={[
{ label: 'powershell', value: 'pwsh', }, { label: 'powershell', value: 'pwsh', },
{ label: 'cmd', value: 'cmd', },
{ label: 'zsh', value: 'zsh', }, { label: 'zsh', value: 'zsh', },
] ]
}> }>
@ -80,6 +81,17 @@ Enable-PoshTransientPrompt
Restart your shell or reload your `$PROFILE` using `. $PROFILE` for the changes to take effect. Restart your shell or reload your `$PROFILE` using `. $PROFILE` for the changes to take effect.
</TabItem>
<TabItem value="cmd">
Set the transient prompt in [clink][clink] to `always` in the `oh-my-posh.lua` script to enable the feature:
```shell
clink set prompt.transient always
```
Restart your shell for the changes to take effect.
</TabItem> </TabItem>
<TabItem value="zsh"> <TabItem value="zsh">
@ -98,3 +110,4 @@ Restart your shell or reload `.zshrc` using `source ~/.zshrc` for the changes to
[go-text-template]: https://golang.org/pkg/text/template/ [go-text-template]: https://golang.org/pkg/text/template/
[console-title]: /docs/config-title#console-title-template [console-title]: /docs/config-title#console-title-template
[sprig]: https://masterminds.github.io/sprig/ [sprig]: https://masterminds.github.io/sprig/
[clink]: https://chrisant996.github.io/clink/

View file

@ -253,7 +253,7 @@ func (e *engine) renderTransientPrompt() string {
prompt := fmt.Sprintf("PS1=\"%s\"", strings.ReplaceAll(e.writer.string(), "\"", "\"\"")) prompt := fmt.Sprintf("PS1=\"%s\"", strings.ReplaceAll(e.writer.string(), "\"", "\"\""))
prompt += "\nRPROMPT=\"\"" prompt += "\nRPROMPT=\"\""
return prompt return prompt
case pwsh, powershell5: case pwsh, powershell5, winCMD:
return e.writer.string() return e.writer.string()
} }
return "" return ""

View file

@ -47,7 +47,7 @@ local function error_level_option()
end end
local function get_posh_prompt(rprompt) local function get_posh_prompt(rprompt)
local prompt_exe = string.format('::OMP:: --config="::CONFIG::" %s %s --rprompt=%s', execution_time_option(), error_level_option(), rprompt) local prompt_exe = string.format('::OMP:: --shell=cmd --config="::CONFIG::" %s %s --rprompt=%s', execution_time_option(), error_level_option(), rprompt)
prompt = io.popen(prompt_exe):read("*a") prompt = io.popen(prompt_exe):read("*a")
return prompt return prompt
end end
@ -60,13 +60,23 @@ function p:rightfilter(prompt)
if tip_word == nil then if tip_word == nil then
return get_posh_prompt(true), false return get_posh_prompt(true), false
end end
local prompt_exe = string.format('::OMP:: --config="::CONFIG::" --command="%s"', tip_word) local prompt_exe = string.format('::OMP:: --shell=cmd --config="::CONFIG::" --command="%s"', tip_word)
tooltip = io.popen(prompt_exe):read("*a") tooltip = io.popen(prompt_exe):read("*a")
if tooltip ~= "" then if tooltip ~= "" then
return tooltip, false return tooltip, false
end end
return get_posh_prompt(true), false return get_posh_prompt(true), false
end end
function p:transientfilter(prompt)
prompt = io.popen('::OMP:: --shell=cmd --config="::CONFIG::" --print-transient'):read("*a")
if prompt == "" then
prompt = nil
end
return prompt
end
function p:transientrightfilter(prompt)
return "", false
end
-- Event handlers -- Event handlers