mirror of
https://github.com/zsh-users/zsh-autosuggestions.git
synced 2026-03-11 04:55:25 +08:00
Compare commits
1 Commits
fixes/part
...
features/b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
767d55eba0 |
10
README.md
10
README.md
@@ -79,11 +79,9 @@ Widgets that modify the buffer and are not found in any of these arrays will fet
|
|||||||
Set `ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE` to an integer value to disable autosuggestion for large buffers. The default is unset, which means that autosuggestion will be tried for any buffer size. Recommended value is 20.
|
Set `ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE` to an integer value to disable autosuggestion for large buffers. The default is unset, which means that autosuggestion will be tried for any buffer size. Recommended value is 20.
|
||||||
This can be useful when pasting large amount of text in the terminal, to avoid triggering autosuggestion for strings that are too long.
|
This can be useful when pasting large amount of text in the terminal, to avoid triggering autosuggestion for strings that are too long.
|
||||||
|
|
||||||
### Asynchronous Mode
|
### Enable Asynchronous Mode
|
||||||
|
|
||||||
Suggestions are fetched asynchronously by default in zsh versions 5.0.8 and greater. To disable asynchronous suggestions and fetch them synchronously instead, `unset ZSH_AUTOSUGGEST_USE_ASYNC` after sourcing the plugin.
|
As of `v0.4.0`, suggestions can be fetched asynchronously. To enable this behavior, set the `ZSH_AUTOSUGGEST_USE_ASYNC` variable (it can be set to anything).
|
||||||
|
|
||||||
Alternatively, if you are using a version of zsh older than 5.0.8 and want to enable asynchronous mode, set the `ZSH_AUTOSUGGEST_USE_ASYNC` variable after sourcing the plugin (it can be set to anything). Note that there is [a bug](https://github.com/zsh-users/zsh-autosuggestions/issues/364#issuecomment-481423232) in versions of zsh older than 5.0.8 where <kbd>ctrl</kbd> + <kbd>c</kbd> will fail to reset the prompt immediately after fetching a suggestion asynchronously.
|
|
||||||
|
|
||||||
### Disabling automatic widget re-binding
|
### Disabling automatic widget re-binding
|
||||||
|
|
||||||
@@ -91,13 +89,13 @@ Set `ZSH_AUTOSUGGEST_MANUAL_REBIND` (it can be set to anything) to disable autom
|
|||||||
|
|
||||||
### Ignoring history suggestions that match a pattern
|
### Ignoring history suggestions that match a pattern
|
||||||
|
|
||||||
Set `ZSH_AUTOSUGGEST_HISTORY_IGNORE` to a [glob pattern](http://zsh.sourceforge.net/Doc/Release/Expansion.html#Glob-Operators) to prevent offering suggestions for history entries that match the pattern. For example, set it to `"cd *"` to never suggest any `cd` commands from history. Or set to `"?(#c50,)"` to never suggest anything 50 characters or longer.
|
Set `ZSH_AUTOSUGGEST_HISTORY_IGNORE` to a glob pattern to prevent offering suggestions for history entries that match the pattern. For example, set it to `"cd *"` to never suggest any `cd` commands from history. Or set to `"?(#c50,)"` to never suggest anything 50 characters or longer.
|
||||||
|
|
||||||
**Note:** This only affects the `history` and `match_prev_cmd` suggestion strategies.
|
**Note:** This only affects the `history` and `match_prev_cmd` suggestion strategies.
|
||||||
|
|
||||||
### Skipping completion suggestions for certain cases
|
### Skipping completion suggestions for certain cases
|
||||||
|
|
||||||
Set `ZSH_AUTOSUGGEST_COMPLETION_IGNORE` to a [glob pattern](http://zsh.sourceforge.net/Doc/Release/Expansion.html#Glob-Operators) to prevent offering completion suggestions when the buffer matches that pattern. For example, set it to `"git *"` to disable completion suggestions for git subcommands.
|
Set `ZSH_AUTOSUGGEST_COMPLETION_IGNORE` to a glob pattern to prevent offering completion suggestions when the buffer matches that pattern. For example, set it to `"git *"` to disable completion suggestions for git subcommands.
|
||||||
|
|
||||||
**Note:** This only affects the `completion` suggestion strategy.
|
**Note:** This only affects the `completion` suggestion strategy.
|
||||||
|
|
||||||
|
|||||||
7
spec/options/use_async_spec.rb
Normal file
7
spec/options/use_async_spec.rb
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
describe 'suggestion fetching' do
|
||||||
|
it 'is performed synchronously'
|
||||||
|
|
||||||
|
context 'when ZSH_AUTOSUGGEST_USE_ASYNC is set' do
|
||||||
|
it 'is performed asynchronously'
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -69,7 +69,7 @@ _zsh_autosuggest_bind_widgets() {
|
|||||||
ignore_widgets=(
|
ignore_widgets=(
|
||||||
.\*
|
.\*
|
||||||
_\*
|
_\*
|
||||||
${_ZSH_AUTOSUGGEST_BUILTIN_ACTIONS/#/autosuggest-}
|
autosuggest-\*
|
||||||
$ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX\*
|
$ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX\*
|
||||||
$ZSH_AUTOSUGGEST_IGNORE_WIDGETS
|
$ZSH_AUTOSUGGEST_IGNORE_WIDGETS
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -21,13 +21,11 @@ _zsh_autosuggest_start() {
|
|||||||
# Mark for auto-loading the functions that we use
|
# Mark for auto-loading the functions that we use
|
||||||
autoload -Uz add-zsh-hook is-at-least
|
autoload -Uz add-zsh-hook is-at-least
|
||||||
|
|
||||||
# Automatically enable asynchronous mode in newer versions of zsh. Disable for
|
# If zle is already running, go ahead and start the autosuggestion widgets.
|
||||||
# older versions because there is a bug when using async mode where ^C does not
|
# Otherwise, wait until the next precmd.
|
||||||
# work immediately after fetching a suggestion.
|
if zle; then
|
||||||
# See https://github.com/zsh-users/zsh-autosuggestions/issues/364
|
_zsh_autosuggest_start
|
||||||
if is-at-least 5.0.8; then
|
(( ! ${+ZSH_AUTOSUGGEST_MANUAL_REBIND} )) && add-zsh-hook precmd _zsh_autosuggest_start
|
||||||
typeset -g ZSH_AUTOSUGGEST_USE_ASYNC=
|
else
|
||||||
|
add-zsh-hook precmd _zsh_autosuggest_start
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Start the autosuggestion widgets on the next precmd
|
|
||||||
add-zsh-hook precmd _zsh_autosuggest_start
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ _zsh_autosuggest_enable() {
|
|||||||
|
|
||||||
# Toggle suggestions (enable/disable)
|
# Toggle suggestions (enable/disable)
|
||||||
_zsh_autosuggest_toggle() {
|
_zsh_autosuggest_toggle() {
|
||||||
if (( ${+_ZSH_AUTOSUGGEST_DISABLED} )); then
|
if [[ -n "${_ZSH_AUTOSUGGEST_DISABLED+x}" ]]; then
|
||||||
_zsh_autosuggest_enable
|
_zsh_autosuggest_enable
|
||||||
else
|
else
|
||||||
_zsh_autosuggest_disable
|
_zsh_autosuggest_disable
|
||||||
@@ -79,7 +79,7 @@ _zsh_autosuggest_modify() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Bail out if suggestions are disabled
|
# Bail out if suggestions are disabled
|
||||||
if (( ${+_ZSH_AUTOSUGGEST_DISABLED} )); then
|
if [[ -n "${_ZSH_AUTOSUGGEST_DISABLED+x}" ]]; then
|
||||||
return $?
|
return $?
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -173,13 +173,11 @@ _zsh_autosuggest_execute() {
|
|||||||
_zsh_autosuggest_partial_accept() {
|
_zsh_autosuggest_partial_accept() {
|
||||||
local -i retval cursor_loc
|
local -i retval cursor_loc
|
||||||
|
|
||||||
# Save the original buffer/postdisplay so we can restore later if needed
|
# Save the contents of the buffer so we can restore later if needed
|
||||||
local original_buffer="$BUFFER"
|
local original_buffer="$BUFFER"
|
||||||
local original_postdisplay="$POSTDISPLAY"
|
|
||||||
|
|
||||||
# Temporarily accept the suggestion.
|
# Temporarily accept the suggestion.
|
||||||
BUFFER="$BUFFER$POSTDISPLAY"
|
BUFFER="$BUFFER$POSTDISPLAY"
|
||||||
unset POSTDISPLAY
|
|
||||||
|
|
||||||
# Original widget moves the cursor
|
# Original widget moves the cursor
|
||||||
_zsh_autosuggest_invoke_original_widget $@
|
_zsh_autosuggest_invoke_original_widget $@
|
||||||
@@ -199,30 +197,16 @@ _zsh_autosuggest_partial_accept() {
|
|||||||
# Clip the buffer at the cursor
|
# Clip the buffer at the cursor
|
||||||
BUFFER="${BUFFER[1,$cursor_loc]}"
|
BUFFER="${BUFFER[1,$cursor_loc]}"
|
||||||
else
|
else
|
||||||
# Restore the original buffer/postdisplay
|
# Restore the original buffer
|
||||||
BUFFER="$original_buffer"
|
BUFFER="$original_buffer"
|
||||||
POSTDISPLAY="$original_postdisplay"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
return $retval
|
return $retval
|
||||||
}
|
}
|
||||||
|
|
||||||
() {
|
() {
|
||||||
typeset -ga _ZSH_AUTOSUGGEST_BUILTIN_ACTIONS
|
|
||||||
|
|
||||||
_ZSH_AUTOSUGGEST_BUILTIN_ACTIONS=(
|
|
||||||
clear
|
|
||||||
fetch
|
|
||||||
suggest
|
|
||||||
accept
|
|
||||||
execute
|
|
||||||
enable
|
|
||||||
disable
|
|
||||||
toggle
|
|
||||||
)
|
|
||||||
|
|
||||||
local action
|
local action
|
||||||
for action in $_ZSH_AUTOSUGGEST_BUILTIN_ACTIONS modify partial_accept; do
|
for action in clear modify fetch suggest accept partial_accept execute enable disable toggle; do
|
||||||
eval "_zsh_autosuggest_widget_$action() {
|
eval "_zsh_autosuggest_widget_$action() {
|
||||||
local -i retval
|
local -i retval
|
||||||
|
|
||||||
@@ -239,7 +223,12 @@ _zsh_autosuggest_partial_accept() {
|
|||||||
}"
|
}"
|
||||||
done
|
done
|
||||||
|
|
||||||
for action in $_ZSH_AUTOSUGGEST_BUILTIN_ACTIONS; do
|
zle -N autosuggest-fetch _zsh_autosuggest_widget_fetch
|
||||||
zle -N autosuggest-$action _zsh_autosuggest_widget_$action
|
zle -N autosuggest-suggest _zsh_autosuggest_widget_suggest
|
||||||
done
|
zle -N autosuggest-accept _zsh_autosuggest_widget_accept
|
||||||
|
zle -N autosuggest-clear _zsh_autosuggest_widget_clear
|
||||||
|
zle -N autosuggest-execute _zsh_autosuggest_widget_execute
|
||||||
|
zle -N autosuggest-enable _zsh_autosuggest_widget_enable
|
||||||
|
zle -N autosuggest-disable _zsh_autosuggest_widget_disable
|
||||||
|
zle -N autosuggest-toggle _zsh_autosuggest_widget_toggle
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -199,7 +199,7 @@ _zsh_autosuggest_bind_widgets() {
|
|||||||
ignore_widgets=(
|
ignore_widgets=(
|
||||||
.\*
|
.\*
|
||||||
_\*
|
_\*
|
||||||
${_ZSH_AUTOSUGGEST_BUILTIN_ACTIONS/#/autosuggest-}
|
autosuggest-\*
|
||||||
$ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX\*
|
$ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX\*
|
||||||
$ZSH_AUTOSUGGEST_IGNORE_WIDGETS
|
$ZSH_AUTOSUGGEST_IGNORE_WIDGETS
|
||||||
)
|
)
|
||||||
@@ -282,7 +282,7 @@ _zsh_autosuggest_enable() {
|
|||||||
|
|
||||||
# Toggle suggestions (enable/disable)
|
# Toggle suggestions (enable/disable)
|
||||||
_zsh_autosuggest_toggle() {
|
_zsh_autosuggest_toggle() {
|
||||||
if (( ${+_ZSH_AUTOSUGGEST_DISABLED} )); then
|
if [[ -n "${_ZSH_AUTOSUGGEST_DISABLED+x}" ]]; then
|
||||||
_zsh_autosuggest_enable
|
_zsh_autosuggest_enable
|
||||||
else
|
else
|
||||||
_zsh_autosuggest_disable
|
_zsh_autosuggest_disable
|
||||||
@@ -341,7 +341,7 @@ _zsh_autosuggest_modify() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Bail out if suggestions are disabled
|
# Bail out if suggestions are disabled
|
||||||
if (( ${+_ZSH_AUTOSUGGEST_DISABLED} )); then
|
if [[ -n "${_ZSH_AUTOSUGGEST_DISABLED+x}" ]]; then
|
||||||
return $?
|
return $?
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -435,13 +435,11 @@ _zsh_autosuggest_execute() {
|
|||||||
_zsh_autosuggest_partial_accept() {
|
_zsh_autosuggest_partial_accept() {
|
||||||
local -i retval cursor_loc
|
local -i retval cursor_loc
|
||||||
|
|
||||||
# Save the original buffer/postdisplay so we can restore later if needed
|
# Save the contents of the buffer so we can restore later if needed
|
||||||
local original_buffer="$BUFFER"
|
local original_buffer="$BUFFER"
|
||||||
local original_postdisplay="$POSTDISPLAY"
|
|
||||||
|
|
||||||
# Temporarily accept the suggestion.
|
# Temporarily accept the suggestion.
|
||||||
BUFFER="$BUFFER$POSTDISPLAY"
|
BUFFER="$BUFFER$POSTDISPLAY"
|
||||||
unset POSTDISPLAY
|
|
||||||
|
|
||||||
# Original widget moves the cursor
|
# Original widget moves the cursor
|
||||||
_zsh_autosuggest_invoke_original_widget $@
|
_zsh_autosuggest_invoke_original_widget $@
|
||||||
@@ -461,30 +459,16 @@ _zsh_autosuggest_partial_accept() {
|
|||||||
# Clip the buffer at the cursor
|
# Clip the buffer at the cursor
|
||||||
BUFFER="${BUFFER[1,$cursor_loc]}"
|
BUFFER="${BUFFER[1,$cursor_loc]}"
|
||||||
else
|
else
|
||||||
# Restore the original buffer/postdisplay
|
# Restore the original buffer
|
||||||
BUFFER="$original_buffer"
|
BUFFER="$original_buffer"
|
||||||
POSTDISPLAY="$original_postdisplay"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
return $retval
|
return $retval
|
||||||
}
|
}
|
||||||
|
|
||||||
() {
|
() {
|
||||||
typeset -ga _ZSH_AUTOSUGGEST_BUILTIN_ACTIONS
|
|
||||||
|
|
||||||
_ZSH_AUTOSUGGEST_BUILTIN_ACTIONS=(
|
|
||||||
clear
|
|
||||||
fetch
|
|
||||||
suggest
|
|
||||||
accept
|
|
||||||
execute
|
|
||||||
enable
|
|
||||||
disable
|
|
||||||
toggle
|
|
||||||
)
|
|
||||||
|
|
||||||
local action
|
local action
|
||||||
for action in $_ZSH_AUTOSUGGEST_BUILTIN_ACTIONS modify partial_accept; do
|
for action in clear modify fetch suggest accept partial_accept execute enable disable toggle; do
|
||||||
eval "_zsh_autosuggest_widget_$action() {
|
eval "_zsh_autosuggest_widget_$action() {
|
||||||
local -i retval
|
local -i retval
|
||||||
|
|
||||||
@@ -501,9 +485,14 @@ _zsh_autosuggest_partial_accept() {
|
|||||||
}"
|
}"
|
||||||
done
|
done
|
||||||
|
|
||||||
for action in $_ZSH_AUTOSUGGEST_BUILTIN_ACTIONS; do
|
zle -N autosuggest-fetch _zsh_autosuggest_widget_fetch
|
||||||
zle -N autosuggest-$action _zsh_autosuggest_widget_$action
|
zle -N autosuggest-suggest _zsh_autosuggest_widget_suggest
|
||||||
done
|
zle -N autosuggest-accept _zsh_autosuggest_widget_accept
|
||||||
|
zle -N autosuggest-clear _zsh_autosuggest_widget_clear
|
||||||
|
zle -N autosuggest-execute _zsh_autosuggest_widget_execute
|
||||||
|
zle -N autosuggest-enable _zsh_autosuggest_widget_enable
|
||||||
|
zle -N autosuggest-disable _zsh_autosuggest_widget_disable
|
||||||
|
zle -N autosuggest-toggle _zsh_autosuggest_widget_toggle
|
||||||
}
|
}
|
||||||
|
|
||||||
#--------------------------------------------------------------------#
|
#--------------------------------------------------------------------#
|
||||||
@@ -865,13 +854,11 @@ _zsh_autosuggest_start() {
|
|||||||
# Mark for auto-loading the functions that we use
|
# Mark for auto-loading the functions that we use
|
||||||
autoload -Uz add-zsh-hook is-at-least
|
autoload -Uz add-zsh-hook is-at-least
|
||||||
|
|
||||||
# Automatically enable asynchronous mode in newer versions of zsh. Disable for
|
# If zle is already running, go ahead and start the autosuggestion widgets.
|
||||||
# older versions because there is a bug when using async mode where ^C does not
|
# Otherwise, wait until the next precmd.
|
||||||
# work immediately after fetching a suggestion.
|
if zle; then
|
||||||
# See https://github.com/zsh-users/zsh-autosuggestions/issues/364
|
_zsh_autosuggest_start
|
||||||
if is-at-least 5.0.8; then
|
(( ! ${+ZSH_AUTOSUGGEST_MANUAL_REBIND} )) && add-zsh-hook precmd _zsh_autosuggest_start
|
||||||
typeset -g ZSH_AUTOSUGGEST_USE_ASYNC=
|
else
|
||||||
|
add-zsh-hook precmd _zsh_autosuggest_start
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Start the autosuggestion widgets on the next precmd
|
|
||||||
add-zsh-hook precmd _zsh_autosuggest_start
|
|
||||||
|
|||||||
Reference in New Issue
Block a user