mirror of
https://github.com/zsh-users/zsh-autosuggestions.git
synced 2025-12-06 07:10:40 +01:00
Compare commits
10 Commits
features/b
...
fixes/part
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4ccfdb2435 | ||
|
|
9ad039443f | ||
|
|
a32fe24acc | ||
|
|
e3897c25c0 | ||
|
|
ee18c7ce24 | ||
|
|
a83c7cf9d6 | ||
|
|
6c634c1e35 | ||
|
|
c114bd2298 | ||
|
|
7682c13860 | ||
|
|
f90d040784 |
10
README.md
10
README.md
@@ -79,9 +79,11 @@ 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.
|
||||
This can be useful when pasting large amount of text in the terminal, to avoid triggering autosuggestion for strings that are too long.
|
||||
|
||||
### Enable Asynchronous Mode
|
||||
### Asynchronous Mode
|
||||
|
||||
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).
|
||||
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.
|
||||
|
||||
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
|
||||
|
||||
@@ -89,13 +91,13 @@ Set `ZSH_AUTOSUGGEST_MANUAL_REBIND` (it can be set to anything) to disable autom
|
||||
|
||||
### Ignoring history suggestions that match a pattern
|
||||
|
||||
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.
|
||||
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.
|
||||
|
||||
**Note:** This only affects the `history` and `match_prev_cmd` suggestion strategies.
|
||||
|
||||
### Skipping completion suggestions for certain cases
|
||||
|
||||
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.
|
||||
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.
|
||||
|
||||
**Note:** This only affects the `completion` suggestion strategy.
|
||||
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
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=(
|
||||
.\*
|
||||
_\*
|
||||
autosuggest-\*
|
||||
${_ZSH_AUTOSUGGEST_BUILTIN_ACTIONS/#/autosuggest-}
|
||||
$ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX\*
|
||||
$ZSH_AUTOSUGGEST_IGNORE_WIDGETS
|
||||
)
|
||||
|
||||
@@ -21,11 +21,13 @@ _zsh_autosuggest_start() {
|
||||
# Mark for auto-loading the functions that we use
|
||||
autoload -Uz add-zsh-hook is-at-least
|
||||
|
||||
# If zle is already running, go ahead and start the autosuggestion widgets.
|
||||
# Otherwise, wait until the next precmd.
|
||||
if zle; then
|
||||
_zsh_autosuggest_start
|
||||
(( ! ${+ZSH_AUTOSUGGEST_MANUAL_REBIND} )) && add-zsh-hook precmd _zsh_autosuggest_start
|
||||
else
|
||||
add-zsh-hook precmd _zsh_autosuggest_start
|
||||
# Automatically enable asynchronous mode in newer versions of zsh. Disable for
|
||||
# older versions because there is a bug when using async mode where ^C does not
|
||||
# work immediately after fetching a suggestion.
|
||||
# See https://github.com/zsh-users/zsh-autosuggestions/issues/364
|
||||
if is-at-least 5.0.8; then
|
||||
typeset -g ZSH_AUTOSUGGEST_USE_ASYNC=
|
||||
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)
|
||||
_zsh_autosuggest_toggle() {
|
||||
if [[ -n "${_ZSH_AUTOSUGGEST_DISABLED+x}" ]]; then
|
||||
if (( ${+_ZSH_AUTOSUGGEST_DISABLED} )); then
|
||||
_zsh_autosuggest_enable
|
||||
else
|
||||
_zsh_autosuggest_disable
|
||||
@@ -79,7 +79,7 @@ _zsh_autosuggest_modify() {
|
||||
fi
|
||||
|
||||
# Bail out if suggestions are disabled
|
||||
if [[ -n "${_ZSH_AUTOSUGGEST_DISABLED+x}" ]]; then
|
||||
if (( ${+_ZSH_AUTOSUGGEST_DISABLED} )); then
|
||||
return $?
|
||||
fi
|
||||
|
||||
@@ -173,11 +173,13 @@ _zsh_autosuggest_execute() {
|
||||
_zsh_autosuggest_partial_accept() {
|
||||
local -i retval cursor_loc
|
||||
|
||||
# Save the contents of the buffer so we can restore later if needed
|
||||
# Save the original buffer/postdisplay so we can restore later if needed
|
||||
local original_buffer="$BUFFER"
|
||||
local original_postdisplay="$POSTDISPLAY"
|
||||
|
||||
# Temporarily accept the suggestion.
|
||||
BUFFER="$BUFFER$POSTDISPLAY"
|
||||
unset POSTDISPLAY
|
||||
|
||||
# Original widget moves the cursor
|
||||
_zsh_autosuggest_invoke_original_widget $@
|
||||
@@ -197,16 +199,30 @@ _zsh_autosuggest_partial_accept() {
|
||||
# Clip the buffer at the cursor
|
||||
BUFFER="${BUFFER[1,$cursor_loc]}"
|
||||
else
|
||||
# Restore the original buffer
|
||||
# Restore the original buffer/postdisplay
|
||||
BUFFER="$original_buffer"
|
||||
POSTDISPLAY="$original_postdisplay"
|
||||
fi
|
||||
|
||||
return $retval
|
||||
}
|
||||
|
||||
() {
|
||||
typeset -ga _ZSH_AUTOSUGGEST_BUILTIN_ACTIONS
|
||||
|
||||
_ZSH_AUTOSUGGEST_BUILTIN_ACTIONS=(
|
||||
clear
|
||||
fetch
|
||||
suggest
|
||||
accept
|
||||
execute
|
||||
enable
|
||||
disable
|
||||
toggle
|
||||
)
|
||||
|
||||
local action
|
||||
for action in clear modify fetch suggest accept partial_accept execute enable disable toggle; do
|
||||
for action in $_ZSH_AUTOSUGGEST_BUILTIN_ACTIONS modify partial_accept; do
|
||||
eval "_zsh_autosuggest_widget_$action() {
|
||||
local -i retval
|
||||
|
||||
@@ -223,12 +239,7 @@ _zsh_autosuggest_partial_accept() {
|
||||
}"
|
||||
done
|
||||
|
||||
zle -N autosuggest-fetch _zsh_autosuggest_widget_fetch
|
||||
zle -N autosuggest-suggest _zsh_autosuggest_widget_suggest
|
||||
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
|
||||
for action in $_ZSH_AUTOSUGGEST_BUILTIN_ACTIONS; do
|
||||
zle -N autosuggest-$action _zsh_autosuggest_widget_$action
|
||||
done
|
||||
}
|
||||
|
||||
@@ -199,7 +199,7 @@ _zsh_autosuggest_bind_widgets() {
|
||||
ignore_widgets=(
|
||||
.\*
|
||||
_\*
|
||||
autosuggest-\*
|
||||
${_ZSH_AUTOSUGGEST_BUILTIN_ACTIONS/#/autosuggest-}
|
||||
$ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX\*
|
||||
$ZSH_AUTOSUGGEST_IGNORE_WIDGETS
|
||||
)
|
||||
@@ -282,7 +282,7 @@ _zsh_autosuggest_enable() {
|
||||
|
||||
# Toggle suggestions (enable/disable)
|
||||
_zsh_autosuggest_toggle() {
|
||||
if [[ -n "${_ZSH_AUTOSUGGEST_DISABLED+x}" ]]; then
|
||||
if (( ${+_ZSH_AUTOSUGGEST_DISABLED} )); then
|
||||
_zsh_autosuggest_enable
|
||||
else
|
||||
_zsh_autosuggest_disable
|
||||
@@ -341,7 +341,7 @@ _zsh_autosuggest_modify() {
|
||||
fi
|
||||
|
||||
# Bail out if suggestions are disabled
|
||||
if [[ -n "${_ZSH_AUTOSUGGEST_DISABLED+x}" ]]; then
|
||||
if (( ${+_ZSH_AUTOSUGGEST_DISABLED} )); then
|
||||
return $?
|
||||
fi
|
||||
|
||||
@@ -435,11 +435,13 @@ _zsh_autosuggest_execute() {
|
||||
_zsh_autosuggest_partial_accept() {
|
||||
local -i retval cursor_loc
|
||||
|
||||
# Save the contents of the buffer so we can restore later if needed
|
||||
# Save the original buffer/postdisplay so we can restore later if needed
|
||||
local original_buffer="$BUFFER"
|
||||
local original_postdisplay="$POSTDISPLAY"
|
||||
|
||||
# Temporarily accept the suggestion.
|
||||
BUFFER="$BUFFER$POSTDISPLAY"
|
||||
unset POSTDISPLAY
|
||||
|
||||
# Original widget moves the cursor
|
||||
_zsh_autosuggest_invoke_original_widget $@
|
||||
@@ -459,16 +461,30 @@ _zsh_autosuggest_partial_accept() {
|
||||
# Clip the buffer at the cursor
|
||||
BUFFER="${BUFFER[1,$cursor_loc]}"
|
||||
else
|
||||
# Restore the original buffer
|
||||
# Restore the original buffer/postdisplay
|
||||
BUFFER="$original_buffer"
|
||||
POSTDISPLAY="$original_postdisplay"
|
||||
fi
|
||||
|
||||
return $retval
|
||||
}
|
||||
|
||||
() {
|
||||
typeset -ga _ZSH_AUTOSUGGEST_BUILTIN_ACTIONS
|
||||
|
||||
_ZSH_AUTOSUGGEST_BUILTIN_ACTIONS=(
|
||||
clear
|
||||
fetch
|
||||
suggest
|
||||
accept
|
||||
execute
|
||||
enable
|
||||
disable
|
||||
toggle
|
||||
)
|
||||
|
||||
local action
|
||||
for action in clear modify fetch suggest accept partial_accept execute enable disable toggle; do
|
||||
for action in $_ZSH_AUTOSUGGEST_BUILTIN_ACTIONS modify partial_accept; do
|
||||
eval "_zsh_autosuggest_widget_$action() {
|
||||
local -i retval
|
||||
|
||||
@@ -485,14 +501,9 @@ _zsh_autosuggest_partial_accept() {
|
||||
}"
|
||||
done
|
||||
|
||||
zle -N autosuggest-fetch _zsh_autosuggest_widget_fetch
|
||||
zle -N autosuggest-suggest _zsh_autosuggest_widget_suggest
|
||||
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
|
||||
for action in $_ZSH_AUTOSUGGEST_BUILTIN_ACTIONS; do
|
||||
zle -N autosuggest-$action _zsh_autosuggest_widget_$action
|
||||
done
|
||||
}
|
||||
|
||||
#--------------------------------------------------------------------#
|
||||
@@ -854,11 +865,13 @@ _zsh_autosuggest_start() {
|
||||
# Mark for auto-loading the functions that we use
|
||||
autoload -Uz add-zsh-hook is-at-least
|
||||
|
||||
# If zle is already running, go ahead and start the autosuggestion widgets.
|
||||
# Otherwise, wait until the next precmd.
|
||||
if zle; then
|
||||
_zsh_autosuggest_start
|
||||
(( ! ${+ZSH_AUTOSUGGEST_MANUAL_REBIND} )) && add-zsh-hook precmd _zsh_autosuggest_start
|
||||
else
|
||||
add-zsh-hook precmd _zsh_autosuggest_start
|
||||
# Automatically enable asynchronous mode in newer versions of zsh. Disable for
|
||||
# older versions because there is a bug when using async mode where ^C does not
|
||||
# work immediately after fetching a suggestion.
|
||||
# See https://github.com/zsh-users/zsh-autosuggestions/issues/364
|
||||
if is-at-least 5.0.8; then
|
||||
typeset -g ZSH_AUTOSUGGEST_USE_ASYNC=
|
||||
fi
|
||||
|
||||
# Start the autosuggestion widgets on the next precmd
|
||||
add-zsh-hook precmd _zsh_autosuggest_start
|
||||
|
||||
Reference in New Issue
Block a user