Compare commits

...

13 Commits

Author SHA1 Message Date
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
6 changed files with 73 additions and 11 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. 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

View File

@@ -1 +1 @@
v0.2.9 v0.2.14

View File

@@ -281,6 +281,43 @@ testWidgetClear() {
"stub_called _zsh_autosuggest_highlight_apply" "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 # For zsh compatibility
setopt shwordsplit setopt shwordsplit
SHUNIT_PARENT=$0 SHUNIT_PARENT=$0

View File

@@ -66,6 +66,9 @@ _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

View File

@@ -5,10 +5,19 @@
# Get a suggestion from history that matches a given prefix # Get a suggestion from history that matches a given prefix
_zsh_autosuggest_suggestion() { _zsh_autosuggest_suggestion() {
setopt localoptions extendedglob local prefix=$(_zsh_autosuggest_escape_command_prefix "$1")
# Escape the prefix (requires EXTENDED_GLOB) # Get all history items (reversed) that match pattern $prefix*
local prefix="${1//(#m)[\][()|\\*?#<>~^]/\\$MATCH}" local history_matches
history_matches=(${(j:\0:s:\0:)history[(R)$prefix*]})
fc -ln -m "$prefix*" 2>/dev/null | tail -1 # Echo the first item that matches
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

@@ -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.9 # v0.2.14
# Copyright (c) 2013 Thiago de Arruda # Copyright (c) 2013 Thiago de Arruda
# Copyright (c) 2016 Eric Freese # Copyright (c) 2016 Eric Freese
# #
@@ -168,6 +168,9 @@ _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
@@ -288,12 +291,21 @@ zle -N autosuggest-clear _zsh_autosuggest_widget_clear
# Get a suggestion from history that matches a given prefix # Get a suggestion from history that matches a given prefix
_zsh_autosuggest_suggestion() { _zsh_autosuggest_suggestion() {
setopt localoptions extendedglob local prefix=$(_zsh_autosuggest_escape_command_prefix "$1")
# Escape the prefix (requires EXTENDED_GLOB) # Get all history items (reversed) that match pattern $prefix*
local prefix="${1//(#m)[\][()|\\*?#<>~^]/\\$MATCH}" local history_matches
history_matches=(${(j:\0:s:\0:)history[(R)$prefix*]})
fc -ln -m "$prefix*" 2>/dev/null | tail -1 # Echo the first item that matches
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}"
} }
#--------------------------------------------------------------------# #--------------------------------------------------------------------#