Compare commits

...

26 Commits

Author SHA1 Message Date
Eric Freese
0a42f872b8 bump version v0.2.16 2016-02-25 13:05:03 -07:00
Eric Freese
dd54925b06 Update URL references after repo move to zsh-users 2016-02-25 13:04:32 -07:00
Eric Freese
c761dc8150 bump version v0.2.15 2016-02-24 18:40:24 -07:00
Eric Freese
cc921994e6 Fix #127 by adding quotes 2016-02-24 18:35:17 -07:00
Eric Freese
0242c7eff1 Fix highlighting when sh_word_split option is enabled 2016-02-24 13:59:49 -07:00
Eric Freese
9d100f4f32 bump version v0.2.14 2016-02-23 20:12:16 -07:00
Eric Freese
ddb7284852 Fix backslash escaping problems with echo -E. 2016-02-23 20:11:56 -07:00
Eric Freese
2a5791710a bump version v0.2.13 2016-02-23 18:14:12 -07:00
Eric Freese
03fac1f0d7 Revert "Use zle -w flag to set WIDGET appropriately when calling orig widget"
This reverts commit 70438d233d.
2016-02-23 18:13:03 -07:00
Eric Freese
aa859a282d bump version v0.2.12 2016-02-23 10:37:57 -07:00
Eric Freese
f08a5a1baa [Formatting] Remove extra space in test script. 2016-02-23 10:24:35 -07:00
Eric Freese
70438d233d Use zle -w flag to set WIDGET appropriately when calling orig widget 2016-02-23 10:21:35 -07:00
Eric Freese
ba029e83d0 bump version v0.2.11 2016-02-17 13:44:52 -07:00
Eric Freese
acc129de6c Fix error when using autosuggest widgets 2016-02-17 13:44:52 -07:00
Eric Freese
aa5ceee256 Make asciinema a bit smaller. 2016-02-16 21:55:56 -07:00
Eric Freese
113ca0ad10 Add asciinema recording to README 2016-02-16 21:35:44 -07:00
Eric Freese
2b449a62f8 bump version v0.2.10 2016-02-16 20:59:31 -07:00
Eric Freese
6d25df6864 Revert usage of fc for suggestions and fix for sh_word_split.
Force field splitting on \0 to support sh_word_split option.
2016-02-16 10:51:01 -07:00
Eric Freese
0faa2b6584 bump version v0.2.9 2016-02-16 09:34:35 -07:00
Eric Freese
a2d8d91196 Actually fix suggestions when sh_split_words option is enabled. 2016-02-16 09:33:26 -07:00
Eric Freese
dd9a8789a7 bump version v0.2.8 2016-02-16 07:59:36 -07:00
Eric Freese
1b98af5b33 Fix suggestions when sh_split_words option is enabled 2016-02-16 07:57:44 -07:00
Eric Freese
45ab49d1f2 bump version v0.2.7 2016-02-15 08:46:23 -07:00
Eric Freese
41f15d5c9f Forgot a pesky backslash 2016-02-15 08:45:52 -07:00
Eric Freese
3ce1adb55d bump version v0.2.6 2016-02-15 08:31:50 -07:00
Eric Freese
2461a98857 Fix segfaults once and for all? 2016-02-15 08:31:00 -07:00
10 changed files with 120 additions and 65 deletions

View File

