feat(fish): tooltip support

This commit is contained in:
Jan De Dobbeleer 2022-03-22 19:53:37 +01:00 committed by Jan De Dobbeleer
parent 0d9eaa2a09
commit 340c851743
3 changed files with 33 additions and 3 deletions

View file

@ -8,7 +8,7 @@ import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";
:::info
Due to limitations (or not having found a way just yet), this feature only works in `zsh`, `powershell` and `cmd` (as of [clink][clink] version v1.2.46) for
Due to limitations (or not having found a way just yet), this feature only works in `fish`, `zsh`, `powershell` and `cmd` (as of [clink][clink] version v1.2.46) for
the time being.
:::
@ -61,6 +61,7 @@ are being explored.
values={[
{ label: 'powershell', value: 'pwsh', },
{ label: 'zsh', value: 'zsh', },
{ label: 'fish', value: 'fish', },
]
}>
<TabItem value="pwsh">
@ -92,6 +93,17 @@ 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>

View file

@ -253,7 +253,7 @@ func (e *Engine) PrintTooltip(tip string) string {
Segments: []*Segment{tooltip},
}
switch e.Env.Shell() {
case shell.ZSH, shell.CMD:
case shell.ZSH, shell.CMD, shell.FISH:
block.init(e.Env, e.Writer, e.Ansi)
text, _ := block.renderSegments()
return text
@ -266,7 +266,7 @@ func (e *Engine) PrintTooltip(tip string) string {
e.write(text)
return e.string()
}
return ""
return " "
}
type ExtraPromptType int

View file

@ -1,6 +1,7 @@
set -g POSH_THEME "::CONFIG::"
set -g POWERLINE_COMMAND "oh-my-posh"
set -g CONDA_PROMPT_MODIFIER false
set -g omp_tooltip_command ""
function fish_prompt
set -g omp_status_cache $status
@ -22,6 +23,11 @@ function fish_prompt
end
function fish_right_prompt
if test -n "$omp_tooltip_command"
::OMP:: prompt print tooltip --config $POSH_THEME --shell fish --command $omp_tooltip_command
set omp_tooltip_command ""
return
end
::OMP:: prompt print right --config $POSH_THEME --shell fish --error $omp_status_cache --execution-time $omp_duration --stack-count $omp_stack_count
end
@ -30,3 +36,15 @@ function postexec_omp --on-event fish_postexec
# pre and postexec not fired for empty command in fish >=3.2
set -gx omp_lastcommand $argv
end
# tooltip
function _render_tooltip
set omp_tooltip_command (commandline --current-buffer | string collect)
commandline --insert " "
commandline --function repaint
end
function enable_poshtooltips
bind \x20 _render_tooltip
end