mirror of
https://github.com/zsh-users/zsh-autosuggestions.git
synced 2024-12-30 00:03:56 +08:00
Add compiled zsh-autosuggestions.zsh
This commit is contained in:
parent
33768b3640
commit
de795f7dd9
|
@ -220,13 +220,13 @@ _zsh_autosuggest_bind_widgets() {
|
||||||
|
|
||||||
# Find every widget we might want to bind and bind it appropriately
|
# Find every widget we might want to bind and bind it appropriately
|
||||||
for widget in ${${(f)"$(builtin zle -la)"}:#${(j:|:)~ignore_widgets}}; do
|
for widget in ${${(f)"$(builtin zle -la)"}:#${(j:|:)~ignore_widgets}}; do
|
||||||
if [ ${ZSH_AUTOSUGGEST_CLEAR_WIDGETS[(r)$widget]} ]; then
|
if [[ -n ${ZSH_AUTOSUGGEST_CLEAR_WIDGETS[(r)$widget]} ]]; then
|
||||||
_zsh_autosuggest_bind_widget $widget clear
|
_zsh_autosuggest_bind_widget $widget clear
|
||||||
elif [ ${ZSH_AUTOSUGGEST_ACCEPT_WIDGETS[(r)$widget]} ]; then
|
elif [[ -n ${ZSH_AUTOSUGGEST_ACCEPT_WIDGETS[(r)$widget]} ]]; then
|
||||||
_zsh_autosuggest_bind_widget $widget accept
|
_zsh_autosuggest_bind_widget $widget accept
|
||||||
elif [ ${ZSH_AUTOSUGGEST_EXECUTE_WIDGETS[(r)$widget]} ]; then
|
elif [[ -n ${ZSH_AUTOSUGGEST_EXECUTE_WIDGETS[(r)$widget]} ]]; then
|
||||||
_zsh_autosuggest_bind_widget $widget execute
|
_zsh_autosuggest_bind_widget $widget execute
|
||||||
elif [ ${ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS[(r)$widget]} ]; then
|
elif [[ -n ${ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS[(r)$widget]} ]]; then
|
||||||
_zsh_autosuggest_bind_widget $widget partial_accept
|
_zsh_autosuggest_bind_widget $widget partial_accept
|
||||||
else
|
else
|
||||||
# Assume any unspecified widget might modify the buffer
|
# Assume any unspecified widget might modify the buffer
|
||||||
|
@ -238,13 +238,13 @@ _zsh_autosuggest_bind_widgets() {
|
||||||
# Given the name of an original widget and args, invoke it, if it exists
|
# Given the name of an original widget and args, invoke it, if it exists
|
||||||
_zsh_autosuggest_invoke_original_widget() {
|
_zsh_autosuggest_invoke_original_widget() {
|
||||||
# Do nothing unless called with at least one arg
|
# Do nothing unless called with at least one arg
|
||||||
[ $# -gt 0 ] || return
|
(( $# )) || return
|
||||||
|
|
||||||
local original_widget_name="$1"
|
local original_widget_name="$1"
|
||||||
|
|
||||||
shift
|
shift
|
||||||
|
|
||||||
if [ $widgets[$original_widget_name] ]; then
|
if (( ${+widgets[$original_widget_name]} )); then
|
||||||
zle $original_widget_name -- $@
|
zle $original_widget_name -- $@
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -257,7 +257,7 @@ _zsh_autosuggest_invoke_original_widget() {
|
||||||
_zsh_autosuggest_highlight_reset() {
|
_zsh_autosuggest_highlight_reset() {
|
||||||
typeset -g _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
|
typeset -g _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
|
||||||
|
|
||||||
if [ -n "$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT" ]; then
|
if [[ -n "$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT" ]]; then
|
||||||
region_highlight=("${(@)region_highlight:#$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT}")
|
region_highlight=("${(@)region_highlight:#$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT}")
|
||||||
unset _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
|
unset _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
|
||||||
fi
|
fi
|
||||||
|
@ -267,7 +267,7 @@ _zsh_autosuggest_highlight_reset() {
|
||||||
_zsh_autosuggest_highlight_apply() {
|
_zsh_autosuggest_highlight_apply() {
|
||||||
typeset -g _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
|
typeset -g _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
|
||||||
|
|
||||||
if [ $#POSTDISPLAY -gt 0 ]; then
|
if (( $#POSTDISPLAY )); then
|
||||||
_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT="$#BUFFER $(($#BUFFER + $#POSTDISPLAY)) $ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE"
|
_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT="$#BUFFER $(($#BUFFER + $#POSTDISPLAY)) $ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE"
|
||||||
region_highlight+=("$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT")
|
region_highlight+=("$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT")
|
||||||
else
|
else
|
||||||
|
@ -289,14 +289,14 @@ _zsh_autosuggest_disable() {
|
||||||
_zsh_autosuggest_enable() {
|
_zsh_autosuggest_enable() {
|
||||||
unset _ZSH_AUTOSUGGEST_DISABLED
|
unset _ZSH_AUTOSUGGEST_DISABLED
|
||||||
|
|
||||||
if [ $#BUFFER -gt 0 ]; then
|
if (( $#BUFFER )); then
|
||||||
_zsh_autosuggest_fetch
|
_zsh_autosuggest_fetch
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Toggle suggestions (enable/disable)
|
# Toggle suggestions (enable/disable)
|
||||||
_zsh_autosuggest_toggle() {
|
_zsh_autosuggest_toggle() {
|
||||||
if [ -n "${_ZSH_AUTOSUGGEST_DISABLED+x}" ]; then
|
if [[ -n "${_ZSH_AUTOSUGGEST_DISABLED+x}" ]]; then
|
||||||
_zsh_autosuggest_enable
|
_zsh_autosuggest_enable
|
||||||
else
|
else
|
||||||
_zsh_autosuggest_disable
|
_zsh_autosuggest_disable
|
||||||
|
@ -330,35 +330,35 @@ _zsh_autosuggest_modify() {
|
||||||
retval=$?
|
retval=$?
|
||||||
|
|
||||||
# Don't fetch a new suggestion if there's more input to be read immediately
|
# Don't fetch a new suggestion if there's more input to be read immediately
|
||||||
if [[ $PENDING > 0 ]] || [[ $KEYS_QUEUED_COUNT > 0 ]]; then
|
if (( $PENDING > 0 )) || (( $KEYS_QUEUED_COUNT > 0 )); then
|
||||||
return $retval
|
return $retval
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Optimize if manually typing in the suggestion
|
# Optimize if manually typing in the suggestion
|
||||||
if [ $#BUFFER -gt $#orig_buffer ]; then
|
if (( $#BUFFER > $#orig_buffer )); then
|
||||||
local added=${BUFFER#$orig_buffer}
|
local added=${BUFFER#$orig_buffer}
|
||||||
|
|
||||||
# If the string added matches the beginning of the postdisplay
|
# If the string added matches the beginning of the postdisplay
|
||||||
if [ "$added" = "${orig_postdisplay:0:$#added}" ]; then
|
if [[ "$added" = "${orig_postdisplay:0:$#added}" ]]; then
|
||||||
POSTDISPLAY="${orig_postdisplay:$#added}"
|
POSTDISPLAY="${orig_postdisplay:$#added}"
|
||||||
return $retval
|
return $retval
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Don't fetch a new suggestion if the buffer hasn't changed
|
# Don't fetch a new suggestion if the buffer hasn't changed
|
||||||
if [ "$BUFFER" = "$orig_buffer" ]; then
|
if [[ "$BUFFER" = "$orig_buffer" ]]; then
|
||||||
POSTDISPLAY="$orig_postdisplay"
|
POSTDISPLAY="$orig_postdisplay"
|
||||||
return $retval
|
return $retval
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Bail out if suggestions are disabled
|
# Bail out if suggestions are disabled
|
||||||
if [ -n "${_ZSH_AUTOSUGGEST_DISABLED+x}" ]; then
|
if [[ -n "${_ZSH_AUTOSUGGEST_DISABLED+x}" ]]; then
|
||||||
return $?
|
return $?
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Get a new suggestion if the buffer is not empty after modification
|
# Get a new suggestion if the buffer is not empty after modification
|
||||||
if [ $#BUFFER -gt 0 ]; then
|
if (( $#BUFFER > 0 )); then
|
||||||
if [ -z "$ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE" -o $#BUFFER -le "$ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE" ]; then
|
if [[ -z "$ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE" ]] || (( $#BUFFER <= $ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE )); then
|
||||||
_zsh_autosuggest_fetch
|
_zsh_autosuggest_fetch
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
@ -381,7 +381,7 @@ _zsh_autosuggest_fetch() {
|
||||||
_zsh_autosuggest_suggest() {
|
_zsh_autosuggest_suggest() {
|
||||||
local suggestion="$1"
|
local suggestion="$1"
|
||||||
|
|
||||||
if [ -n "$suggestion" ] && [ $#BUFFER -gt 0 ]; then
|
if [[ -n "$suggestion" ]] && (( $#BUFFER )); then
|
||||||
POSTDISPLAY="${suggestion#$BUFFER}"
|
POSTDISPLAY="${suggestion#$BUFFER}"
|
||||||
else
|
else
|
||||||
unset POSTDISPLAY
|
unset POSTDISPLAY
|
||||||
|
@ -394,12 +394,12 @@ _zsh_autosuggest_accept() {
|
||||||
|
|
||||||
# When vicmd keymap is active, the cursor can't move all the way
|
# When vicmd keymap is active, the cursor can't move all the way
|
||||||
# to the end of the buffer
|
# to the end of the buffer
|
||||||
if [ "$KEYMAP" = "vicmd" ]; then
|
if [[ "$KEYMAP" = "vicmd" ]]; then
|
||||||
max_cursor_pos=$((max_cursor_pos - 1))
|
max_cursor_pos=$((max_cursor_pos - 1))
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Only accept if the cursor is at the end of the buffer
|
# Only accept if the cursor is at the end of the buffer
|
||||||
if [ $CURSOR -eq $max_cursor_pos ]; then
|
if [[ $CURSOR = $max_cursor_pos ]]; then
|
||||||
# Add the suggestion to the buffer
|
# Add the suggestion to the buffer
|
||||||
BUFFER="$BUFFER$POSTDISPLAY"
|
BUFFER="$BUFFER$POSTDISPLAY"
|
||||||
|
|
||||||
|
@ -441,7 +441,7 @@ _zsh_autosuggest_partial_accept() {
|
||||||
retval=$?
|
retval=$?
|
||||||
|
|
||||||
# If we've moved past the end of the original buffer
|
# If we've moved past the end of the original buffer
|
||||||
if [ $CURSOR -gt $#original_buffer ]; then
|
if (( $CURSOR > $#original_buffer )); then
|
||||||
# Set POSTDISPLAY to text right of the cursor
|
# Set POSTDISPLAY to text right of the cursor
|
||||||
POSTDISPLAY="$RBUFFER"
|
POSTDISPLAY="$RBUFFER"
|
||||||
|
|
||||||
|
@ -622,7 +622,7 @@ _zsh_autosuggest_async_pty_create() {
|
||||||
typeset -h REPLY
|
typeset -h REPLY
|
||||||
|
|
||||||
# If we won't get a fd back from zpty, try to guess it
|
# If we won't get a fd back from zpty, try to guess it
|
||||||
if [ $_ZSH_AUTOSUGGEST_ZPTY_RETURNS_FD -eq 0 ]; then
|
if (( ! $_ZSH_AUTOSUGGEST_ZPTY_RETURNS_FD )); then
|
||||||
integer -l zptyfd
|
integer -l zptyfd
|
||||||
exec {zptyfd}>&1 # Open a new file descriptor (above 10).
|
exec {zptyfd}>&1 # Open a new file descriptor (above 10).
|
||||||
exec {zptyfd}>&- # Close it so it's free to be used by zpty.
|
exec {zptyfd}>&- # Close it so it's free to be used by zpty.
|
||||||
|
@ -683,7 +683,7 @@ _zsh_autosuggest_start() {
|
||||||
# to the widget list variables to take effect on the next precmd.
|
# to the widget list variables to take effect on the next precmd.
|
||||||
add-zsh-hook precmd _zsh_autosuggest_bind_widgets
|
add-zsh-hook precmd _zsh_autosuggest_bind_widgets
|
||||||
|
|
||||||
if [ -n "${ZSH_AUTOSUGGEST_USE_ASYNC+x}" ]; then
|
if [[ -n "${ZSH_AUTOSUGGEST_USE_ASYNC+x}" ]]; then
|
||||||
_zsh_autosuggest_async_start
|
_zsh_autosuggest_async_start
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user