@@ -4,6 +4,7 @@ _[Fish](http://fishshell.com/)-like fast/unobtrusive autosuggestions for zsh._
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
@@ -12,7 +13,7 @@ It suggests commands as you type, based on command history.
1. Clone this repository somewhere on your machine. This guide will assume `~/.zsh/zsh-autosuggestions`.
```sh
git clone git://github.com/tarruda/zsh-autosuggestions ~/.zsh/zsh-autosuggestions
git clone git://github.com/zsh-users/zsh-autosuggestions ~/.zsh/zsh-autosuggestions
```
2. Add the following to your `.zshrc`:
@@ -29,7 +30,7 @@ It suggests commands as you type, based on command history.
1. Clone this repository into `$ZSH_CUSTOM/plugins` (by default `~/.oh-my-zsh/custom/plugins`)
```sh
git clone git://github.com/tarruda/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions
git clone git://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions
```
2. Add the plugin to the list of plugins for Oh My Zsh to load:
@@ -40,8 +41,6 @@ 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. See the comments in that issue for a workaround.
## Usage
@@ -95,36 +94,17 @@ bindkey '^ ' autosuggest-accept
### [`zsh-history-substring-search`](https://github.com/zsh-users/zsh-history-substring-search)
When the buffer is empty and one of the `history-substring-search-up/down` widgets is invoked, it will call the `up/down-line-or-history` widget. If the `up/down-line-or-history` widgets are in `ZSH_AUTOSUGGEST_CLEAR_WIDGETS` (the list of widgets that clear the suggestion), this can create an infinite recursion, crashing the shell session.
For best results, you'll want to remove `up-line-or-history` and `down-line-or-history` from `ZSH_AUTOSUGGEST_CLEAR_WIDGETS`:
```
# Remove *-line-or-history widgets from list of widgets that clear the autosuggestion to avoid conflict with history-substring-search-* widgets
ZSH_AUTOSUGGEST_CLEAR_WIDGETS=("${(@)ZSH_AUTOSUGGEST_CLEAR_WIDGETS:#(up|down)-line-or-history}")
```
Additionally, the `history-substring-search-up` and `history-substring-search-down` widgets are not bound by default. You'll probably want to add them to `ZSH_AUTOSUGGEST_CLEAR_WIDGETS` so that the suggestion will be cleared when you start searching through history:
The `history-substring-search-up` and `history-substring-search-down` widgets are not bound by default. You'll probably want to add them to `ZSH_AUTOSUGGEST_CLEAR_WIDGETS` so that the suggestion will be cleared when you start searching through history:
```sh
# Add history-substring-search-* widgets to list of widgets that clear the autosuggestion
ZSH_AUTOSUGGEST_CLEAR_WIDGETS+=(history-substring-search-up history-substring-search-down)
```
For example:
```sh
source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh
source ~/Code/zsh-history-substring-search/zsh-history-substring-search.zsh
ZSH_AUTOSUGGEST_CLEAR_WIDGETS=("${(@)ZSH_AUTOSUGGEST_CLEAR_WIDGETS:#(up|down)-line-or-history}")
ZSH_AUTOSUGGEST_CLEAR_WIDGETS+=(history-substring-search-up history-substring-search-down)
```
## Troubleshooting
If you have a problem, please search through [the list of issues on GitHub](https://github.com/tarruda/zsh-autosuggestions/issues) to see if someone else has already reported it.
If you have a problem, please search through [the list of issues on GitHub](https://github.com/zsh-users/zsh-autosuggestions/issues) to see if someone else has already reported it.
### Reporting an Issue
@@ -133,7 +113,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. See [this comment](https://github.com/tarruda/zsh-autosuggestions/issues/102#issuecomment-180944764) for a good example of what this means.
- The smallest, simplest `.zshrc` configuration that will reproduce the problem. See [this comment](https://github.com/zsh-users/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

2
URL
View File

@@ -1 +1 @@
https://github.com/tarruda/zsh-autosuggestions
https://github.com/zsh-users/zsh-autosuggestions

View File

@@ -1 +1 @@
v0.2.5
v0.2.16

View File

@@ -85,7 +85,7 @@ testWidgetFunctionClear() {
BUFFER="ec"
POSTDISPLAY="ho hello"
_zsh_autosuggest_clear
_zsh_autosuggest_clear "original-widget"
assertEquals \
"BUFFER was modified" \
@@ -109,7 +109,7 @@ testWidgetFunctionModify() {
_zsh_autosuggest_suggestion \
"echo hello"
_zsh_autosuggest_modify
_zsh_autosuggest_modify "original-widget"
assertTrue \
"original widget not invoked" \
@@ -136,7 +136,7 @@ testWidgetFunctionAcceptCursorAtEnd() {
stub _zsh_autosuggest_invoke_original_widget
_zsh_autosuggest_accept
_zsh_autosuggest_accept "original-widget"
assertTrue \
"original widget not invoked" \
@@ -160,7 +160,7 @@ testWidgetFunctionAcceptCursorNotAtEnd() {
stub _zsh_autosuggest_invoke_original_widget
_zsh_autosuggest_accept
_zsh_autosuggest_accept "original-widget"
assertTrue \
"original widget not invoked" \
@@ -186,7 +186,7 @@ testWidgetFunctionPartialAcceptCursorMovesOutOfBuffer() {
_zsh_autosuggest_invoke_original_widget \
'CURSOR=5; LBUFFER="echo "; RBUFFER="hello"'
_zsh_autosuggest_partial_accept
_zsh_autosuggest_partial_accept "original-widget"
assertTrue \
"original widget not invoked" \
@@ -212,7 +212,7 @@ testWidgetFunctionPartialAcceptCursorStaysInBuffer() {
_zsh_autosuggest_invoke_original_widget \
'CURSOR=5; LBUFFER="echo "; RBUFFER="hello"'
_zsh_autosuggest_partial_accept
_zsh_autosuggest_partial_accept "original-widget"
assertTrue \
"original widget not invoked" \
@@ -236,7 +236,7 @@ testWidgetAccept() {
# Call the function pointed to by the widget since we can't call
# the widget itself when zle is not active
${widgets[autosuggest-accept]#*:}
${widgets[autosuggest-accept]#*:} "original-widget"
assertTrue \
"autosuggest-accept widget does not exist" \
@@ -262,7 +262,7 @@ testWidgetClear() {
# Call the function pointed to by the widget since we can't call
# the widget itself when zle is not active
${widgets[autosuggest-clear]#*:}
${widgets[autosuggest-clear]#*:} "original-widget"
assertTrue \
"autosuggest-clear widget does not exist" \
@@ -281,6 +281,43 @@ testWidgetClear() {
"stub_called _zsh_autosuggest_highlight_apply"
}
testEscapeCommandPrefix() {
assertEquals \
"Did not escape single backslash" \
"\\\\" \
"$(_zsh_autosuggest_escape_command_prefix "\\")"
assertEquals \
"Did not escape two backslashes" \
"\\\\\\\\" \
"$(_zsh_autosuggest_escape_command_prefix "\\\\")"
assertEquals \
"Did not escape parentheses" \
"\\(\\)" \
"$(_zsh_autosuggest_escape_command_prefix "()")"
assertEquals \
"Did not escape square brackets" \
"\\[\\]" \
"$(_zsh_autosuggest_escape_command_prefix "[]")"
assertEquals \
"Did not escape pipe" \
"\\|" \
"$(_zsh_autosuggest_escape_command_prefix "|")"
assertEquals \
"Did not escape star" \
"\\*" \
"$(_zsh_autosuggest_escape_command_prefix "*")"
assertEquals \
"Did not escape question mark" \
"\\?" \
"$(_zsh_autosuggest_escape_command_prefix "?")"
}
# For zsh compatibility
setopt shwordsplit
SHUNIT_PARENT=$0

View File

@@ -12,7 +12,7 @@ _zsh_autosuggest_bind_widget() {
# Save a reference to the original widget
case $widgets[$widget] in
# Already bound
user:_zsh_autosuggest_(widget|orig)_*);;
user:_zsh_autosuggest_(bound|orig)_*);;
# User-defined widget
user:*)
@@ -31,8 +31,18 @@ _zsh_autosuggest_bind_widget() {
;;
esac
# Pass the original widget's name explicitly into the autosuggest
# function. Use this passed in widget name to call the original
# widget instead of relying on the $WIDGET variable being set
# correctly. $WIDGET cannot be trusted because other plugins call
# zle without the `-w` flag (e.g. `zle self-insert` instead of
# `zle self-insert -w`).
eval "_zsh_autosuggest_bound_$widget() {
_zsh_autosuggest_widget_$autosuggest_action $prefix$widget \$@
}"
# Create the bound widget
zle -N $widget _zsh_autosuggest_widget_$autosuggest_action
zle -N $widget _zsh_autosuggest_bound_$widget
}
# Map all configured widgets to the right autosuggest widgets
@@ -54,9 +64,14 @@ _zsh_autosuggest_bind_widgets() {
done
}
# Given the name of a widget, invoke the original we saved, if it exists
# Given the name of an original widget and args, invoke it, if it exists
_zsh_autosuggest_invoke_original_widget() {
local original_widget_name="$ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX$WIDGET"
# Do nothing unless called with at least one arg
[ $# -gt 0 ] || return
local original_widget_name=$1
shift
if [ $widgets[$original_widget_name] ]; then
zle $original_widget_name -- $@

View File

@@ -26,7 +26,7 @@ _zsh_autosuggest_check_deprecated_config() {
}
_zsh_autosuggest_deprecated_start_widget() {
_zsh_autosuggest_deprecated_warning "The autosuggest-start widget is deprecated. For more info, see the README at https://github.com/tarruda/zsh-autosuggestions."
_zsh_autosuggest_deprecated_warning "The autosuggest-start widget is deprecated. For more info, see the README at https://github.com/zsh-users/zsh-autosuggestions."
zle -D autosuggest-start
eval "zle-line-init() {
$(echo $functions[${widgets[zle-line-init]#*:}] | sed -e 's/zle autosuggest-start//g')

View File

@@ -15,7 +15,7 @@ _zsh_autosuggest_highlight_reset() {
_zsh_autosuggest_highlight_apply() {
if [ $#POSTDISPLAY -gt 0 ]; then
_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT="$#BUFFER $(($#BUFFER + $#POSTDISPLAY)) $ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE"
region_highlight+=($_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT)
region_highlight+=("$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT")
else
unset _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
fi

View File

@@ -5,15 +5,19 @@
# Get a suggestion from history that matches a given prefix
_zsh_autosuggest_suggestion() {
setopt localoptions extendedglob
# Escape the prefix (requires EXTENDED_GLOB)
local prefix=${1//(#m)[\][()|\\*?#<>~^]/\\$MATCH}
local prefix="$(_zsh_autosuggest_escape_command_prefix "$1")"
# Get all history items (reversed) that match pattern $prefix*
local history_matches
history_matches=(${history[(R)$prefix*]})
history_matches=(${(j:\0:s:\0:)history[(R)$prefix*]})
# Echo the first item that matches
echo ${history_matches[1]}
echo -E "$history_matches[1]"
}
_zsh_autosuggest_escape_command_prefix() {
setopt localoptions EXTENDED_GLOB
# Escape special chars in the string (requires EXTENDED_GLOB)
echo -E "${1//(#m)[\\()\[\]|*?]/\\$MATCH}"
}

View File

@@ -19,7 +19,7 @@ _zsh_autosuggest_modify() {
# Get a new suggestion if the buffer is not empty after modification
local suggestion
if [ $#BUFFER -gt 0 ]; then
suggestion=$(_zsh_autosuggest_suggestion $BUFFER)
suggestion=$(_zsh_autosuggest_suggestion "$BUFFER")
fi
# Add the suggestion to the POSTDISPLAY

View File

@@ -1,6 +1,6 @@
# Fish-like fast/unobtrusive autosuggestions for zsh.
# https://github.com/tarruda/zsh-autosuggestions
# v0.2.5
# https://github.com/zsh-users/zsh-autosuggestions
# v0.2.16
# Copyright (c) 2013 Thiago de Arruda
# Copyright (c) 2016 Eric Freese
#
@@ -92,7 +92,7 @@ _zsh_autosuggest_check_deprecated_config() {
}
_zsh_autosuggest_deprecated_start_widget() {
_zsh_autosuggest_deprecated_warning "The autosuggest-start widget is deprecated. For more info, see the README at https://github.com/tarruda/zsh-autosuggestions."
_zsh_autosuggest_deprecated_warning "The autosuggest-start widget is deprecated. For more info, see the README at https://github.com/zsh-users/zsh-autosuggestions."
zle -D autosuggest-start
eval "zle-line-init() {
$(echo $functions[${widgets[zle-line-init]#*:}] | sed -e 's/zle autosuggest-start//g')
@@ -114,7 +114,7 @@ _zsh_autosuggest_bind_widget() {
# Save a reference to the original widget
case $widgets[$widget] in
# Already bound
user:_zsh_autosuggest_(widget|orig)_*);;
user:_zsh_autosuggest_(bound|orig)_*);;
# User-defined widget
user:*)
@@ -133,8 +133,18 @@ _zsh_autosuggest_bind_widget() {
;;
esac
# Pass the original widget's name explicitly into the autosuggest
# function. Use this passed in widget name to call the original
# widget instead of relying on the $WIDGET variable being set
# correctly. $WIDGET cannot be trusted because other plugins call
# zle without the `-w` flag (e.g. `zle self-insert` instead of
# `zle self-insert -w`).
eval "_zsh_autosuggest_bound_$widget() {
_zsh_autosuggest_widget_$autosuggest_action $prefix$widget \$@
}"
# Create the bound widget
zle -N $widget _zsh_autosuggest_widget_$autosuggest_action
zle -N $widget _zsh_autosuggest_bound_$widget
}
# Map all configured widgets to the right autosuggest widgets
@@ -156,9 +166,14 @@ _zsh_autosuggest_bind_widgets() {
done
}
# Given the name of a widget, invoke the original we saved, if it exists
# Given the name of an original widget and args, invoke it, if it exists
_zsh_autosuggest_invoke_original_widget() {
local original_widget_name="$ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX$WIDGET"
# Do nothing unless called with at least one arg
[ $# -gt 0 ] || return
local original_widget_name=$1
shift
if [ $widgets[$original_widget_name] ]; then
zle $original_widget_name -- $@
@@ -181,7 +196,7 @@ _zsh_autosuggest_highlight_reset() {
_zsh_autosuggest_highlight_apply() {
if [ $#POSTDISPLAY -gt 0 ]; then
_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT="$#BUFFER $(($#BUFFER + $#POSTDISPLAY)) $ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE"
region_highlight+=($_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT)
region_highlight+=("$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT")
else
unset _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
fi
@@ -207,7 +222,7 @@ _zsh_autosuggest_modify() {
# Get a new suggestion if the buffer is not empty after modification
local suggestion
if [ $#BUFFER -gt 0 ]; then
suggestion=$(_zsh_autosuggest_suggestion $BUFFER)
suggestion=$(_zsh_autosuggest_suggestion "$BUFFER")
fi
# Add the suggestion to the POSTDISPLAY
@@ -276,17 +291,21 @@ zle -N autosuggest-clear _zsh_autosuggest_widget_clear
# Get a suggestion from history that matches a given prefix
_zsh_autosuggest_suggestion() {
setopt localoptions extendedglob
# Escape the prefix (requires EXTENDED_GLOB)
local prefix=${1//(#m)[\][()|\\*?#<>~^]/\\$MATCH}
local prefix="$(_zsh_autosuggest_escape_command_prefix "$1")"
# Get all history items (reversed) that match pattern $prefix*
local history_matches
history_matches=(${history[(R)$prefix*]})
history_matches=(${(j:\0:s:\0:)history[(R)$prefix*]})
# Echo the first item that matches
echo ${history_matches[1]}
echo -E "$history_matches[1]"
}
_zsh_autosuggest_escape_command_prefix() {
setopt localoptions EXTENDED_GLOB
# Escape special chars in the string (requires EXTENDED_GLOB)
echo -E "${1//(#m)[\\()\[\]|*?]/\\$MATCH}"
}
#--------------------------------------------------------------------#