fix(tooltip): check only the first word of command line

This commit is contained in:
L. Yeung 2023-04-22 02:08:11 +08:00 committed by Jan De Dobbeleer
parent 7368c6541e
commit 14f012308e
2 changed files with 16 additions and 15 deletions

View file

@ -69,19 +69,6 @@ if [[ "$(zle -lL zle-line-init)" = *"_posh-zle-line-init"* ]]; then
fi fi
function _posh-tooltip() { function _posh-tooltip() {
# ignore an empty buffer
if [[ -z "$BUFFER" ]]; then
zle .self-insert
return
fi
local tooltip=$(::OMP:: print tooltip --config="$POSH_THEME" --shell=zsh --error="$omp_last_error" --command="$BUFFER" --shell-version="$ZSH_VERSION")
# ignore an empty tooltip
if [[ -n "$tooltip" ]]; then
RPROMPT=$tooltip
zle .reset-prompt
fi
# https://github.com/zsh-users/zsh-autosuggestions - clear suggestion to avoid keeping it after the newly inserted space # https://github.com/zsh-users/zsh-autosuggestions - clear suggestion to avoid keeping it after the newly inserted space
if [[ -n "$(zle -lL autosuggest-clear)" ]]; then if [[ -n "$(zle -lL autosuggest-clear)" ]]; then
# only if suggestions not disabled (variable not set) # only if suggestions not disabled (variable not set)
@ -97,6 +84,20 @@ function _posh-tooltip() {
zle autosuggest-fetch zle autosuggest-fetch
fi fi
fi fi
# get the first word of command line as tip
local tip=${${(MS)BUFFER##[[:graph:]]*}%%[[:space:]]*}
# ignore an empty tip
if [[ -z "$tip" ]]; then
return
fi
local tooltip=$(::OMP:: print tooltip --config="$POSH_THEME" --shell=zsh --error="$omp_last_error" --command="$tip" --shell-version="$ZSH_VERSION")
# ignore an empty tooltip
if [[ -z "$tooltip" ]]; then
return
fi
RPROMPT=$tooltip
zle .reset-prompt
} }
function _posh-zle-line-init() { function _posh-zle-line-init() {

View file

@ -44,7 +44,7 @@ import Config from '@site/src/components/Config.js';
}}/> }}/>
This configuration will render a right-aligned git segment when you type `git` or `g` followed by a space. This configuration will render a right-aligned git segment when you type `git` or `g` followed by a space.
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 spaces. Keep in mind that this is a blocking call, meaning that if the segment renders slow,
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. you can't type until it's visible. Optimizations in this space are being explored.
[clink]: https://chrisant996.github.io/clink/ [clink]: https://chrisant996.github.io/clink/