|
|
@ -27,14 +27,14 @@ menu-complete reverse-menu-complete menu-expand-or-complete menu-select
|
|
|
|
accept-and-menu-complete
|
|
|
|
accept-and-menu-complete
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
pause-autosuggestions() {
|
|
|
|
autosuggest-pause-autosuggestions() {
|
|
|
|
[[ -n $ZLE_AUTOSUGGESTING_PAUSED ]] && return
|
|
|
|
[[ -n $ZLE_AUTOSUGGESTING_PAUSED ]] && return
|
|
|
|
local widget
|
|
|
|
local widget
|
|
|
|
# When autosuggestions are disabled, kill the unmaterialized part
|
|
|
|
# When autosuggestions are disabled, kill the unmaterialized part
|
|
|
|
RBUFFER=''
|
|
|
|
RBUFFER=''
|
|
|
|
unset ZLE_AUTOSUGGESTING
|
|
|
|
unset ZLE_AUTOSUGGESTING
|
|
|
|
ZLE_AUTOSUGGESTING_PAUSED=1
|
|
|
|
ZLE_AUTOSUGGESTING_PAUSED=1
|
|
|
|
zle -A self-insert paused-autosuggest-self-insert
|
|
|
|
zle -A self-insert autosuggest-paused-self-insert
|
|
|
|
zle -A .magic-space magic-space
|
|
|
|
zle -A .magic-space magic-space
|
|
|
|
zle -A .backward-delete-char backward-delete-char
|
|
|
|
zle -A .backward-delete-char backward-delete-char
|
|
|
|
zle -A .accept-line accept-line
|
|
|
|
zle -A .accept-line accept-line
|
|
|
@ -44,7 +44,7 @@ pause-autosuggestions() {
|
|
|
|
for widget in $ZLE_AUTOSUGGEST_COMPLETION_WIDGETS; do
|
|
|
|
for widget in $ZLE_AUTOSUGGEST_COMPLETION_WIDGETS; do
|
|
|
|
eval "zle -A autosuggest-${widget}-orig $widget"
|
|
|
|
eval "zle -A autosuggest-${widget}-orig $widget"
|
|
|
|
done
|
|
|
|
done
|
|
|
|
highlight-suggested-text
|
|
|
|
autosuggest-highlight-suggested-text
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
enable-autosuggestions() {
|
|
|
|
enable-autosuggestions() {
|
|
|
@ -53,9 +53,9 @@ enable-autosuggestions() {
|
|
|
|
unset ZLE_AUTOSUGGESTING_PAUSED
|
|
|
|
unset ZLE_AUTOSUGGESTING_PAUSED
|
|
|
|
ZLE_AUTOSUGGESTING=1
|
|
|
|
ZLE_AUTOSUGGESTING=1
|
|
|
|
# Replace prediction widgets by versions that will also highlight RBUFFER
|
|
|
|
# Replace prediction widgets by versions that will also highlight RBUFFER
|
|
|
|
zle -N self-insert autosuggest-self-insert
|
|
|
|
zle -N self-insert autosuggest-insert-or-space
|
|
|
|
zle -N magic-space autosuggest-self-insert
|
|
|
|
zle -N magic-space autosuggest-insert-or-space
|
|
|
|
zle -N backward-delete-char autosuggest-delete
|
|
|
|
zle -N backward-delete-char autosuggest-backward-delete-char
|
|
|
|
zle -N accept-line autosuggest-accept-line
|
|
|
|
zle -N accept-line autosuggest-accept-line
|
|
|
|
# Hook into some default widgets that should pause autosuggestion
|
|
|
|
# Hook into some default widgets that should pause autosuggestion
|
|
|
|
# automatically
|
|
|
|
# automatically
|
|
|
@ -69,13 +69,13 @@ enable-autosuggestions() {
|
|
|
|
zle -A autosuggest-tab $widget"
|
|
|
|
zle -A autosuggest-tab $widget"
|
|
|
|
done
|
|
|
|
done
|
|
|
|
if [[ $BUFFER != '' ]]; then
|
|
|
|
if [[ $BUFFER != '' ]]; then
|
|
|
|
show-suggestion
|
|
|
|
autosuggest-pop-suggestion
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
disable-autosuggestions() {
|
|
|
|
disable-autosuggestions() {
|
|
|
|
if [[ -z $ZLE_AUTOSUGGESTING_PAUSED ]]; then
|
|
|
|
if [[ -z $ZLE_AUTOSUGGESTING_PAUSED ]]; then
|
|
|
|
pause-autosuggestions
|
|
|
|
autosuggest-pause-autosuggestions
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
unset ZLE_AUTOSUGGESTING_PAUSED
|
|
|
|
unset ZLE_AUTOSUGGESTING_PAUSED
|
|
|
|
zle -A .self-insert self-insert
|
|
|
|
zle -A .self-insert self-insert
|
|
|
@ -90,7 +90,7 @@ toggle-autosuggestions() {
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
highlight-suggested-text() {
|
|
|
|
autosuggest-highlight-suggested-text() {
|
|
|
|
if [[ -n $ZLE_AUTOSUGGESTING ]]; then
|
|
|
|
if [[ -n $ZLE_AUTOSUGGESTING ]]; then
|
|
|
|
local color='fg=8'
|
|
|
|
local color='fg=8'
|
|
|
|
[[ -n $AUTOSUGGESTION_HIGHLIGHT_COLOR ]] &&\
|
|
|
|
[[ -n $AUTOSUGGESTION_HIGHLIGHT_COLOR ]] &&\
|
|
|
@ -101,36 +101,36 @@ highlight-suggested-text() {
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
autosuggest-self-insert() {
|
|
|
|
autosuggest-insert-or-space() {
|
|
|
|
setopt localoptions noshwordsplit noksharrays
|
|
|
|
if [[ $LBUFFER == *$'\012'* ]] || (( PENDING )); then
|
|
|
|
if [[ ${RBUFFER[1]} == ${KEYS[-1]} ]]; then
|
|
|
|
# Editing a multiline buffer or pasting in a chunk of text, dont
|
|
|
|
# Same as what's typed, just move on
|
|
|
|
# autosuggest
|
|
|
|
|
|
|
|
zle .$WIDGET "$@"
|
|
|
|
|
|
|
|
elif [[ ${RBUFFER[1]} == ${KEYS[-1]} ]]; then
|
|
|
|
|
|
|
|
# Same as what's typed, just move on
|
|
|
|
((++CURSOR))
|
|
|
|
((++CURSOR))
|
|
|
|
highlight-suggested-text
|
|
|
|
autosuggest-highlight-suggested-text
|
|
|
|
else
|
|
|
|
else
|
|
|
|
LBUFFER="$LBUFFER$KEYS"
|
|
|
|
LBUFFER="$LBUFFER$KEYS"
|
|
|
|
show-suggestion
|
|
|
|
autosuggest-pop-suggestion
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Taken from predict-on
|
|
|
|
autosuggest-backward-delete-char() {
|
|
|
|
autosuggest-delete() {
|
|
|
|
if ! (( $CURSOR )); then
|
|
|
|
if (( $#LBUFFER > 1 )); then
|
|
|
|
zle .kill-whole-line
|
|
|
|
setopt localoptions noshwordsplit noksharrays
|
|
|
|
return
|
|
|
|
# When editing a multiline buffer, it's unlikely prediction is wanted;
|
|
|
|
fi
|
|
|
|
# or if the last widget was e.g. a motion, then probably the intent is
|
|
|
|
|
|
|
|
# to actually edit the line, not change the search prefix.
|
|
|
|
if [[ $LBUFFER == *$'\012'* || $LASTWIDGET != (self-insert|magic-space|backward-delete-char) ]]; then
|
|
|
|
if [[ $LASTWIDGET != (self-insert|magic-space|backward-delete-char) ]]; then
|
|
|
|
# When editing a multiline buffer or if the last widget was e.g. a motion,
|
|
|
|
LBUFFER="$LBUFFER[1,-2]"
|
|
|
|
# then probably the intent is to actually edit the line, not change the
|
|
|
|
else
|
|
|
|
# search prefix.
|
|
|
|
((--CURSOR))
|
|
|
|
LBUFFER="$LBUFFER[1,-2]"
|
|
|
|
zle .history-beginning-search-forward || RBUFFER=""
|
|
|
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
else
|
|
|
|
else
|
|
|
|
zle .kill-whole-line
|
|
|
|
((--CURSOR))
|
|
|
|
|
|
|
|
zle .history-beginning-search-forward || RBUFFER=''
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
highlight-suggested-text
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# When autosuggesting, ignore RBUFFER which corresponds to the 'unmaterialized'
|
|
|
|
# When autosuggesting, ignore RBUFFER which corresponds to the 'unmaterialized'
|
|
|
@ -141,50 +141,56 @@ autosuggest-accept-line() {
|
|
|
|
zle .accept-line
|
|
|
|
zle .accept-line
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
paused-autosuggest-self-insert() {
|
|
|
|
autosuggest-paused-self-insert() {
|
|
|
|
if [[ $RBUFFER == '' ]]; then
|
|
|
|
if [[ $RBUFFER == '' ]]; then
|
|
|
|
# Resume autosuggestions when inserting at the end of the line
|
|
|
|
# Resume autosuggestions when inserting at the end of the line
|
|
|
|
enable-autosuggestions
|
|
|
|
enable-autosuggestions
|
|
|
|
autosuggest-self-insert
|
|
|
|
zle autosuggest-modify
|
|
|
|
else
|
|
|
|
else
|
|
|
|
zle .self-insert
|
|
|
|
zle .self-insert
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
autosuggest-get-suggested-completion() {
|
|
|
|
autosuggest-get-suggested-completion() {
|
|
|
|
|
|
|
|
if (( $CURSOR == 0 )) || [[ ${LBUFFER[-1]} == ' ' ]]; then
|
|
|
|
|
|
|
|
RBUFFER=''
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
local words last_word
|
|
|
|
local words last_word
|
|
|
|
local suggestion=$(autosuggest-first-completion $LBUFFER)
|
|
|
|
local suggestion="$(autosuggest-first-completion ${LBUFFER})"
|
|
|
|
words=(${(z)LBUFFER})
|
|
|
|
words=(${(z)LBUFFER})
|
|
|
|
last_word=${words[-1]}
|
|
|
|
last_word=${words[-1]}
|
|
|
|
suggestion=${suggestion:$#last_word}
|
|
|
|
suggestion=${suggestion:$#last_word}
|
|
|
|
RBUFFER="$suggestion"
|
|
|
|
RBUFFER="$suggestion"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
show-suggestion() {
|
|
|
|
autosuggest-pop-suggestion() {
|
|
|
|
[[ -n $ZLE_DISABLE_AUTOSUGGEST || $LBUFFER == '' ]] && return
|
|
|
|
[[ -n $ZLE_DISABLE_AUTOSUGGEST || $LBUFFER == '' ]] && return
|
|
|
|
zle .history-beginning-search-backward ||\
|
|
|
|
zle .history-beginning-search-backward ||\
|
|
|
|
autosuggest-get-suggested-completion
|
|
|
|
autosuggest-get-suggested-completion
|
|
|
|
highlight-suggested-text
|
|
|
|
autosuggest-highlight-suggested-text
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
autosuggest-pause() {
|
|
|
|
autosuggest-pause() {
|
|
|
|
pause-autosuggestions
|
|
|
|
autosuggest-pause-autosuggestions
|
|
|
|
zle autosuggest-${WIDGET}-orig "$@"
|
|
|
|
zle autosuggest-${WIDGET}-orig "$@"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
autosuggest-tab() {
|
|
|
|
autosuggest-tab() {
|
|
|
|
RBUFFER=''
|
|
|
|
RBUFFER=''
|
|
|
|
zle autosuggest-${WIDGET}-orig "$@"
|
|
|
|
zle autosuggest-${WIDGET}-orig "$@"
|
|
|
|
|
|
|
|
autosuggest-highlight-suggested-text
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
accept-suggested-small-word() {
|
|
|
|
accept-suggested-small-word() {
|
|
|
|
zle .vi-forward-word
|
|
|
|
zle .vi-forward-word
|
|
|
|
highlight-suggested-text
|
|
|
|
autosuggest-highlight-suggested-text
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
accept-suggested-word() {
|
|
|
|
accept-suggested-word() {
|
|
|
|
zle .forward-word
|
|
|
|
zle .forward-word
|
|
|
|
highlight-suggested-text
|
|
|
|
autosuggest-highlight-suggested-text
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
zle -N toggle-autosuggestions
|
|
|
|
zle -N toggle-autosuggestions
|
|
|
|