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]]}" } #--------------------------------------------------------------------#