From 940e10a691b34f0281d09794135e8ab81e8fae32 Mon Sep 17 00:00:00 2001 From: Kaleb Elwert Date: Mon, 17 Jul 2017 13:45:48 -0700 Subject: [PATCH 01/26] Fix conditionals to use [[ and (( rather than [ This fixes a small issue in src/widgets.zsh which makes it so if you alias [ to g[ (as is done in prezto if the gnu-utility module is loaded) autosuggestions would fail. The documentation for GNU test mentions that -o and -a should be avoided if possible because it's not very clear. Also, with zsh and [[ -o actually tests if an option is set, which makes this option even more confusing. --- spec/integrations/rebound_bracket_spec.rb | 13 +++++++ src/async.zsh | 2 +- src/bind.zsh | 12 +++--- src/highlight.zsh | 4 +- src/start.zsh | 2 +- src/widgets.zsh | 26 ++++++------- zsh-autosuggestions.zsh | 46 +++++++++++------------ 7 files changed, 59 insertions(+), 46 deletions(-) create mode 100644 spec/integrations/rebound_bracket_spec.rb diff --git a/spec/integrations/rebound_bracket_spec.rb b/spec/integrations/rebound_bracket_spec.rb new file mode 100644 index 0000000..8b420f0 --- /dev/null +++ b/spec/integrations/rebound_bracket_spec.rb @@ -0,0 +1,13 @@ +describe 'rebinding [' do + context 'initialized before sourcing the plugin' do + before do + session.run_command("function [ { $commands[\\[] \"$@\" }") + session.clear_screen + end + + it 'executes the custom behavior and the built-in behavior' do + session.send_string('asdf') + wait_for { session.content }.to eq('asdf') + end + end +end diff --git a/src/async.zsh b/src/async.zsh index 124c9ac..1d1e76d 100644 --- a/src/async.zsh +++ b/src/async.zsh @@ -63,7 +63,7 @@ _zsh_autosuggest_async_pty_create() { typeset -h REPLY # If we won't get a fd back from zpty, try to guess it - if [ $_ZSH_AUTOSUGGEST_ZPTY_RETURNS_FD -eq 0 ]; then + if (( ! $_ZSH_AUTOSUGGEST_ZPTY_RETURNS_FD )); then integer -l zptyfd exec {zptyfd}>&1 # Open a new file descriptor (above 10). exec {zptyfd}>&- # Close it so it's free to be used by zpty. diff --git a/src/bind.zsh b/src/bind.zsh index be0d164..ed9a977 100644 --- a/src/bind.zsh +++ b/src/bind.zsh @@ -88,13 +88,13 @@ _zsh_autosuggest_bind_widgets() { # Find every widget we might want to bind and bind it appropriately for widget in ${${(f)"$(builtin zle -la)"}:#${(j:|:)~ignore_widgets}}; do - if [ ${ZSH_AUTOSUGGEST_CLEAR_WIDGETS[(r)$widget]} ]; then + if [[ -n ${ZSH_AUTOSUGGEST_CLEAR_WIDGETS[(r)$widget]} ]]; then _zsh_autosuggest_bind_widget $widget clear - elif [ ${ZSH_AUTOSUGGEST_ACCEPT_WIDGETS[(r)$widget]} ]; then + elif [[ -n ${ZSH_AUTOSUGGEST_ACCEPT_WIDGETS[(r)$widget]} ]]; then _zsh_autosuggest_bind_widget $widget accept - elif [ ${ZSH_AUTOSUGGEST_EXECUTE_WIDGETS[(r)$widget]} ]; then + elif [[ -n ${ZSH_AUTOSUGGEST_EXECUTE_WIDGETS[(r)$widget]} ]]; then _zsh_autosuggest_bind_widget $widget execute - elif [ ${ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS[(r)$widget]} ]; then + elif [[ -n ${ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS[(r)$widget]} ]]; then _zsh_autosuggest_bind_widget $widget partial_accept else # Assume any unspecified widget might modify the buffer @@ -106,13 +106,13 @@ _zsh_autosuggest_bind_widgets() { # Given the name of an original widget and args, invoke it, if it exists _zsh_autosuggest_invoke_original_widget() { # Do nothing unless called with at least one arg - [ $# -gt 0 ] || return + (( $# )) || return local original_widget_name="$1" shift - if [ $widgets[$original_widget_name] ]; then + if (( ${+widgets[$original_widget_name]} )); then zle $original_widget_name -- $@ fi } diff --git a/src/highlight.zsh b/src/highlight.zsh index aa5a427..273c03d 100644 --- a/src/highlight.zsh +++ b/src/highlight.zsh @@ -7,7 +7,7 @@ _zsh_autosuggest_highlight_reset() { typeset -g _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT - if [ -n "$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT" ]; then + if [[ -n "$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT" ]]; then region_highlight=("${(@)region_highlight:#$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT}") unset _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT fi @@ -17,7 +17,7 @@ _zsh_autosuggest_highlight_reset() { _zsh_autosuggest_highlight_apply() { typeset -g _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT - if [ $#POSTDISPLAY -gt 0 ]; then + if (( $#POSTDISPLAY )); then typeset -g _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT="$#BUFFER $(($#BUFFER + $#POSTDISPLAY)) $ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE" region_highlight+=("$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT") else diff --git a/src/start.zsh b/src/start.zsh index 6fa8ce9..6f48ab6 100644 --- a/src/start.zsh +++ b/src/start.zsh @@ -15,7 +15,7 @@ _zsh_autosuggest_start() { # to the widget list variables to take effect on the next precmd. add-zsh-hook precmd _zsh_autosuggest_bind_widgets - if [ -n "${ZSH_AUTOSUGGEST_USE_ASYNC+x}" ]; then + if [[ -n "${ZSH_AUTOSUGGEST_USE_ASYNC+x}" ]]; then _zsh_autosuggest_async_start fi } diff --git a/src/widgets.zsh b/src/widgets.zsh index 8710c02..8a31133 100644 --- a/src/widgets.zsh +++ b/src/widgets.zsh @@ -13,14 +13,14 @@ _zsh_autosuggest_disable() { _zsh_autosuggest_enable() { unset _ZSH_AUTOSUGGEST_DISABLED - if [ $#BUFFER -gt 0 ]; then + if (( $#BUFFER )); then _zsh_autosuggest_fetch fi } # Toggle suggestions (enable/disable) _zsh_autosuggest_toggle() { - if [ -n "${_ZSH_AUTOSUGGEST_DISABLED+x}" ]; then + if [[ -n "${_ZSH_AUTOSUGGEST_DISABLED+x}" ]]; then _zsh_autosuggest_enable else _zsh_autosuggest_disable @@ -54,35 +54,35 @@ _zsh_autosuggest_modify() { retval=$? # Don't fetch a new suggestion if there's more input to be read immediately - if [[ $PENDING > 0 ]] || [[ $KEYS_QUEUED_COUNT > 0 ]]; then + if (( $PENDING > 0 )) || (( $KEYS_QUEUED_COUNT > 0 )); then return $retval fi # Optimize if manually typing in the suggestion - if [ $#BUFFER -gt $#orig_buffer ]; then + if (( $#BUFFER > $#orig_buffer )); then local added=${BUFFER#$orig_buffer} # If the string added matches the beginning of the postdisplay - if [ "$added" = "${orig_postdisplay:0:$#added}" ]; then + if [[ "$added" = "${orig_postdisplay:0:$#added}" ]]; then POSTDISPLAY="${orig_postdisplay:$#added}" return $retval fi fi # Don't fetch a new suggestion if the buffer hasn't changed - if [ "$BUFFER" = "$orig_buffer" ]; then + if [[ "$BUFFER" = "$orig_buffer" ]]; then POSTDISPLAY="$orig_postdisplay" return $retval fi # Bail out if suggestions are disabled - if [ -n "${_ZSH_AUTOSUGGEST_DISABLED+x}" ]; then + if [[ -n "${_ZSH_AUTOSUGGEST_DISABLED+x}" ]]; then return $? fi # Get a new suggestion if the buffer is not empty after modification - if [ $#BUFFER -gt 0 ]; then - if [ -z "$ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE" -o $#BUFFER -le "$ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE" ]; then + if (( $#BUFFER > 0 )); then + if [[ -z "$ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE" ]] || (( $#BUFFER <= $ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE )); then _zsh_autosuggest_fetch fi fi @@ -105,7 +105,7 @@ _zsh_autosuggest_fetch() { _zsh_autosuggest_suggest() { local suggestion="$1" - if [ -n "$suggestion" ] && [ $#BUFFER -gt 0 ]; then + if [[ -n "$suggestion" ]] && (( $#BUFFER )); then POSTDISPLAY="${suggestion#$BUFFER}" else unset POSTDISPLAY @@ -118,12 +118,12 @@ _zsh_autosuggest_accept() { # When vicmd keymap is active, the cursor can't move all the way # to the end of the buffer - if [ "$KEYMAP" = "vicmd" ]; then + if [[ "$KEYMAP" = "vicmd" ]]; then max_cursor_pos=$((max_cursor_pos - 1)) fi # Only accept if the cursor is at the end of the buffer - if [ $CURSOR -eq $max_cursor_pos ]; then + if [[ $CURSOR = $max_cursor_pos ]]; then # Add the suggestion to the buffer BUFFER="$BUFFER$POSTDISPLAY" @@ -165,7 +165,7 @@ _zsh_autosuggest_partial_accept() { retval=$? # If we've moved past the end of the original buffer - if [ $CURSOR -gt $#original_buffer ]; then + if (( $CURSOR > $#original_buffer )); then # Set POSTDISPLAY to text right of the cursor POSTDISPLAY="$RBUFFER" diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index 6cbaf05..3878d25 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -209,13 +209,13 @@ _zsh_autosuggest_bind_widgets() { # Find every widget we might want to bind and bind it appropriately for widget in ${${(f)"$(builtin zle -la)"}:#${(j:|:)~ignore_widgets}}; do - if [ ${ZSH_AUTOSUGGEST_CLEAR_WIDGETS[(r)$widget]} ]; then + if [[ -n ${ZSH_AUTOSUGGEST_CLEAR_WIDGETS[(r)$widget]} ]]; then _zsh_autosuggest_bind_widget $widget clear - elif [ ${ZSH_AUTOSUGGEST_ACCEPT_WIDGETS[(r)$widget]} ]; then + elif [[ -n ${ZSH_AUTOSUGGEST_ACCEPT_WIDGETS[(r)$widget]} ]]; then _zsh_autosuggest_bind_widget $widget accept - elif [ ${ZSH_AUTOSUGGEST_EXECUTE_WIDGETS[(r)$widget]} ]; then + elif [[ -n ${ZSH_AUTOSUGGEST_EXECUTE_WIDGETS[(r)$widget]} ]]; then _zsh_autosuggest_bind_widget $widget execute - elif [ ${ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS[(r)$widget]} ]; then + elif [[ -n ${ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS[(r)$widget]} ]]; then _zsh_autosuggest_bind_widget $widget partial_accept else # Assume any unspecified widget might modify the buffer @@ -227,13 +227,13 @@ _zsh_autosuggest_bind_widgets() { # Given the name of an original widget and args, invoke it, if it exists _zsh_autosuggest_invoke_original_widget() { # Do nothing unless called with at least one arg - [ $# -gt 0 ] || return + (( $# )) || return local original_widget_name="$1" shift - if [ $widgets[$original_widget_name] ]; then + if (( ${+widgets[$original_widget_name]} )); then zle $original_widget_name -- $@ fi } @@ -246,7 +246,7 @@ _zsh_autosuggest_invoke_original_widget() { _zsh_autosuggest_highlight_reset() { typeset -g _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT - if [ -n "$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT" ]; then + if [[ -n "$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT" ]]; then region_highlight=("${(@)region_highlight:#$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT}") unset _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT fi @@ -256,7 +256,7 @@ _zsh_autosuggest_highlight_reset() { _zsh_autosuggest_highlight_apply() { typeset -g _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT - if [ $#POSTDISPLAY -gt 0 ]; then + if (( $#POSTDISPLAY )); then typeset -g _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT="$#BUFFER $(($#BUFFER + $#POSTDISPLAY)) $ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE" region_highlight+=("$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT") else @@ -278,14 +278,14 @@ _zsh_autosuggest_disable() { _zsh_autosuggest_enable() { unset _ZSH_AUTOSUGGEST_DISABLED - if [ $#BUFFER -gt 0 ]; then + if (( $#BUFFER )); then _zsh_autosuggest_fetch fi } # Toggle suggestions (enable/disable) _zsh_autosuggest_toggle() { - if [ -n "${_ZSH_AUTOSUGGEST_DISABLED+x}" ]; then + if [[ -n "${_ZSH_AUTOSUGGEST_DISABLED+x}" ]]; then _zsh_autosuggest_enable else _zsh_autosuggest_disable @@ -319,35 +319,35 @@ _zsh_autosuggest_modify() { retval=$? # Don't fetch a new suggestion if there's more input to be read immediately - if [[ $PENDING > 0 ]] || [[ $KEYS_QUEUED_COUNT > 0 ]]; then + if (( $PENDING > 0 )) || (( $KEYS_QUEUED_COUNT > 0 )); then return $retval fi # Optimize if manually typing in the suggestion - if [ $#BUFFER -gt $#orig_buffer ]; then + if (( $#BUFFER > $#orig_buffer )); then local added=${BUFFER#$orig_buffer} # If the string added matches the beginning of the postdisplay - if [ "$added" = "${orig_postdisplay:0:$#added}" ]; then + if [[ "$added" = "${orig_postdisplay:0:$#added}" ]]; then POSTDISPLAY="${orig_postdisplay:$#added}" return $retval fi fi # Don't fetch a new suggestion if the buffer hasn't changed - if [ "$BUFFER" = "$orig_buffer" ]; then + if [[ "$BUFFER" = "$orig_buffer" ]]; then POSTDISPLAY="$orig_postdisplay" return $retval fi # Bail out if suggestions are disabled - if [ -n "${_ZSH_AUTOSUGGEST_DISABLED+x}" ]; then + if [[ -n "${_ZSH_AUTOSUGGEST_DISABLED+x}" ]]; then return $? fi # Get a new suggestion if the buffer is not empty after modification - if [ $#BUFFER -gt 0 ]; then - if [ -z "$ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE" -o $#BUFFER -le "$ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE" ]; then + if (( $#BUFFER > 0 )); then + if [[ -z "$ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE" ]] || (( $#BUFFER <= $ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE )); then _zsh_autosuggest_fetch fi fi @@ -370,7 +370,7 @@ _zsh_autosuggest_fetch() { _zsh_autosuggest_suggest() { local suggestion="$1" - if [ -n "$suggestion" ] && [ $#BUFFER -gt 0 ]; then + if [[ -n "$suggestion" ]] && (( $#BUFFER )); then POSTDISPLAY="${suggestion#$BUFFER}" else unset POSTDISPLAY @@ -383,12 +383,12 @@ _zsh_autosuggest_accept() { # When vicmd keymap is active, the cursor can't move all the way # to the end of the buffer - if [ "$KEYMAP" = "vicmd" ]; then + if [[ "$KEYMAP" = "vicmd" ]]; then max_cursor_pos=$((max_cursor_pos - 1)) fi # Only accept if the cursor is at the end of the buffer - if [ $CURSOR -eq $max_cursor_pos ]; then + if [[ $CURSOR = $max_cursor_pos ]]; then # Add the suggestion to the buffer BUFFER="$BUFFER$POSTDISPLAY" @@ -430,7 +430,7 @@ _zsh_autosuggest_partial_accept() { retval=$? # If we've moved past the end of the original buffer - if [ $CURSOR -gt $#original_buffer ]; then + if (( $CURSOR > $#original_buffer )); then # Set POSTDISPLAY to text right of the cursor POSTDISPLAY="$RBUFFER" @@ -601,7 +601,7 @@ _zsh_autosuggest_async_pty_create() { typeset -h REPLY # If we won't get a fd back from zpty, try to guess it - if [ $_ZSH_AUTOSUGGEST_ZPTY_RETURNS_FD -eq 0 ]; then + if (( ! $_ZSH_AUTOSUGGEST_ZPTY_RETURNS_FD )); then integer -l zptyfd exec {zptyfd}>&1 # Open a new file descriptor (above 10). exec {zptyfd}>&- # Close it so it's free to be used by zpty. @@ -662,7 +662,7 @@ _zsh_autosuggest_start() { # to the widget list variables to take effect on the next precmd. add-zsh-hook precmd _zsh_autosuggest_bind_widgets - if [ -n "${ZSH_AUTOSUGGEST_USE_ASYNC+x}" ]; then + if [[ -n "${ZSH_AUTOSUGGEST_USE_ASYNC+x}" ]]; then _zsh_autosuggest_async_start fi } From 29257230fe270142e4a4b97adc539b3bf2f51e1c Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Tue, 28 Nov 2017 10:00:33 -0700 Subject: [PATCH 02/26] Add missing issue/pr numbers from last version --- CHANGELOG.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ac0f8e6..69c1655 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,12 +3,12 @@ ## v0.4.0 - High-level integration tests using RSpec and tmux - Add continuous integration with Circle CI -- Experimental support for asynchronous suggestions (#) -- Fix problems with multi-line suggestions (#) +- Experimental support for asynchronous suggestions (#170) +- Fix problems with multi-line suggestions (#225) - Optimize case where manually typing in suggestion -- Avoid wrapping any zle-* widgets (#) +- Avoid wrapping any zle-* widgets (#206) - Remove support for deprecated options from v0.0.x -- Handle history entries that begin with dashes (#) +- Handle history entries that begin with dashes - Gracefully handle being sourced multiple times (#126) - Add enable/disable/toggle widgets to disable/enable suggestions (#219) From 9f9237ab8a530eeff389161202bbc7283ad6af3e Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Tue, 28 Nov 2017 09:53:49 -0700 Subject: [PATCH 03/26] v0.4.1 --- CHANGELOG.md | 7 +++++++ VERSION | 2 +- zsh-autosuggestions.zsh | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 69c1655..fb15b88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## v0.4.1 +- Switch to [[ and (( conditionals instead of [ (#257) +- Avoid warnnestedvar warnings with `typeset -g` (#275) +- Replace tabs with spaces in yaml (#268) +- Clean up and fix escaping of special characters (#267) +- Add `emacs-forward-word` to default list of partial accept widgets (#246) + ## v0.4.0 - High-level integration tests using RSpec and tmux - Add continuous integration with Circle CI diff --git a/VERSION b/VERSION index fb7a04c..5aff472 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v0.4.0 +v0.4.1 diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index 3878d25..fadbac7 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -1,6 +1,6 @@ # Fish-like fast/unobtrusive autosuggestions for zsh. # https://github.com/zsh-users/zsh-autosuggestions -# v0.4.0 +# v0.4.1 # Copyright (c) 2013 Thiago de Arruda # Copyright (c) 2016-2017 Eric Freese # From be8bba6f388bd9118b0aaf3580c0d3bd97350ed8 Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Fri, 1 Dec 2017 08:03:27 -0700 Subject: [PATCH 04/26] Run CI on prominent versions of zsh back to 4.3.11 RHEL6 bundles v4.3.11 Ubuntu 14.04 and Amazon Linux bundle v5.0.2 --- circle.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/circle.yml b/circle.yml index 5e3a6f6..d0f7633 100644 --- a/circle.yml +++ b/circle.yml @@ -1,12 +1,12 @@ machine: environment: - ZSH_VERSIONS: 5.0.8 5.1.1 5.2 5.3.1 + ZSH_VERSIONS: zsh-dev/4.3.11 zsh/5.0.2 zsh/5.0.8 zsh/5.1.1 zsh/5.2 zsh/5.3.1 zsh/5.4.2 dependencies: pre: - - for v in $(echo $ZSH_VERSIONS | awk "{ for (i=$((1+CIRCLE_NODE_INDEX));i<=NF;i+=$CIRCLE_NODE_TOTAL) print \$i }"); do wget https://sourceforge.net/projects/zsh/files/zsh/$v/zsh-$v.tar.gz && tar xzf zsh-$v.tar.gz && cd zsh-$v && ./configure && sudo make install || exit 1; done + - for v in $(echo $ZSH_VERSIONS | awk "{ for (i=$((1+CIRCLE_NODE_INDEX));i<=NF;i+=$CIRCLE_NODE_TOTAL) print \$i }"); do wget https://sourceforge.net/projects/zsh/files/$v/zsh-${v#*/}.tar.gz && tar xzf zsh-${v#*/}.tar.gz && pushd zsh-${v#*/} && ./configure && sudo make install && popd || exit 1; done test: override: - - for v in $(echo $ZSH_VERSIONS | awk "{ for (i=$((1+CIRCLE_NODE_INDEX));i<=NF;i+=$CIRCLE_NODE_TOTAL) print \$i }"); do TEST_ZSH_BIN=/usr/local/bin/zsh-$v make test || exit 1; done: + - for v in $(echo $ZSH_VERSIONS | awk "{ for (i=$((1+CIRCLE_NODE_INDEX));i<=NF;i+=$CIRCLE_NODE_TOTAL) print \$i }"); do TEST_ZSH_BIN=/usr/local/bin/zsh-${v#*/} make test || exit 1; done: parallel: true From a1babef972538d97fedaf32326dcf2bbeeadb6d2 Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Wed, 6 Dec 2017 07:51:06 -0700 Subject: [PATCH 05/26] Revert "Simplify escaping of pattern and fix match_prev_cmd strategy" This reverts commit 7f8ff2867cef80de7d56e37e1744c27782403e89. --- Makefile | 1 + src/strategies/default.zsh | 14 ++++++++++++-- src/strategies/match_prev_cmd.zsh | 7 ++++--- src/util.zsh | 11 +++++++++++ zsh-autosuggestions.zsh | 32 ++++++++++++++++++++++++++----- 5 files changed, 55 insertions(+), 10 deletions(-) create mode 100644 src/util.zsh diff --git a/Makefile b/Makefile index 5402b7f..d5d162c 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,7 @@ SRC_DIR := ./src SRC_FILES := \ $(SRC_DIR)/setup.zsh \ $(SRC_DIR)/config.zsh \ + $(SRC_DIR)/util.zsh \ $(SRC_DIR)/features.zsh \ $(SRC_DIR)/bind.zsh \ $(SRC_DIR)/highlight.zsh \ diff --git a/src/strategies/default.zsh b/src/strategies/default.zsh index 17bf65d..0e85fb5 100644 --- a/src/strategies/default.zsh +++ b/src/strategies/default.zsh @@ -7,9 +7,19 @@ # _zsh_autosuggest_strategy_default() { - local prefix="$1" + # Reset options to defaults and enable LOCAL_OPTIONS + emulate -L zsh + + # Enable globbing flags so that we can use (#m) + setopt EXTENDED_GLOB + + # Escape backslashes and all of the glob operators so we can use + # this string as a pattern to search the $history associative array. + # - (#m) globbing flag enables setting references for match data + # TODO: Use (b) flag when we can drop support for zsh older than v5.0.8 + local prefix="${1//(#m)[\\*?[\]<>()|^~#]/\\$MATCH}" # Get the history items that match # - (r) subscript flag makes the pattern match on values - typeset -g suggestion="${history[(r)${(b)prefix}*]}" + typeset -g suggestion="${history[(r)${prefix}*]}" } diff --git a/src/strategies/match_prev_cmd.zsh b/src/strategies/match_prev_cmd.zsh index 8a84728..dfeb55f 100644 --- a/src/strategies/match_prev_cmd.zsh +++ b/src/strategies/match_prev_cmd.zsh @@ -21,18 +21,19 @@ # `HIST_EXPIRE_DUPS_FIRST`. _zsh_autosuggest_strategy_match_prev_cmd() { - local prefix="$1" + # TODO: Use (b) flag when we can drop support for zsh older than v5.0.8 + local prefix="${1//(#m)[\\*?[\]<>()|^~#]/\\$MATCH}" # Get all history event numbers that correspond to history # entries that match pattern $prefix* local history_match_keys - history_match_keys=(${(k)history[(R)${(b)prefix}*]}) + history_match_keys=(${(k)history[(R)$prefix*]}) # By default we use the first history number (most recent history entry) local histkey="${history_match_keys[1]}" # Get the previously executed command - local prev_cmd="${history[$((HISTCMD-1))]}" + local prev_cmd="$(_zsh_autosuggest_escape_command "${history[$((HISTCMD-1))]}")" # Iterate up to the first 200 history event numbers that match $prefix for key in "${(@)history_match_keys[1,200]}"; do diff --git a/src/util.zsh b/src/util.zsh new file mode 100644 index 0000000..1f55d36 --- /dev/null +++ b/src/util.zsh @@ -0,0 +1,11 @@ + +#--------------------------------------------------------------------# +# Utility Functions # +#--------------------------------------------------------------------# + +_zsh_autosuggest_escape_command() { + setopt localoptions EXTENDED_GLOB + + # Escape special chars in the string (requires EXTENDED_GLOB) + echo -E "${1//(#m)[\"\'\\()\[\]|*?~]/\\$MATCH}" +} diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index fadbac7..95792da 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -101,6 +101,17 @@ ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE= # Pty name for calculating autosuggestions asynchronously ZSH_AUTOSUGGEST_ASYNC_PTY_NAME=zsh_autosuggest_pty +#--------------------------------------------------------------------# +# Utility Functions # +#--------------------------------------------------------------------# + +_zsh_autosuggest_escape_command() { + setopt localoptions EXTENDED_GLOB + + # Escape special chars in the string (requires EXTENDED_GLOB) + echo -E "${1//(#m)[\"\'\\()\[\]|*?~]/\\$MATCH}" +} + #--------------------------------------------------------------------# # Feature Detection # #--------------------------------------------------------------------# @@ -478,11 +489,21 @@ zle -N autosuggest-toggle _zsh_autosuggest_widget_toggle # _zsh_autosuggest_strategy_default() { - local prefix="$1" + # Reset options to defaults and enable LOCAL_OPTIONS + emulate -L zsh + + # Enable globbing flags so that we can use (#m) + setopt EXTENDED_GLOB + + # Escape backslashes and all of the glob operators so we can use + # this string as a pattern to search the $history associative array. + # - (#m) globbing flag enables setting references for match data + # TODO: Use (b) flag when we can drop support for zsh older than v5.0.8 + local prefix="${1//(#m)[\\*?[\]<>()|^~#]/\\$MATCH}" # Get the history items that match # - (r) subscript flag makes the pattern match on values - typeset -g suggestion="${history[(r)${(b)prefix}*]}" + typeset -g suggestion="${history[(r)${prefix}*]}" } #--------------------------------------------------------------------# @@ -507,18 +528,19 @@ _zsh_autosuggest_strategy_default() { # `HIST_EXPIRE_DUPS_FIRST`. _zsh_autosuggest_strategy_match_prev_cmd() { - local prefix="$1" + # TODO: Use (b) flag when we can drop support for zsh older than v5.0.8 + local prefix="${1//(#m)[\\*?[\]<>()|^~#]/\\$MATCH}" # Get all history event numbers that correspond to history # entries that match pattern $prefix* local history_match_keys - history_match_keys=(${(k)history[(R)${(b)prefix}*]}) + history_match_keys=(${(k)history[(R)$prefix*]}) # By default we use the first history number (most recent history entry) local histkey="${history_match_keys[1]}" # Get the previously executed command - local prev_cmd="${history[$((HISTCMD-1))]}" + local prev_cmd="$(_zsh_autosuggest_escape_command "${history[$((HISTCMD-1))]}")" # Iterate up to the first 200 history event numbers that match $prefix for key in "${(@)history_match_keys[1,200]}"; do From 4ea825faf893e2c596e630a926a9f83629ec7327 Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Wed, 6 Dec 2017 08:09:14 -0700 Subject: [PATCH 06/26] Fix #247 and #248 without using `(b)` flag To support older versions of zsh (< 5.0.8). We were missing the EXTENDED_GLOB option that allows use of `(#m)` flag. --- src/strategies/match_prev_cmd.zsh | 6 ++++++ zsh-autosuggestions.zsh | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/strategies/match_prev_cmd.zsh b/src/strategies/match_prev_cmd.zsh index dfeb55f..f76d3c1 100644 --- a/src/strategies/match_prev_cmd.zsh +++ b/src/strategies/match_prev_cmd.zsh @@ -21,6 +21,12 @@ # `HIST_EXPIRE_DUPS_FIRST`. _zsh_autosuggest_strategy_match_prev_cmd() { + # Reset options to defaults and enable LOCAL_OPTIONS + emulate -L zsh + + # Enable globbing flags so that we can use (#m) + setopt EXTENDED_GLOB + # TODO: Use (b) flag when we can drop support for zsh older than v5.0.8 local prefix="${1//(#m)[\\*?[\]<>()|^~#]/\\$MATCH}" diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index 95792da..ebc717d 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -528,6 +528,12 @@ _zsh_autosuggest_strategy_default() { # `HIST_EXPIRE_DUPS_FIRST`. _zsh_autosuggest_strategy_match_prev_cmd() { + # Reset options to defaults and enable LOCAL_OPTIONS + emulate -L zsh + + # Enable globbing flags so that we can use (#m) + setopt EXTENDED_GLOB + # TODO: Use (b) flag when we can drop support for zsh older than v5.0.8 local prefix="${1//(#m)[\\*?[\]<>()|^~#]/\\$MATCH}" From f462410b3cd94935e06692f5d4c16833706c801e Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Wed, 6 Dec 2017 08:21:27 -0700 Subject: [PATCH 07/26] Add zsh version requirements to readme --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 8aedb31..6a6ae1e 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,8 @@ It suggests commands as you type, based on command history. ## Installation +Requirements: Zsh v4.3.11 or later + ### Manual 1. Clone this repository somewhere on your machine. This guide will assume `~/.zsh/zsh-autosuggestions`. From 15931f04ffac91a2f9a1a044b6b3ee4050751064 Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Wed, 6 Dec 2017 08:30:12 -0700 Subject: [PATCH 08/26] v0.4.2 --- CHANGELOG.md | 4 ++++ VERSION | 2 +- zsh-autosuggestions.zsh | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb15b88..3134f5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## v0.4.2 +- Fix bug in zsh versions older than 5.0.8 (#296) +- Officially support back to zsh v4.3.11 + ## v0.4.1 - Switch to [[ and (( conditionals instead of [ (#257) - Avoid warnnestedvar warnings with `typeset -g` (#275) diff --git a/VERSION b/VERSION index 5aff472..0eec13e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v0.4.1 +v0.4.2 diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index ebc717d..ccfe07e 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -1,6 +1,6 @@ # Fish-like fast/unobtrusive autosuggestions for zsh. # https://github.com/zsh-users/zsh-autosuggestions -# v0.4.1 +# v0.4.2 # Copyright (c) 2013 Thiago de Arruda # Copyright (c) 2016-2017 Eric Freese # From c978004c0ec926e94f8094523723e109a61f9bde Mon Sep 17 00:00:00 2001 From: dana Date: Tue, 16 Jan 2018 14:08:38 -0600 Subject: [PATCH 09/26] ..._invoke_original_widget: Return 0 when given no arguments `_zsh_autosuggest_widget_accept()` (&al.) passes this function's return status on, and ZLE rings the bell if it's >0. Not having an original widget isn't an error condition, so always returning 0 here should be OK to avoid the bell Fixes #228 --- src/bind.zsh | 2 +- zsh-autosuggestions.zsh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bind.zsh b/src/bind.zsh index ed9a977..42a0dd0 100644 --- a/src/bind.zsh +++ b/src/bind.zsh @@ -106,7 +106,7 @@ _zsh_autosuggest_bind_widgets() { # Given the name of an original widget and args, invoke it, if it exists _zsh_autosuggest_invoke_original_widget() { # Do nothing unless called with at least one arg - (( $# )) || return + (( $# )) || return 0 local original_widget_name="$1" diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index ccfe07e..a9330ea 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -238,7 +238,7 @@ _zsh_autosuggest_bind_widgets() { # Given the name of an original widget and args, invoke it, if it exists _zsh_autosuggest_invoke_original_widget() { # Do nothing unless called with at least one arg - (( $# )) || return + (( $# )) || return 0 local original_widget_name="$1" From 3136700ccf1fd5fb0a8d66627eed5edd892881dc Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Fri, 23 Mar 2018 15:04:21 -0600 Subject: [PATCH 10/26] Don't fetch suggestions after [up,down]-line-or-beginning-search These widgets rely on `$LASTWIDGET` being set to restore the cursor position. When asynchronous suggestions are enabled, and the widget triggers a suggestion to be fetched, `autosuggest-suggest` will be called and $LASTWIDGET will be set to it. --- .../async_line_or_beginning_spec.rb | 27 +++++++++++++++++++ src/config.zsh | 2 ++ zsh-autosuggestions.zsh | 2 ++ 3 files changed, 31 insertions(+) create mode 100644 spec/integrations/async_line_or_beginning_spec.rb diff --git a/spec/integrations/async_line_or_beginning_spec.rb b/spec/integrations/async_line_or_beginning_spec.rb new file mode 100644 index 0000000..41935fd --- /dev/null +++ b/spec/integrations/async_line_or_beginning_spec.rb @@ -0,0 +1,27 @@ +describe 'using up-line-or-beginning-search when async is enabled' do + let(:options) { ["ZSH_AUTOSUGGEST_USE_ASYNC="] } + let(:before_sourcing) do + -> do + session. + run_command('autoload -U up-line-or-beginning-search'). + run_command('zle -N up-line-or-beginning-search'). + send_string('bindkey "'). + send_keys('C-v').send_keys('up'). + send_string('" up-line-or-beginning-search'). + send_keys('enter') + end + end + + it 'should show previous history entries' do + with_history( + 'echo foo', + 'echo bar', + 'echo baz' + ) do + session.clear_screen + 3.times { session.send_keys('up') } + wait_for { session.content }.to eq("echo foo") + end + end +end + diff --git a/src/config.zsh b/src/config.zsh index ba694c0..5c44af5 100644 --- a/src/config.zsh +++ b/src/config.zsh @@ -21,6 +21,8 @@ ZSH_AUTOSUGGEST_CLEAR_WIDGETS=( history-beginning-search-backward history-substring-search-up history-substring-search-down + up-line-or-beginning-search + down-line-or-beginning-search up-line-or-history down-line-or-history accept-line diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index a9330ea..3e0405d 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -57,6 +57,8 @@ ZSH_AUTOSUGGEST_CLEAR_WIDGETS=( history-beginning-search-backward history-substring-search-up history-substring-search-down + up-line-or-beginning-search + down-line-or-beginning-search up-line-or-history down-line-or-history accept-line From 60aff2d944087e81962515033699e3b5720851ea Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Tue, 27 Mar 2018 14:51:37 -0600 Subject: [PATCH 11/26] Remove unused local `$suggestion` variable --- src/async.zsh | 3 +-- zsh-autosuggestions.zsh | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/async.zsh b/src/async.zsh index 1d1e76d..de55e1d 100644 --- a/src/async.zsh +++ b/src/async.zsh @@ -23,7 +23,6 @@ _zsh_autosuggest_async_server() { # Silence any error messages exec 2>/dev/null - local strategy=$1 local last_pid while IFS='' read -r -d $'\0' query; do @@ -70,7 +69,7 @@ _zsh_autosuggest_async_pty_create() { fi # Fork a zpty process running the server function - zpty -b $ZSH_AUTOSUGGEST_ASYNC_PTY_NAME "_zsh_autosuggest_async_server _zsh_autosuggest_strategy_$ZSH_AUTOSUGGEST_STRATEGY" + zpty -b $ZSH_AUTOSUGGEST_ASYNC_PTY_NAME _zsh_autosuggest_async_server # Store the fd so we can remove the handler later if (( REPLY )); then diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index 3e0405d..a1037ba 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -591,7 +591,6 @@ _zsh_autosuggest_async_server() { # Silence any error messages exec 2>/dev/null - local strategy=$1 local last_pid while IFS='' read -r -d $'\0' query; do @@ -638,7 +637,7 @@ _zsh_autosuggest_async_pty_create() { fi # Fork a zpty process running the server function - zpty -b $ZSH_AUTOSUGGEST_ASYNC_PTY_NAME "_zsh_autosuggest_async_server _zsh_autosuggest_strategy_$ZSH_AUTOSUGGEST_STRATEGY" + zpty -b $ZSH_AUTOSUGGEST_ASYNC_PTY_NAME _zsh_autosuggest_async_server # Store the fd so we can remove the handler later if (( REPLY )); then From afc14f79ccf608078eec4f893bf9da188ae166da Mon Sep 17 00:00:00 2001 From: babaorum Date: Mon, 16 Apr 2018 22:37:54 +0200 Subject: [PATCH 12/26] make Oh my zsh install works without ZSH_CUSTOM defined --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6a6ae1e..65e414a 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ Requirements: Zsh v4.3.11 or later 1. Clone this repository into `$ZSH_CUSTOM/plugins` (by default `~/.oh-my-zsh/custom/plugins`) ```sh - git clone https://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions + git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions ``` 2. Add the plugin to the list of plugins for Oh My Zsh to load: From b2b9bf3b8c72e83feec3c52be0bc06bd4ffa3c56 Mon Sep 17 00:00:00 2001 From: Benjamin Denhartog Date: Mon, 14 May 2018 07:06:14 -0700 Subject: [PATCH 13/26] update arch linux installation instructions (now available via pacman) closes #328 --- README.md | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 65e414a..a8ad5de 100644 --- a/README.md +++ b/README.md @@ -46,17 +46,16 @@ Requirements: Zsh v4.3.11 or later 3. Start a new terminal session. -### Arch Linux via the AUR -1. Install the [`zsh-autosuggestions`](https://aur.archlinux.org/packages/zsh-autosuggestions/) or the [`zsh-autosuggestions-git`](https://aur.archlinux.org/packages/zsh-autosuggestions-git/) packages from the [AUR](https://wiki.archlinux.org/index.php/Arch_User_Repository). +### Arch Linux + +1. Install [`zsh-autosuggestions`](https://www.archlinux.org/packages/community/any/zsh-autosuggestions/) from the `community` repository. ```sh - pacaur -S zsh-autosuggestions - ``` - or - ``` - pacaur -S zsh-autosuggestions-git + pacman -S zsh-autosuggestions ``` + or, to use a package based on the `master` branch, install [`zsh-autosuggestions-git`](https://aur.archlinux.org/packages/zsh-autosuggestions-git/) from the [AUR](https://wiki.archlinux.org/index.php/Arch_User_Repository). + 2. Add the following to your `.zshrc`: ```sh From 19ad3ba7cdc288abb83471ffef9c68d0bc0d59b6 Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Tue, 15 May 2018 10:02:38 -0600 Subject: [PATCH 14/26] Add new 5.5.1 version of zsh to CI --- circle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index d0f7633..c804ae1 100644 --- a/circle.yml +++ b/circle.yml @@ -1,6 +1,6 @@ machine: environment: - ZSH_VERSIONS: zsh-dev/4.3.11 zsh/5.0.2 zsh/5.0.8 zsh/5.1.1 zsh/5.2 zsh/5.3.1 zsh/5.4.2 + ZSH_VERSIONS: zsh-dev/4.3.11 zsh/5.0.2 zsh/5.0.8 zsh/5.1.1 zsh/5.2 zsh/5.3.1 zsh/5.4.2 zsh/5.5.1 dependencies: pre: From 51fef255dabbf827fc9f5f802a12462770e03153 Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Tue, 15 May 2018 11:36:20 -0600 Subject: [PATCH 15/26] Add method to connect terminal to tmux session during tests Useful with `binding.pry` to inspect behavior of tests. --- spec/terminal_session.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/terminal_session.rb b/spec/terminal_session.rb index 82705d3..2d9468f 100644 --- a/spec/terminal_session.rb +++ b/spec/terminal_session.rb @@ -77,6 +77,10 @@ class TerminalSession map(&:to_i) end + def attach! + tmux_command('attach-session') + end + private attr_reader :opts From 42f5a06f7f29007d91e37f85e1dc5a80f1b7c059 Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Tue, 15 May 2018 11:32:46 -0600 Subject: [PATCH 16/26] Need to reset the POSTDISPLAY if exiting early Specific case where this matters is following: Be in vi insert mode with some text in the buffer and the cursor at the end of the buffer. Press `esc` to trigger `vi-cmd-mode widget`, then before the cursor moves (KEYTIMEOUT), press `h` to trigger `vi-backward-char` widget. When `vi-cmd-mode` original widget exits, KEYS_QUEUED_COUNT will be non-zero and the suggestion will be lost. --- spec/integrations/vi_mode_spec.rb | 21 +++++++++++++++++++++ src/widgets.zsh | 1 + zsh-autosuggestions.zsh | 1 + 3 files changed, 23 insertions(+) create mode 100644 spec/integrations/vi_mode_spec.rb diff --git a/spec/integrations/vi_mode_spec.rb b/spec/integrations/vi_mode_spec.rb new file mode 100644 index 0000000..95f9293 --- /dev/null +++ b/spec/integrations/vi_mode_spec.rb @@ -0,0 +1,21 @@ +describe 'when using vi mode' do + let(:before_sourcing) do + -> do + session.run_command('bindkey -v') + end + end + + describe 'moving the cursor after exiting insert mode' do + it 'should not clear the current suggestion' do + with_history('foobar foo') do + session. + send_string('foo'). + send_keys('escape'). + send_keys('h') + + wait_for { session.content }.to eq('foobar foo') + end + end + end +end + diff --git a/src/widgets.zsh b/src/widgets.zsh index 8a31133..2004518 100644 --- a/src/widgets.zsh +++ b/src/widgets.zsh @@ -55,6 +55,7 @@ _zsh_autosuggest_modify() { # Don't fetch a new suggestion if there's more input to be read immediately if (( $PENDING > 0 )) || (( $KEYS_QUEUED_COUNT > 0 )); then + POSTDISPLAY="$orig_postdisplay" return $retval fi diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index a1037ba..bc84bfd 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -333,6 +333,7 @@ _zsh_autosuggest_modify() { # Don't fetch a new suggestion if there's more input to be read immediately if (( $PENDING > 0 )) || (( $KEYS_QUEUED_COUNT > 0 )); then + POSTDISPLAY="$orig_postdisplay" return $retval fi From 393f7b8bb9d83aef1847d39ad20c6a73849917b8 Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Mon, 14 May 2018 10:59:08 -0600 Subject: [PATCH 17/26] Fix vi-mode partial-accept Issue #188. PR #324. Thanks to @toadjaune and @IngoHeimbach. --- spec/integrations/vi_mode_spec.rb | 46 +++++++++++++++++++++++++++++++ src/config.zsh | 2 ++ src/widgets.zsh | 14 +++++++--- zsh-autosuggestions.zsh | 16 ++++++++--- 4 files changed, 70 insertions(+), 8 deletions(-) diff --git a/spec/integrations/vi_mode_spec.rb b/spec/integrations/vi_mode_spec.rb index 95f9293..cf471b5 100644 --- a/spec/integrations/vi_mode_spec.rb +++ b/spec/integrations/vi_mode_spec.rb @@ -17,5 +17,51 @@ describe 'when using vi mode' do end end end + + describe '`vi-forward-word-end`' do + it 'should accept through the end of the current word' do + with_history('foobar foo') do + session. + send_string('foo'). + send_keys('escape'). + send_keys('e'). # vi-forward-word-end + send_keys('a'). # vi-add-next + send_string('baz') + + wait_for { session.content }.to eq('foobarbaz') + end + end + end + + describe '`vi-forward-word`' do + it 'should accept through the first character of the next word' do + with_history('foobar foo') do + session. + send_string('foo'). + send_keys('escape'). + send_keys('w'). # vi-forward-word + send_keys('a'). # vi-add-next + send_string('az') + + wait_for { session.content }.to eq('foobar faz') + end + end + end + + describe '`vi-find-next-char`' do + it 'should accept through the next occurrence of the character' do + with_history('foobar foo') do + session. + send_string('foo'). + send_keys('escape'). + send_keys('f'). # vi-find-next-char + send_keys('o'). + send_keys('a'). # vi-add-next + send_string('b') + + wait_for { session.content }.to eq('foobar fob') + end + end + end end diff --git a/src/config.zsh b/src/config.zsh index 5c44af5..c4d07fd 100644 --- a/src/config.zsh +++ b/src/config.zsh @@ -49,6 +49,8 @@ ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS=( vi-forward-word-end vi-forward-blank-word vi-forward-blank-word-end + vi-find-next-char + vi-find-next-char-skip ) # Widgets that should be ignored (globbing supported but must be escaped) diff --git a/src/widgets.zsh b/src/widgets.zsh index 2004518..87bb62e 100644 --- a/src/widgets.zsh +++ b/src/widgets.zsh @@ -153,7 +153,7 @@ _zsh_autosuggest_execute() { # Partially accept the suggestion _zsh_autosuggest_partial_accept() { - local -i retval + local -i retval cursor_loc # Save the contents of the buffer so we can restore later if needed local original_buffer="$BUFFER" @@ -165,13 +165,19 @@ _zsh_autosuggest_partial_accept() { _zsh_autosuggest_invoke_original_widget $@ retval=$? + # Normalize cursor location across vi/emacs modes + cursor_loc=$CURSOR + if [[ "$KEYMAP" = "vicmd" ]]; then + cursor_loc=$((cursor_loc + 1)) + fi + # If we've moved past the end of the original buffer - if (( $CURSOR > $#original_buffer )); then + if (( $cursor_loc > $#original_buffer )); then # Set POSTDISPLAY to text right of the cursor - POSTDISPLAY="$RBUFFER" + POSTDISPLAY="${BUFFER[$(($cursor_loc + 1)),$#BUFFER]}" # Clip the buffer at the cursor - BUFFER="$LBUFFER" + BUFFER="${BUFFER[1,$cursor_loc]}" else # Restore the original buffer BUFFER="$original_buffer" diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index bc84bfd..4c06cdb 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -85,6 +85,8 @@ ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS=( vi-forward-word-end vi-forward-blank-word vi-forward-blank-word-end + vi-find-next-char + vi-find-next-char-skip ) # Widgets that should be ignored (globbing supported but must be escaped) @@ -431,7 +433,7 @@ _zsh_autosuggest_execute() { # Partially accept the suggestion _zsh_autosuggest_partial_accept() { - local -i retval + local -i retval cursor_loc # Save the contents of the buffer so we can restore later if needed local original_buffer="$BUFFER" @@ -443,13 +445,19 @@ _zsh_autosuggest_partial_accept() { _zsh_autosuggest_invoke_original_widget $@ retval=$? + # Normalize cursor location across vi/emacs modes + cursor_loc=$CURSOR + if [[ "$KEYMAP" = "vicmd" ]]; then + cursor_loc=$((cursor_loc + 1)) + fi + # If we've moved past the end of the original buffer - if (( $CURSOR > $#original_buffer )); then + if (( $cursor_loc > $#original_buffer )); then # Set POSTDISPLAY to text right of the cursor - POSTDISPLAY="$RBUFFER" + POSTDISPLAY="${BUFFER[$(($cursor_loc + 1)),$#BUFFER]}" # Clip the buffer at the cursor - BUFFER="$LBUFFER" + BUFFER="${BUFFER[1,$cursor_loc]}" else # Restore the original buffer BUFFER="$original_buffer" From 59c72c68059b2f18cd1090ef10b1f9398920ac56 Mon Sep 17 00:00:00 2001 From: Harm te Hennepe Date: Sun, 24 Dec 2017 22:46:20 +0100 Subject: [PATCH 18/26] Don't break kill ring rotation --- spec/kill_ring_spec.rb | 23 +++++++++++++++++++++++ src/config.zsh | 1 + zsh-autosuggestions.zsh | 1 + 3 files changed, 25 insertions(+) create mode 100644 spec/kill_ring_spec.rb diff --git a/spec/kill_ring_spec.rb b/spec/kill_ring_spec.rb new file mode 100644 index 0000000..4d0178f --- /dev/null +++ b/spec/kill_ring_spec.rb @@ -0,0 +1,23 @@ +context 'with some items in the kill ring' do + before do + session. + send_string('echo foo'). + send_keys('C-u'). + send_string('echo bar'). + send_keys('C-u') + end + + describe '`yank-pop`' do + it 'should cycle through all items in the kill ring' do + session.send_keys('C-y') + wait_for { session.content }.to eq('echo bar') + + session.send_keys('escape').send_keys('y') + wait_for { session.content }.to eq('echo foo') + + session.send_keys('escape').send_keys('y') + wait_for { session.content }.to eq('echo bar') + end + end +end + diff --git a/src/config.zsh b/src/config.zsh index c4d07fd..597307f 100644 --- a/src/config.zsh +++ b/src/config.zsh @@ -61,6 +61,7 @@ ZSH_AUTOSUGGEST_IGNORE_WIDGETS=( set-local-history which-command yank + yank-pop ) # Max size of buffer to trigger autosuggestion. Leave undefined for no upper bound. diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index 4c06cdb..7f6e7de 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -97,6 +97,7 @@ ZSH_AUTOSUGGEST_IGNORE_WIDGETS=( set-local-history which-command yank + yank-pop ) # Max size of buffer to trigger autosuggestion. Leave undefined for no upper bound. From 726bc4eb5c44133f95be26d82bd34531df5c89a5 Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Tue, 15 May 2018 13:42:18 -0600 Subject: [PATCH 19/26] Create general spec for async behavior --- spec/async_spec.rb | 31 +++++++++++++++++++ .../async_line_or_beginning_spec.rb | 27 ---------------- 2 files changed, 31 insertions(+), 27 deletions(-) create mode 100644 spec/async_spec.rb delete mode 100644 spec/integrations/async_line_or_beginning_spec.rb diff --git a/spec/async_spec.rb b/spec/async_spec.rb new file mode 100644 index 0000000..9405fb2 --- /dev/null +++ b/spec/async_spec.rb @@ -0,0 +1,31 @@ +context 'with asynchronous suggestions enabled' do + let(:options) { ["ZSH_AUTOSUGGEST_USE_ASYNC="] } + + describe '`up-line-or-beginning-search`' do + let(:before_sourcing) do + -> do + session. + run_command('autoload -U up-line-or-beginning-search'). + run_command('zle -N up-line-or-beginning-search'). + send_string('bindkey "'). + send_keys('C-v').send_keys('up'). + send_string('" up-line-or-beginning-search'). + send_keys('enter') + end + end + + it 'should show previous history entries' do + with_history( + 'echo foo', + 'echo bar', + 'echo baz' + ) do + session.clear_screen + 3.times { session.send_keys('up') } + wait_for { session.content }.to eq("echo foo") + end + end + end +end + + diff --git a/spec/integrations/async_line_or_beginning_spec.rb b/spec/integrations/async_line_or_beginning_spec.rb deleted file mode 100644 index 41935fd..0000000 --- a/spec/integrations/async_line_or_beginning_spec.rb +++ /dev/null @@ -1,27 +0,0 @@ -describe 'using up-line-or-beginning-search when async is enabled' do - let(:options) { ["ZSH_AUTOSUGGEST_USE_ASYNC="] } - let(:before_sourcing) do - -> do - session. - run_command('autoload -U up-line-or-beginning-search'). - run_command('zle -N up-line-or-beginning-search'). - send_string('bindkey "'). - send_keys('C-v').send_keys('up'). - send_string('" up-line-or-beginning-search'). - send_keys('enter') - end - end - - it 'should show previous history entries' do - with_history( - 'echo foo', - 'echo bar', - 'echo baz' - ) do - session.clear_screen - 3.times { session.send_keys('up') } - wait_for { session.content }.to eq("echo foo") - end - end -end - From df5fb858aa55448cd6a522fd66b0a0c577085787 Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Tue, 15 May 2018 13:55:37 -0600 Subject: [PATCH 20/26] Destroy old pty even if it's no longer running (#249) For unknown reasons, the pty will occasionally quit running. In these cases, we still want to remove it so that a fresh one can be created. We don't actually need this check because error messages from `zle` and `zpty` are redirected to /dev/null. One sure way to kill all currently running pty's is to run `exit` in a subshell. Even without zsh-autosuggestions loaded, the following works: % zmodload zsh/zpty % zpty -b foo cat % zpty -b bar cat % zpty (31689) bar: cat (31666) foo: cat % $(exit) % zpty (finished) bar: cat (finished) foo: cat --- spec/async_spec.rb | 10 ++++++++++ src/async.zsh | 10 ++++------ zsh-autosuggestions.zsh | 10 ++++------ 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/spec/async_spec.rb b/spec/async_spec.rb index 9405fb2..0bcbaa1 100644 --- a/spec/async_spec.rb +++ b/spec/async_spec.rb @@ -26,6 +26,16 @@ context 'with asynchronous suggestions enabled' do end end end + + describe 'exiting a subshell' do + it 'should not cause error messages to be printed' do + session.run_command('$(exit)') + + sleep 1 + + expect(session.content).to eq('$(exit)') + end + end end diff --git a/src/async.zsh b/src/async.zsh index de55e1d..9a0cfaa 100644 --- a/src/async.zsh +++ b/src/async.zsh @@ -83,13 +83,11 @@ _zsh_autosuggest_async_pty_create() { } _zsh_autosuggest_async_pty_destroy() { - if zpty -t $ZSH_AUTOSUGGEST_ASYNC_PTY_NAME &>/dev/null; then - # Remove the input handler - zle -F $_ZSH_AUTOSUGGEST_PTY_FD &>/dev/null + # Remove the input handler + zle -F $_ZSH_AUTOSUGGEST_PTY_FD &>/dev/null - # Destroy the zpty - zpty -d $ZSH_AUTOSUGGEST_ASYNC_PTY_NAME &>/dev/null - fi + # Destroy the zpty + zpty -d $ZSH_AUTOSUGGEST_ASYNC_PTY_NAME &>/dev/null } _zsh_autosuggest_async_pty_recreate() { diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index 7f6e7de..3443469 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -661,13 +661,11 @@ _zsh_autosuggest_async_pty_create() { } _zsh_autosuggest_async_pty_destroy() { - if zpty -t $ZSH_AUTOSUGGEST_ASYNC_PTY_NAME &>/dev/null; then - # Remove the input handler - zle -F $_ZSH_AUTOSUGGEST_PTY_FD &>/dev/null + # Remove the input handler + zle -F $_ZSH_AUTOSUGGEST_PTY_FD &>/dev/null - # Destroy the zpty - zpty -d $ZSH_AUTOSUGGEST_ASYNC_PTY_NAME &>/dev/null - fi + # Destroy the zpty + zpty -d $ZSH_AUTOSUGGEST_ASYNC_PTY_NAME &>/dev/null } _zsh_autosuggest_async_pty_recreate() { From b003b2238adc66fb38f8c0a382e9374a7c4aa21c Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Mon, 21 May 2018 10:46:03 -0600 Subject: [PATCH 21/26] Update changelog for v0.4.3 release --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3134f5f..f017be2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## v0.4.3 +- Avoid bell when accepting suggestions with `autosuggest-accept` (#228) +- Don't fetch suggestions after [up,down]-line-or-beginning-search (#227, #241) +- We are now running CI against new 5.5.1 version +- Fix partial-accept in vi mode (#188) +- Fix suggestion disappearing on fast movement after switching to `vicmd` mode (#290) +- Fix issue rotating through kill ring with `yank-pop` (#301) +- Fix issue creating new pty for async mode when previous pty is not properly cleaned up (#249) + ## v0.4.2 - Fix bug in zsh versions older than 5.0.8 (#296) - Officially support back to zsh v4.3.11 From c113e49fe22b659b1c79698294215fd0e4c7e4d9 Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Mon, 21 May 2018 10:52:41 -0600 Subject: [PATCH 22/26] Update license copyright year --- LICENSE | 2 +- zsh-autosuggestions.zsh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/LICENSE b/LICENSE index ad6594e..bcbc8b9 100644 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,5 @@ Copyright (c) 2013 Thiago de Arruda -Copyright (c) 2016-2017 Eric Freese +Copyright (c) 2016-2018 Eric Freese Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index 3443469..c47586a 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -2,7 +2,7 @@ # https://github.com/zsh-users/zsh-autosuggestions # v0.4.2 # Copyright (c) 2013 Thiago de Arruda -# Copyright (c) 2016-2017 Eric Freese +# Copyright (c) 2016-2018 Eric Freese # # Permission is hereby granted, free of charge, to any person # obtaining a copy of this software and associated documentation From 72ccee33b400af989160d9fd5b91bd2ec0481dbd Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Mon, 21 May 2018 11:35:26 -0600 Subject: [PATCH 23/26] Pull out separate doc for installation instructions --- INSTALL.md | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 69 +++--------------------------------------------------- 2 files changed, 70 insertions(+), 66 deletions(-) create mode 100644 INSTALL.md diff --git a/INSTALL.md b/INSTALL.md new file mode 100644 index 0000000..945cec7 --- /dev/null +++ b/INSTALL.md @@ -0,0 +1,67 @@ +## Installation + +### Manual (Git Clone) + +1. Clone this repository somewhere on your machine. This guide will assume `~/.zsh/zsh-autosuggestions`. + + ```sh + git clone https://github.com/zsh-users/zsh-autosuggestions ~/.zsh/zsh-autosuggestions + ``` + +2. Add the following to your `.zshrc`: + + ```sh + source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh + ``` + +3. Start a new terminal session. + +### Oh My Zsh + +1. Clone this repository into `$ZSH_CUSTOM/plugins` (by default `~/.oh-my-zsh/custom/plugins`) + + ```sh + git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions + ``` + +2. Add the plugin to the list of plugins for Oh My Zsh to load: + + ```sh + plugins=(zsh-autosuggestions) + ``` + +3. Start a new terminal session. + +### Arch Linux + +1. Install [`zsh-autosuggestions`](https://www.archlinux.org/packages/community/any/zsh-autosuggestions/) from the `community` repository. + + ```sh + pacman -S zsh-autosuggestions + ``` + + or, to use a package based on the `master` branch, install [`zsh-autosuggestions-git`](https://aur.archlinux.org/packages/zsh-autosuggestions-git/) from the [AUR](https://wiki.archlinux.org/index.php/Arch_User_Repository). + +2. Add the following to your `.zshrc`: + + ```sh + source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh + ``` + +3. Start a new terminal session. + +### macOS via Homebrew +1. Install the `zsh-autosuggestions` package using [Homebrew](https://brew.sh/). + + ```sh + brew install zsh-autosuggestions + ``` + +2. Add the following to your `.zshrc`: + + ```sh + source /usr/local/share/zsh-autosuggestions/zsh-autosuggestions.zsh + ``` + +3. Start a new terminal session. + diff --git a/README.md b/README.md index a8ad5de..4ad07d8 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ _[Fish](http://fishshell.com/)-like fast/unobtrusive autosuggestions for zsh._ It suggests commands as you type, based on command history. +Requirements: Zsh v4.3.11 or later + [![CircleCI](https://circleci.com/gh/zsh-users/zsh-autosuggestions.svg?style=svg)](https://circleci.com/gh/zsh-users/zsh-autosuggestions) @@ -11,73 +13,8 @@ It suggests commands as you type, based on command history. ## Installation -Requirements: Zsh v4.3.11 or later +See [INSTALL.md](INSTALL.md). -### Manual - -1. Clone this repository somewhere on your machine. This guide will assume `~/.zsh/zsh-autosuggestions`. - - ```sh - git clone https://github.com/zsh-users/zsh-autosuggestions ~/.zsh/zsh-autosuggestions - ``` - -2. Add the following to your `.zshrc`: - - ```sh - source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh - ``` - -3. Start a new terminal session. - - -### Oh My Zsh - -1. Clone this repository into `$ZSH_CUSTOM/plugins` (by default `~/.oh-my-zsh/custom/plugins`) - - ```sh - git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions - ``` - -2. Add the plugin to the list of plugins for Oh My Zsh to load: - - ```sh - plugins=(zsh-autosuggestions) - ``` - -3. Start a new terminal session. - -### Arch Linux - -1. Install [`zsh-autosuggestions`](https://www.archlinux.org/packages/community/any/zsh-autosuggestions/) from the `community` repository. - - ```sh - pacman -S zsh-autosuggestions - ``` - - or, to use a package based on the `master` branch, install [`zsh-autosuggestions-git`](https://aur.archlinux.org/packages/zsh-autosuggestions-git/) from the [AUR](https://wiki.archlinux.org/index.php/Arch_User_Repository). - -2. Add the following to your `.zshrc`: - - ```sh - source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh - ``` - -3. Start a new terminal session. - -### macOS via Homebrew -1. Install the `zsh-autosuggestions` package using [Homebrew](https://brew.sh/). - - ```sh - brew install zsh-autosuggestions - ``` - -2. Add the following to your `.zshrc`: - - ```sh - source /usr/local/share/zsh-autosuggestions/zsh-autosuggestions.zsh - ``` - -3. Start a new terminal session. ## Usage From aa0b10db4440f3fd01bbc2dbd8fd4590fc50a1d1 Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Mon, 21 May 2018 11:38:41 -0600 Subject: [PATCH 24/26] v0.4.3 --- VERSION | 2 +- zsh-autosuggestions.zsh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index 0eec13e..f87d474 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v0.4.2 +v0.4.3 diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index c47586a..1c3eab5 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -1,6 +1,6 @@ # Fish-like fast/unobtrusive autosuggestions for zsh. # https://github.com/zsh-users/zsh-autosuggestions -# v0.4.2 +# v0.4.3 # Copyright (c) 2013 Thiago de Arruda # Copyright (c) 2016-2018 Eric Freese # From 63789e96b54d8e8acb91792216cc564f16d2cd07 Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Sat, 26 May 2018 14:01:03 -0600 Subject: [PATCH 25/26] Fix handling of newline + carriage return in async pty (#333) --- spec/async_spec.rb | 39 +++++++++++++++++++++++++++++++++++++++ src/async.zsh | 5 ++++- zsh-autosuggestions.zsh | 5 ++++- 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/spec/async_spec.rb b/spec/async_spec.rb index 0bcbaa1..10f1a74 100644 --- a/spec/async_spec.rb +++ b/spec/async_spec.rb @@ -27,6 +27,45 @@ context 'with asynchronous suggestions enabled' do end end + it 'should not add extra carriage returns before newlines' do + session. + send_string('echo "'). + send_keys('escape'). + send_keys('enter'). + send_string('"'). + send_keys('enter') + + session.clear_screen + + session.send_string('echo') + wait_for { session.content }.to eq("echo \"\n\"") + end + + it 'should treat carriage returns and newlines as separate characters' do + session. + send_string('echo "'). + send_keys('C-v'). + send_keys('enter'). + send_string('foo"'). + send_keys('enter') + + session. + send_string('echo "'). + send_keys('control'). + send_keys('enter'). + send_string('bar"'). + send_keys('enter') + + session.clear_screen + + session. + send_string('echo "'). + send_keys('C-v'). + send_keys('enter') + + wait_for { session.content }.to eq('echo "^Mfoo"') + end + describe 'exiting a subshell' do it 'should not cause error messages to be printed' do session.run_command('$(exit)') diff --git a/src/async.zsh b/src/async.zsh index 9a0cfaa..62e3329 100644 --- a/src/async.zsh +++ b/src/async.zsh @@ -17,9 +17,12 @@ _zsh_autosuggest_async_server() { sleep 1 # Block for long enough for the signal to come through } - # Output only newlines (not carriage return + newline) + # Don't add any extra carriage returns stty -onlcr + # Don't translate carriage returns to newlines + stty -icrnl + # Silence any error messages exec 2>/dev/null diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index 1c3eab5..e2e06be 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -595,9 +595,12 @@ _zsh_autosuggest_async_server() { sleep 1 # Block for long enough for the signal to come through } - # Output only newlines (not carriage return + newline) + # Don't add any extra carriage returns stty -onlcr + # Don't translate carriage returns to newlines + stty -icrnl + # Silence any error messages exec 2>/dev/null From 5549b68e6edd285a50173c7360a935d91879f33a Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Sat, 26 May 2018 15:33:32 -0600 Subject: [PATCH 26/26] Async is less reliable in zsh versions < 5.0.8 `stty` occasionally hangs (always in CircleCI) inside the async pty. Disable the tests for now until we can figure out and fix/workaround this issue. --- spec/async_spec.rb | 4 ++++ spec/terminal_session.rb | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/spec/async_spec.rb b/spec/async_spec.rb index 10f1a74..152adde 100644 --- a/spec/async_spec.rb +++ b/spec/async_spec.rb @@ -1,4 +1,8 @@ context 'with asynchronous suggestions enabled' do + before do + skip 'Async mode not supported below v5.0.8' if session.zsh_version < Gem::Version.new('5.0.8') + end + let(:options) { ["ZSH_AUTOSUGGEST_USE_ASYNC="] } describe '`up-line-or-beginning-search`' do diff --git a/spec/terminal_session.rb b/spec/terminal_session.rb index 2d9468f..f91ee6c 100644 --- a/spec/terminal_session.rb +++ b/spec/terminal_session.rb @@ -18,6 +18,10 @@ class TerminalSession tmux_command("new-session -d -x #{opts[:width]} -y #{opts[:height]} '#{cmd}'") end + def zsh_version + @zsh_version ||= Gem::Version.new(`#{ZSH_BIN} -c 'echo -n $ZSH_VERSION'`) + end + def tmux_socket_name @tmux_socket_name ||= SecureRandom.hex(6) end