From 0305908adf1f9ee703d545cc18ef77c34092d410 Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Tue, 24 Jan 2017 23:04:07 -0700 Subject: [PATCH] Revert `fc` usage in calculating suggestion As far as I know, `fc` makes it impossible to tell whether history items used an actual newline character or the string "\n". Pulling from the `$history` array gives a more accurate representation of the actual command that was run. --- spec/strategies/default_spec.rb | 2 +- src/strategies/default.zsh | 9 ++++++++- zsh-autosuggestions.zsh | 9 ++++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/spec/strategies/default_spec.rb b/spec/strategies/default_spec.rb index 1b6a4a2..3987c7e 100644 --- a/spec/strategies/default_spec.rb +++ b/spec/strategies/default_spec.rb @@ -30,7 +30,7 @@ describe 'default strategy' do end end - xcontext 'with a multiline hist entry' do + context 'with a multiline hist entry' do before do session.send_string('echo "') session.send_keys('enter') diff --git a/src/strategies/default.zsh b/src/strategies/default.zsh index a242ee0..4246b78 100644 --- a/src/strategies/default.zsh +++ b/src/strategies/default.zsh @@ -9,5 +9,12 @@ _zsh_autosuggest_strategy_default() { setopt localoptions EXTENDED_GLOB - fc -lnrm "${1//(#m)[\\()\[\]|*?~]/\\$MATCH}*" 1 2>/dev/null | head -n 1 + local prefix="${1//(#m)[\\()\[\]|*?~]/\\$MATCH}" + + # Get the keys of the history items that match + local -a histkeys + histkeys=(${(k)history[(r)$prefix*]}) + + # Echo the value of the first key + echo -E "${history[$histkeys[1]]}" } diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index 2dc5141..a438c65 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -421,7 +421,14 @@ zle -N _autosuggest-show-suggestion _zsh_autosuggest_show_suggestion _zsh_autosuggest_strategy_default() { setopt localoptions EXTENDED_GLOB - fc -lnrm "${1//(#m)[\\()\[\]|*?~]/\\$MATCH}*" 1 2>/dev/null | head -n 1 + local prefix="${1//(#m)[\\()\[\]|*?~]/\\$MATCH}" + + # Get the keys of the history items that match + local -a histkeys + histkeys=(${(k)history[(r)$prefix*]}) + + # Echo the value of the first key + echo -E "${history[$histkeys[1]]}" } #--------------------------------------------------------------------#