mirror of
https://github.com/zsh-users/zsh-autosuggestions.git
synced 2025-12-06 23:30:39 +01:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aa859a282d | ||
|
|
f08a5a1baa | ||
|
|
70438d233d | ||
|
|
ba029e83d0 | ||
|
|
acc129de6c | ||
|
|
aa5ceee256 | ||
|
|
113ca0ad10 | ||
|
|
2b449a62f8 | ||
|
|
6d25df6864 | ||
|
|
0faa2b6584 | ||
|
|
a2d8d91196 |
@@ -4,6 +4,7 @@ _[Fish](http://fishshell.com/)-like fast/unobtrusive autosuggestions for zsh._
|
|||||||
|
|
||||||
It suggests commands as you type, based on command history.
|
It suggests commands as you type, based on command history.
|
||||||
|
|
||||||
|
<a href="https://asciinema.org/a/36578" target="_blank"><img src="https://asciinema.org/a/36578.png" width="520"/></a>
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ testWidgetFunctionModify() {
|
|||||||
POSTDISPLAY=""
|
POSTDISPLAY=""
|
||||||
|
|
||||||
stub_and_eval \
|
stub_and_eval \
|
||||||
_zsh_autosuggest_invoke_original_widget \
|
_zsh_autosuggest_invoke_original_widget \
|
||||||
'BUFFER+="e"'
|
'BUFFER+="e"'
|
||||||
|
|
||||||
stub_and_echo \
|
stub_and_echo \
|
||||||
|
|||||||
@@ -66,11 +66,14 @@ _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
|
||||||
|
[ $# -gt 0 ] || 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 -w -- $@
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,12 +8,12 @@ _zsh_autosuggest_suggestion() {
|
|||||||
setopt localoptions extendedglob
|
setopt localoptions extendedglob
|
||||||
|
|
||||||
# Escape the prefix (requires EXTENDED_GLOB)
|
# Escape the prefix (requires EXTENDED_GLOB)
|
||||||
local prefix=${1//(#m)[\][()|\\*?#<>~^]/\\$MATCH}
|
local prefix="${1//(#m)[\][()|\\*?#<>~^]/\\$MATCH}"
|
||||||
|
|
||||||
# Get all history items (reversed) that match pattern $prefix*
|
# Get all history items (reversed) that match pattern $prefix*
|
||||||
local history_matches
|
local history_matches
|
||||||
history_matches=(${history[(R)$prefix*]})
|
history_matches=(${(j:\0:s:\0:)history[(R)$prefix*]})
|
||||||
|
|
||||||
# Echo the first item that matches
|
# Echo the first item that matches
|
||||||
echo ${history_matches[1]}
|
echo "$history_matches[1]"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# Fish-like fast/unobtrusive autosuggestions for zsh.
|
# Fish-like fast/unobtrusive autosuggestions for zsh.
|
||||||
# https://github.com/tarruda/zsh-autosuggestions
|
# https://github.com/tarruda/zsh-autosuggestions
|
||||||
# v0.2.8
|
# v0.2.12
|
||||||
# Copyright (c) 2013 Thiago de Arruda
|
# Copyright (c) 2013 Thiago de Arruda
|
||||||
# Copyright (c) 2016 Eric Freese
|
# Copyright (c) 2016 Eric Freese
|
||||||
#
|
#
|
||||||
@@ -168,12 +168,15 @@ _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
|
||||||
|
[ $# -gt 0 ] || 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 -w -- $@
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -291,14 +294,14 @@ _zsh_autosuggest_suggestion() {
|
|||||||
setopt localoptions extendedglob
|
setopt localoptions extendedglob
|
||||||
|
|
||||||
# Escape the prefix (requires EXTENDED_GLOB)
|
# Escape the prefix (requires EXTENDED_GLOB)
|
||||||
local prefix=${1//(#m)[\][()|\\*?#<>~^]/\\$MATCH}
|
local prefix="${1//(#m)[\][()|\\*?#<>~^]/\\$MATCH}"
|
||||||
|
|
||||||
# Get all history items (reversed) that match pattern $prefix*
|
# Get all history items (reversed) that match pattern $prefix*
|
||||||
local history_matches
|
local history_matches
|
||||||
history_matches=(${history[(R)$prefix*]})
|
history_matches=(${(j:\0:s:\0:)history[(R)$prefix*]})
|
||||||
|
|
||||||
# Echo the first item that matches
|
# Echo the first item that matches
|
||||||
echo ${history_matches[1]}
|
echo "$history_matches[1]"
|
||||||
}
|
}
|
||||||
|
|
||||||
#--------------------------------------------------------------------#
|
#--------------------------------------------------------------------#
|
||||||
|
|||||||
Reference in New Issue
Block a user