mirror of
https://github.com/zsh-users/zsh-autosuggestions.git
synced 2025-12-06 15:20:40 +01:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
76f415bf43 | ||
|
|
5e419da326 | ||
|
|
cd71081303 | ||
|
|
9788c2ee49 | ||
|
|
ebcfc46b72 | ||
|
|
b49d002888 | ||
|
|
266437c98a | ||
|
|
51b39e210e | ||
|
|
011f5420fc | ||
|
|
1a38fbf6a5 |
@@ -40,7 +40,7 @@ It suggests commands as you type, based on command history.
|
||||
|
||||
3. Start a new terminal session.
|
||||
|
||||
> **Note:** There is an open issue ([#102](https://github.com/tarruda/zsh-autosuggestions/issues/102)) when using this plugin with `bracketed-paste-magic`, which is enabled by default by Oh My Zsh.
|
||||
**Note:** There is an open issue ([#102](https://github.com/tarruda/zsh-autosuggestions/issues/102)) when using this plugin with `bracketed-paste-magic`, which is enabled by default by Oh My Zsh. See the comments in that issue for a workaround.
|
||||
|
||||
|
||||
## Usage
|
||||
@@ -69,10 +69,11 @@ Set `ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE` to configure the style that the suggestion
|
||||
This plugin works by triggering custom behavior when certain [zle widgets](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Zle-Widgets) are invoked. You can add and remove widgets from these arrays to change the behavior of this plugin:
|
||||
|
||||
- `ZSH_AUTOSUGGEST_CLEAR_WIDGETS`: Widgets in this array will clear the suggestion when invoked.
|
||||
- `ZSH_AUTOSUGGEST_MODIFY_WIDGETS`: Widgets in this array will modify the buffer and fetch a new suggestion when invoked.
|
||||
- `ZSH_AUTOSUGGEST_ACCEPT_WIDGETS`: Widgets in this array will accept the suggestion when invoked.
|
||||
- `ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS`: Widgets in this array will partially accept the suggestion when invoked.
|
||||
|
||||
Widgets not in any of these lists will update the suggestion when invoked.
|
||||
|
||||
**Note:** A widget shouldn't belong to more than one of the above arrays.
|
||||
|
||||
|
||||
@@ -132,7 +133,7 @@ Before reporting an issue, please try temporarily disabling sections of your con
|
||||
|
||||
When reporting an issue, please include:
|
||||
|
||||
- The smallest, simplest `.zshrc` configuration that will reproduce the problem
|
||||
- The smallest, simplest `.zshrc` configuration that will reproduce the problem. See [this comment](https://github.com/tarruda/zsh-autosuggestions/issues/102#issuecomment-180944764) for a good example of what this means.
|
||||
- The version of zsh you're using (`zsh --version`)
|
||||
- Which operating system you're running
|
||||
|
||||
|
||||
46
src/bind.zsh
46
src/bind.zsh
@@ -1,18 +1,18 @@
|
||||
|
||||
#----------------#
|
||||
#--------------------------------------------------------------------#
|
||||
# Widget Helpers #
|
||||
#----------------#
|
||||
#--------------------------------------------------------------------#
|
||||
|
||||
# Bind a single widget to an autosuggest widget, saving a reference to the original widget
|
||||
_zsh_autosuggest_bind_widget() {
|
||||
local widget=$1
|
||||
local autosuggest_function=$2
|
||||
local autosuggest_action=$2
|
||||
local prefix=$ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX
|
||||
local action
|
||||
|
||||
# Save a reference to the original widget
|
||||
case $widgets[$widget] in
|
||||
# Already bound
|
||||
user:_zsh_autosuggest_(bound|orig)_*);;
|
||||
user:_zsh_autosuggest_(widget|orig)_*);;
|
||||
|
||||
# User-defined widget
|
||||
user:*)
|
||||
@@ -31,23 +31,8 @@ _zsh_autosuggest_bind_widget() {
|
||||
;;
|
||||
esac
|
||||
|
||||
# Set up widget to call $autosuggest_function if it exists
|
||||
# Otherwise just call the original widget
|
||||
if [ -n "$autosuggest_function" ]; then;
|
||||
action=$autosuggest_function;
|
||||
else;
|
||||
action="zle $prefix$widget \$@"
|
||||
fi
|
||||
|
||||
# Create new function for the widget that highlights and calls the action
|
||||
eval "_zsh_autosuggest_bound_$widget() {
|
||||
_zsh_autosuggest_highlight_reset
|
||||
$action
|
||||
_zsh_autosuggest_highlight_apply
|
||||
}"
|
||||
|
||||
# Create the bound widget
|
||||
zle -N $widget _zsh_autosuggest_bound_$widget
|
||||
zle -N $widget _zsh_autosuggest_widget_$autosuggest_action
|
||||
}
|
||||
|
||||
# Map all configured widgets to the right autosuggest widgets
|
||||
@@ -55,26 +40,25 @@ _zsh_autosuggest_bind_widgets() {
|
||||
local widget;
|
||||
|
||||
# Find every widget we might want to bind and bind it appropriately
|
||||
for widget in ${${(f)"$(builtin zle -la)"}:#(.*|_*|orig-*|autosuggest-*|$ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX*|run-help|which-command|beep|set-local-history|yank)}; do
|
||||
if [ ${ZSH_AUTOSUGGEST_MODIFY_WIDGETS[(r)$widget]} ]; then
|
||||
_zsh_autosuggest_bind_widget $widget _zsh_autosuggest_modify
|
||||
elif [ ${ZSH_AUTOSUGGEST_CLEAR_WIDGETS[(r)$widget]} ]; then
|
||||
_zsh_autosuggest_bind_widget $widget _zsh_autosuggest_clear
|
||||
for widget in ${${(f)"$(builtin zle -la)"}:#(.*|_*|orig-*|autosuggest-*|$ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX*|zle-line-*|run-help|which-command|beep|set-local-history|yank)}; do
|
||||
if [ ${ZSH_AUTOSUGGEST_CLEAR_WIDGETS[(r)$widget]} ]; then
|
||||
_zsh_autosuggest_bind_widget $widget clear
|
||||
elif [ ${ZSH_AUTOSUGGEST_ACCEPT_WIDGETS[(r)$widget]} ]; then
|
||||
_zsh_autosuggest_bind_widget $widget _zsh_autosuggest_accept
|
||||
_zsh_autosuggest_bind_widget $widget accept
|
||||
elif [ ${ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS[(r)$widget]} ]; then
|
||||
_zsh_autosuggest_bind_widget $widget _zsh_autosuggest_partial_accept
|
||||
_zsh_autosuggest_bind_widget $widget partial_accept
|
||||
else
|
||||
_zsh_autosuggest_bind_widget $widget
|
||||
# Assume any unspecified widget might modify the buffer
|
||||
_zsh_autosuggest_bind_widget $widget modify
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# Given the name of a widget, invoke the original we saved, if it exists
|
||||
_zsh_autosuggest_invoke_original_widget() {
|
||||
local original_widget_name="$ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX$1"
|
||||
local original_widget_name="$ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX$WIDGET"
|
||||
|
||||
if [ $widgets[$original_widget_name] ]; then
|
||||
zle $original_widget_name
|
||||
zle $original_widget_name -- $@
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
#--------------------------------#
|
||||
#--------------------------------------------------------------------#
|
||||
# Global Configuration Variables #
|
||||
#--------------------------------#
|
||||
#--------------------------------------------------------------------#
|
||||
|
||||
# Color to use when highlighting suggestion
|
||||
# Uses format of `region_highlight`
|
||||
@@ -22,27 +22,6 @@ ZSH_AUTOSUGGEST_CLEAR_WIDGETS=(
|
||||
accept-line
|
||||
)
|
||||
|
||||
# Widgets that modify the suggestion
|
||||
ZSH_AUTOSUGGEST_MODIFY_WIDGETS=(
|
||||
list-choices
|
||||
complete-word
|
||||
menu-complete
|
||||
menu-expand-or-complete
|
||||
reverse-menu-complete
|
||||
expand-or-complete
|
||||
expand-or-complete-prefix
|
||||
self-insert
|
||||
magic-space
|
||||
bracketed-paste
|
||||
expand-cmd-path
|
||||
accept-and-menu-complete
|
||||
backward-delete-char
|
||||
vi-backward-delete-char
|
||||
delete-char
|
||||
vi-delete-char
|
||||
delete-char-or-list
|
||||
)
|
||||
|
||||
# Widgets that accept the entire suggestion
|
||||
ZSH_AUTOSUGGEST_ACCEPT_WIDGETS=(
|
||||
forward-char
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
|
||||
#-------------------------------------#
|
||||
#--------------------------------------------------------------------#
|
||||
# Handle Deprecated Variables/Widgets #
|
||||
#-------------------------------------#
|
||||
#--------------------------------------------------------------------#
|
||||
|
||||
unset _ZSH_AUTOSUGGEST_DEPRECATED_START_WIDGET_WARNING_SHOWN
|
||||
_zsh_autosuggest_deprecated_warning() {
|
||||
>&2 echo "zsh-autosuggestions: $@"
|
||||
}
|
||||
|
||||
_zsh_autosuggest_check_deprecated_config() {
|
||||
if [ -n "$AUTOSUGGESTION_HIGHLIGHT_COLOR" ]; then
|
||||
@@ -23,17 +25,12 @@ _zsh_autosuggest_check_deprecated_config() {
|
||||
fi
|
||||
}
|
||||
|
||||
_zsh_autosuggest_deprecated_warning() {
|
||||
>&2 echo "zsh-autosuggestions: $@"
|
||||
}
|
||||
|
||||
_zsh_autosuggest_deprecated_start_widget() {
|
||||
if [ -z "$_ZSH_AUTOSUGGEST_DEPRECATED_START_WIDGET_WARNING_SHOWN" ]; then
|
||||
_zsh_autosuggest_deprecated_warning "The autosuggest-start widget is deprecated. Use the autosuggest_start function instead. For more info, see README at https://github.com/tarruda/zsh-autosuggestions."
|
||||
_ZSH_AUTOSUGGEST_DEPRECATED_START_WIDGET_WARNING_SHOWN=true
|
||||
fi
|
||||
|
||||
autosuggest_start
|
||||
_zsh_autosuggest_deprecated_warning "The autosuggest-start widget is deprecated. For more info, see the README at https://github.com/tarruda/zsh-autosuggestions."
|
||||
zle -D autosuggest-start
|
||||
eval "zle-line-init() {
|
||||
$(echo $functions[${widgets[zle-line-init]#*:}] | sed -e 's/zle autosuggest-start//g')
|
||||
}"
|
||||
}
|
||||
|
||||
zle -N autosuggest-start _zsh_autosuggest_deprecated_start_widget
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
#--------------#
|
||||
#--------------------------------------------------------------------#
|
||||
# Highlighting #
|
||||
#--------------#
|
||||
#--------------------------------------------------------------------#
|
||||
|
||||
# If there was a highlight, remove it
|
||||
_zsh_autosuggest_highlight_reset() {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
#-------#
|
||||
#--------------------------------------------------------------------#
|
||||
# Start #
|
||||
#-------#
|
||||
#--------------------------------------------------------------------#
|
||||
|
||||
# Start the autosuggestion widgets
|
||||
_zsh_autosuggest_start() {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
#------------#
|
||||
#--------------------------------------------------------------------#
|
||||
# Suggestion #
|
||||
#------------#
|
||||
#--------------------------------------------------------------------#
|
||||
|
||||
# Get a suggestion from history that matches a given prefix
|
||||
_zsh_autosuggest_suggestion() {
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
|
||||
#------------------------------------#
|
||||
#--------------------------------------------------------------------#
|
||||
# Autosuggest Widget Implementations #
|
||||
#------------------------------------#
|
||||
#--------------------------------------------------------------------#
|
||||
|
||||
# Clear the suggestion
|
||||
_zsh_autosuggest_clear() {
|
||||
# Remove the suggestion
|
||||
unset POSTDISPLAY
|
||||
|
||||
_zsh_autosuggest_invoke_original_widget $WIDGET
|
||||
_zsh_autosuggest_invoke_original_widget $@
|
||||
}
|
||||
|
||||
# Modify the buffer and get a new suggestion
|
||||
_zsh_autosuggest_modify() {
|
||||
# Original widget modifies the buffer
|
||||
_zsh_autosuggest_invoke_original_widget $WIDGET
|
||||
_zsh_autosuggest_invoke_original_widget $@
|
||||
|
||||
# Get a new suggestion if the buffer is not empty after modification
|
||||
local suggestion
|
||||
@@ -44,7 +44,7 @@ _zsh_autosuggest_accept() {
|
||||
CURSOR=${#BUFFER}
|
||||
fi
|
||||
|
||||
_zsh_autosuggest_invoke_original_widget $WIDGET
|
||||
_zsh_autosuggest_invoke_original_widget $@
|
||||
}
|
||||
|
||||
# Partially accept the suggestion
|
||||
@@ -56,7 +56,7 @@ _zsh_autosuggest_partial_accept() {
|
||||
BUFFER="$BUFFER$POSTDISPLAY"
|
||||
|
||||
# Original widget moves the cursor
|
||||
_zsh_autosuggest_invoke_original_widget $WIDGET
|
||||
_zsh_autosuggest_invoke_original_widget $@
|
||||
|
||||
# If we've moved past the end of the original buffer
|
||||
if [ $CURSOR -gt $#original_buffer ]; then
|
||||
@@ -71,17 +71,13 @@ _zsh_autosuggest_partial_accept() {
|
||||
fi
|
||||
}
|
||||
|
||||
_zsh_autosuggest_widget_accept() {
|
||||
for action in clear modify accept partial_accept; do
|
||||
eval "_zsh_autosuggest_widget_$action() {
|
||||
_zsh_autosuggest_highlight_reset
|
||||
_zsh_autosuggest_accept
|
||||
_zsh_autosuggest_$action \$@
|
||||
_zsh_autosuggest_highlight_apply
|
||||
}
|
||||
|
||||
_zsh_autosuggest_widget_clear() {
|
||||
_zsh_autosuggest_highlight_reset
|
||||
_zsh_autosuggest_clear
|
||||
_zsh_autosuggest_highlight_apply
|
||||
}
|
||||
}"
|
||||
done
|
||||
|
||||
zle -N autosuggest-accept _zsh_autosuggest_widget_accept
|
||||
zle -N autosuggest-clear _zsh_autosuggest_widget_clear
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Fish-like fast/unobtrusive autosuggestions for zsh.
|
||||
# https://github.com/tarruda/zsh-autosuggestions
|
||||
# v0.2.0
|
||||
# v0.2.5
|
||||
# Copyright (c) 2013 Thiago de Arruda
|
||||
# Copyright (c) 2016 Eric Freese
|
||||
#
|
||||
@@ -25,9 +25,9 @@
|
||||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
# OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
#--------------------------------#
|
||||
#--------------------------------------------------------------------#
|
||||
# Global Configuration Variables #
|
||||
#--------------------------------#
|
||||
#--------------------------------------------------------------------#
|
||||
|
||||
# Color to use when highlighting suggestion
|
||||
# Uses format of `region_highlight`
|
||||
@@ -48,27 +48,6 @@ ZSH_AUTOSUGGEST_CLEAR_WIDGETS=(
|
||||
accept-line
|
||||
)
|
||||
|
||||
# Widgets that modify the suggestion
|
||||
ZSH_AUTOSUGGEST_MODIFY_WIDGETS=(
|
||||
list-choices
|
||||
complete-word
|
||||
menu-complete
|
||||
menu-expand-or-complete
|
||||
reverse-menu-complete
|
||||
expand-or-complete
|
||||
expand-or-complete-prefix
|
||||
self-insert
|
||||
magic-space
|
||||
bracketed-paste
|
||||
expand-cmd-path
|
||||
accept-and-menu-complete
|
||||
backward-delete-char
|
||||
vi-backward-delete-char
|
||||
delete-char
|
||||
vi-delete-char
|
||||
delete-char-or-list
|
||||
)
|
||||
|
||||
# Widgets that accept the entire suggestion
|
||||
ZSH_AUTOSUGGEST_ACCEPT_WIDGETS=(
|
||||
forward-char
|
||||
@@ -86,11 +65,13 @@ ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS=(
|
||||
vi-forward-blank-word-end
|
||||
)
|
||||
|
||||
#-------------------------------------#
|
||||
#--------------------------------------------------------------------#
|
||||
# Handle Deprecated Variables/Widgets #
|
||||
#-------------------------------------#
|
||||
#--------------------------------------------------------------------#
|
||||
|
||||
unset _ZSH_AUTOSUGGEST_DEPRECATED_START_WIDGET_WARNING_SHOWN
|
||||
_zsh_autosuggest_deprecated_warning() {
|
||||
>&2 echo "zsh-autosuggestions: $@"
|
||||
}
|
||||
|
||||
_zsh_autosuggest_check_deprecated_config() {
|
||||
if [ -n "$AUTOSUGGESTION_HIGHLIGHT_COLOR" ]; then
|
||||
@@ -110,35 +91,30 @@ _zsh_autosuggest_check_deprecated_config() {
|
||||
fi
|
||||
}
|
||||
|
||||
_zsh_autosuggest_deprecated_warning() {
|
||||
>&2 echo "zsh-autosuggestions: $@"
|
||||
}
|
||||
|
||||
_zsh_autosuggest_deprecated_start_widget() {
|
||||
if [ -z "$_ZSH_AUTOSUGGEST_DEPRECATED_START_WIDGET_WARNING_SHOWN" ]; then
|
||||
_zsh_autosuggest_deprecated_warning "The autosuggest-start widget is deprecated. Use the autosuggest_start function instead. For more info, see README at https://github.com/tarruda/zsh-autosuggestions."
|
||||
_ZSH_AUTOSUGGEST_DEPRECATED_START_WIDGET_WARNING_SHOWN=true
|
||||
fi
|
||||
|
||||
autosuggest_start
|
||||
_zsh_autosuggest_deprecated_warning "The autosuggest-start widget is deprecated. For more info, see the README at https://github.com/tarruda/zsh-autosuggestions."
|
||||
zle -D autosuggest-start
|
||||
eval "zle-line-init() {
|
||||
$(echo $functions[${widgets[zle-line-init]#*:}] | sed -e 's/zle autosuggest-start//g')
|
||||
}"
|
||||
}
|
||||
|
||||
zle -N autosuggest-start _zsh_autosuggest_deprecated_start_widget
|
||||
|
||||
#----------------#
|
||||
#--------------------------------------------------------------------#
|
||||
# Widget Helpers #
|
||||
#----------------#
|
||||
#--------------------------------------------------------------------#
|
||||
|
||||
# Bind a single widget to an autosuggest widget, saving a reference to the original widget
|
||||
_zsh_autosuggest_bind_widget() {
|
||||
local widget=$1
|
||||
local autosuggest_function=$2
|
||||
local autosuggest_action=$2
|
||||
local prefix=$ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX
|
||||
local action
|
||||
|
||||
# Save a reference to the original widget
|
||||
case $widgets[$widget] in
|
||||
# Already bound
|
||||
user:_zsh_autosuggest_(bound|orig)_*);;
|
||||
user:_zsh_autosuggest_(widget|orig)_*);;
|
||||
|
||||
# User-defined widget
|
||||
user:*)
|
||||
@@ -157,23 +133,8 @@ _zsh_autosuggest_bind_widget() {
|
||||
;;
|
||||
esac
|
||||
|
||||
# Set up widget to call $autosuggest_function if it exists
|
||||
# Otherwise just call the original widget
|
||||
if [ -n "$autosuggest_function" ]; then;
|
||||
action=$autosuggest_function;
|
||||
else;
|
||||
action="zle $prefix$widget \$@"
|
||||
fi
|
||||
|
||||
# Create new function for the widget that highlights and calls the action
|
||||
eval "_zsh_autosuggest_bound_$widget() {
|
||||
_zsh_autosuggest_highlight_reset
|
||||
$action
|
||||
_zsh_autosuggest_highlight_apply
|
||||
}"
|
||||
|
||||
# Create the bound widget
|
||||
zle -N $widget _zsh_autosuggest_bound_$widget
|
||||
zle -N $widget _zsh_autosuggest_widget_$autosuggest_action
|
||||
}
|
||||
|
||||
# Map all configured widgets to the right autosuggest widgets
|
||||
@@ -181,33 +142,32 @@ _zsh_autosuggest_bind_widgets() {
|
||||
local widget;
|
||||
|
||||
# Find every widget we might want to bind and bind it appropriately
|
||||
for widget in ${${(f)"$(builtin zle -la)"}:#(.*|_*|orig-*|autosuggest-*|$ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX*|run-help|which-command|beep|set-local-history|yank)}; do
|
||||
if [ ${ZSH_AUTOSUGGEST_MODIFY_WIDGETS[(r)$widget]} ]; then
|
||||
_zsh_autosuggest_bind_widget $widget _zsh_autosuggest_modify
|
||||
elif [ ${ZSH_AUTOSUGGEST_CLEAR_WIDGETS[(r)$widget]} ]; then
|
||||
_zsh_autosuggest_bind_widget $widget _zsh_autosuggest_clear
|
||||
for widget in ${${(f)"$(builtin zle -la)"}:#(.*|_*|orig-*|autosuggest-*|$ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX*|zle-line-*|run-help|which-command|beep|set-local-history|yank)}; do
|
||||
if [ ${ZSH_AUTOSUGGEST_CLEAR_WIDGETS[(r)$widget]} ]; then
|
||||
_zsh_autosuggest_bind_widget $widget clear
|
||||
elif [ ${ZSH_AUTOSUGGEST_ACCEPT_WIDGETS[(r)$widget]} ]; then
|
||||
_zsh_autosuggest_bind_widget $widget _zsh_autosuggest_accept
|
||||
_zsh_autosuggest_bind_widget $widget accept
|
||||
elif [ ${ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS[(r)$widget]} ]; then
|
||||
_zsh_autosuggest_bind_widget $widget _zsh_autosuggest_partial_accept
|
||||
_zsh_autosuggest_bind_widget $widget partial_accept
|
||||
else
|
||||
_zsh_autosuggest_bind_widget $widget
|
||||
# Assume any unspecified widget might modify the buffer
|
||||
_zsh_autosuggest_bind_widget $widget modify
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# Given the name of a widget, invoke the original we saved, if it exists
|
||||
_zsh_autosuggest_invoke_original_widget() {
|
||||
local original_widget_name="$ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX$1"
|
||||
local original_widget_name="$ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX$WIDGET"
|
||||
|
||||
if [ $widgets[$original_widget_name] ]; then
|
||||
zle $original_widget_name
|
||||
zle $original_widget_name -- $@
|
||||
fi
|
||||
}
|
||||
|
||||
#--------------#
|
||||
#--------------------------------------------------------------------#
|
||||
# Highlighting #
|
||||
#--------------#
|
||||
#--------------------------------------------------------------------#
|
||||
|
||||
# If there was a highlight, remove it
|
||||
_zsh_autosuggest_highlight_reset() {
|
||||
@@ -227,22 +187,22 @@ _zsh_autosuggest_highlight_apply() {
|
||||
fi
|
||||
}
|
||||
|
||||
#------------------------------------#
|
||||
#--------------------------------------------------------------------#
|
||||
# Autosuggest Widget Implementations #
|
||||
#------------------------------------#
|
||||
#--------------------------------------------------------------------#
|
||||
|
||||
# Clear the suggestion
|
||||
_zsh_autosuggest_clear() {
|
||||
# Remove the suggestion
|
||||
unset POSTDISPLAY
|
||||
|
||||
_zsh_autosuggest_invoke_original_widget $WIDGET
|
||||
_zsh_autosuggest_invoke_original_widget $@
|
||||
}
|
||||
|
||||
# Modify the buffer and get a new suggestion
|
||||
_zsh_autosuggest_modify() {
|
||||
# Original widget modifies the buffer
|
||||
_zsh_autosuggest_invoke_original_widget $WIDGET
|
||||
_zsh_autosuggest_invoke_original_widget $@
|
||||
|
||||
# Get a new suggestion if the buffer is not empty after modification
|
||||
local suggestion
|
||||
@@ -272,7 +232,7 @@ _zsh_autosuggest_accept() {
|
||||
CURSOR=${#BUFFER}
|
||||
fi
|
||||
|
||||
_zsh_autosuggest_invoke_original_widget $WIDGET
|
||||
_zsh_autosuggest_invoke_original_widget $@
|
||||
}
|
||||
|
||||
# Partially accept the suggestion
|
||||
@@ -284,7 +244,7 @@ _zsh_autosuggest_partial_accept() {
|
||||
BUFFER="$BUFFER$POSTDISPLAY"
|
||||
|
||||
# Original widget moves the cursor
|
||||
_zsh_autosuggest_invoke_original_widget $WIDGET
|
||||
_zsh_autosuggest_invoke_original_widget $@
|
||||
|
||||
# If we've moved past the end of the original buffer
|
||||
if [ $CURSOR -gt $#original_buffer ]; then
|
||||
@@ -299,24 +259,20 @@ _zsh_autosuggest_partial_accept() {
|
||||
fi
|
||||
}
|
||||
|
||||
_zsh_autosuggest_widget_accept() {
|
||||
for action in clear modify accept partial_accept; do
|
||||
eval "_zsh_autosuggest_widget_$action() {
|
||||
_zsh_autosuggest_highlight_reset
|
||||
_zsh_autosuggest_accept
|
||||
_zsh_autosuggest_$action \$@
|
||||
_zsh_autosuggest_highlight_apply
|
||||
}
|
||||
|
||||
_zsh_autosuggest_widget_clear() {
|
||||
_zsh_autosuggest_highlight_reset
|
||||
_zsh_autosuggest_clear
|
||||
_zsh_autosuggest_highlight_apply
|
||||
}
|
||||
}"
|
||||
done
|
||||
|
||||
zle -N autosuggest-accept _zsh_autosuggest_widget_accept
|
||||
zle -N autosuggest-clear _zsh_autosuggest_widget_clear
|
||||
|
||||
#------------#
|
||||
#--------------------------------------------------------------------#
|
||||
# Suggestion #
|
||||
#------------#
|
||||
#--------------------------------------------------------------------#
|
||||
|
||||
# Get a suggestion from history that matches a given prefix
|
||||
_zsh_autosuggest_suggestion() {
|
||||
@@ -333,9 +289,9 @@ _zsh_autosuggest_suggestion() {
|
||||
echo ${history_matches[1]}
|
||||
}
|
||||
|
||||
#-------#
|
||||
#--------------------------------------------------------------------#
|
||||
# Start #
|
||||
#-------#
|
||||
#--------------------------------------------------------------------#
|
||||
|
||||
# Start the autosuggestion widgets
|
||||
_zsh_autosuggest_start() {
|
||||
|
||||
Reference in New Issue
Block a user