Browse Source

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.
pull/180/head
Eric Freese 7 years ago
parent
commit
0305908adf
3 changed files with 17 additions and 3 deletions
  1. +1
    -1
      spec/strategies/default_spec.rb
  2. +8
    -1
      src/strategies/default.zsh
  3. +8
    -1
      zsh-autosuggestions.zsh

+ 1
- 1
spec/strategies/default_spec.rb View File

@ -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')

+ 8
- 1
src/strategies/default.zsh View File

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

+ 8
- 1
zsh-autosuggestions.zsh View File

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

Loading…
Cancel
Save