Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setopt HIST_IGNORE_ALL_DUPS breaks history completion. #280

Closed
cpakkala opened this issue Jun 1, 2021 · 8 comments
Closed

setopt HIST_IGNORE_ALL_DUPS breaks history completion. #280

cpakkala opened this issue Jun 1, 2021 · 8 comments
Assignees
Labels
question Further information is requested

Comments

@cpakkala
Copy link

cpakkala commented Jun 1, 2021

  • zsh-autocomplete version: 7f44a6d
  • Zsh version: zsh-5.8-0-g77d203f
  • Framework: none
  • Plugin manager: none
$ cd ~zsh-autocomplete
$ git switch main       # Make sure you test with the `main` branch.
$ git pull              # Update to the latest commit.
$ cd $(mktemp -d)       # Create a temp dir and enter it.
$ # Restart Zsh without config files or environment variables in this dir:
$ exec env -i HOME=$PWD PS1='%# ' TERM=$TERM zsh -f
% source /path/to/zsh-autocomplete/zsh-autocomplete.plugin.zsh
% setopt HIST_IGNORE_ALL_DUPS
% setopt HIST_FIND_NO_DUPS
% echo blah
% pwd
% echo blah
% <up arrow>  (up-line-or-history widget)
_autocomplete.history_lines:22: invalid subscript

The problem is that HIST_IGNORE_ALL_DUPS removes items from the $history array, but there are multiple places in the code that cycle through all the indexes, starting with line 22 of history_lines:
[[ -v events[$history[$histno]] ]]

If you insert an "echo $histno" just before that line, you can see which index it fails on and then you can see with the "history" command that that index cooresponds to the index of the first "echo blah" above which was removed when the second instance was entered.

@cpakkala cpakkala added the bug Something isn't working label Jun 1, 2021
@marlonrichert
Copy link
Owner

marlonrichert commented Jun 1, 2021

I'm unable to reproduce this with the exact steps you've given. Are you sure you've executed them to the letter? In particular, it's important that you first do cd $(mktemp -d); exec env -i HOME=$PWD PS1='%# ' TERM=$TERM zsh -f, before executing your test case.

@marlonrichert marlonrichert added question Further information is requested and removed bug Something isn't working labels Jun 1, 2021
@cpakkala
Copy link
Author

cpakkala commented Jun 2, 2021

I'm unable to reproduce this with the exact steps you've given. Are you sure you've executed them to the letter? In particular, it's important that you first do cd $(mktemp -d); exec env -i HOME=$PWD PS1='%# ' TERM=$TERM zsh -f, before executing your test case.

My mistake; it also requires setopt HIST_FIND_NO_DUPS.

@marlonrichert
Copy link
Owner

Works fine for me:

% cd $(mktemp -d)
exec env -i PS1='%# ' HOME=$PWD TERM=$TERM zsh -f 
% git clone --depth 1 -- https://github.com/marlonrichert/zsh-autocomplete.git
Cloning into 'zsh-autocomplete'...
remote: Enumerating objects: 59, done.
remote: Counting objects: 100% (59/59), done.
remote: Compressing objects: 100% (54/54), done.
remote: Total 59 (delta 0), reused 29 (delta 0), pack-reused 0
Receiving objects: 100% (59/59), 1.60 MiB | 2.62 MiB/s, done.
% source zsh-autocomplete/zsh-autocomplete.plugin.zsh 
% setopt histfindnodups
% echo blah
blah
% pwd
/private/var/folders/24/37_vm48s2tz9bhmj1rzffvl40000gn/T/tmp.nukaIfV0
% echo blah
blah
% setopt histignorealldups
% setopt histignorealldups;
1 git clone --depth 1 -- https://github.com/marlonrichert/zsh-autocomplete.git                                                                                            
2 source zsh-autocomplete/zsh-autocomplete.plugin.zsh                                                                                                                     
3 setopt histfindnodups                                                                                                                                                   
5 pwd                                                                                                                                                                     
6 echo blah                                                                                                                                                               
7 setopt histignorealldups

@cpakkala
Copy link
Author

cpakkala commented Jun 5, 2021

I don't know how we're different:

$ cd $(mktemp -d) && exec env -i HOME=$PWD PS1='%# ' TERM=$TERM zsh -f
% git clone --depth 1 -- https://github.com/marlonrichert/zsh-autocomplete.git
Cloning into 'zsh-autocomplete'...
remote: Enumerating objects: 59, done.
remote: Counting objects: 100% (59/59), done.
remote: Compressing objects: 100% (54/54), done.
remote: Total 59 (delta 0), reused 29 (delta 0), pack-reused 0
Receiving objects: 100% (59/59), 1.60 MiB | 8.75 MiB/s, done.
% source zsh-autocomplete/zsh-autocomplete.plugin.zsh
% setopt histfindnodups
% setopt histignorealldups
% echo blah
blah
% pwd
/tmp/tmp.vJuCEJBbPm
% echo blah
blah
%
_autocomplete.history_lines:22: invalid subscript
% echo $ZSH_VERSION
5.8

@marlonrichert
Copy link
Owner

Can you try that again, but before you press ⬆️, run this:

functions -t _autocomplete.history_lines

@cpakkala
Copy link
Author

cpakkala commented Jun 5, 2021

$ cd $(mktemp -d) && exec env -i HOME=$PWD PS1='%# ' TERM=$TERM zsh -f                                                                                                   
% git clone --depth 1 -- https://github.com/marlonrichert/zsh-autocomplete.git                                                                                           
Cloning into 'zsh-autocomplete'...                                                                                                                                       
remote: Enumerating objects: 59, done.                                                                                                                                   
remote: Counting objects: 100% (59/59), done.                                                                                                                            
remote: Compressing objects: 100% (54/54), done.                                                                                                                         
remote: Total 59 (delta 0), reused 29 (delta 0), pack-reused 0                                                                                                           
Receiving objects: 100% (59/59), 1.60 MiB | 7.41 MiB/s, done.                                                                                                            
% source zsh-autocomplete/zsh-autocomplete.plugin.zsh                                                                                                                    
% setopt histfindnodups histignorealldups                                                                                                                                
% echo blah                                                                                                                                                              
blah                                                                                                                                                                     
% pwd                                                                                                                                                                    
/tmp/tmp.sPqaFIhq39                                                                                                                                                      
% echo blah                                                                                                                                                              
blah                                                                                                                                                                     
% functions -t _autocomplete.history_lines                                                                                                                               
% +_autocomplete.history_lines:113> _autocomplete.history_lines                                                                                                          
+_autocomplete.history_lines:1> local tag=history-lines                                                                                                                  
+_autocomplete.history_lines:2> _tags history-lines                                                                                                                      
+_tags:3> local prev                                                                                                                                                     
+_tags:10> [[ history-lines = -- ]]                                                                                                                                      
+_tags:15> ((  1  ))                                                                                                                                                     
+_tags:19> local curcontext=history-search:autocomplete.history-lines:: order tag nodef tmp                                                                              
+_tags:21> [[ history-lines = -C?* ]]                                                                                                                                    
+_tags:24> [[ history-lines = -C ]]                                                                                                                                      
+_tags:29> [[ history-lines = -(|-) ]]                                                                                                                                   
+_tags:31> zstyle -a :completion:history-search:autocomplete.history-lines::: group-order order                                                                          
+_tags:32> compgroups expansions history-words options aliases functions builtins reserved-words executables local-directories directories suffix-aliases                
+_tags:36> comptags -i history-search:autocomplete.history-lines:: history-lines                                                                                         
+_tags:40> [[ -n '' ]]                                                                                                                                                   
+_tags:43> zstyle -a :completion:history-search:autocomplete.history-lines::: tag-order order                                                                            
+_tags:44> ((  ! 0  ))                                                                                                                                                   
+_tags:55> [[ -z '' ]]                                                                                                                                                   
+_tags:55> comptry history-lines                                                                                                                                         
+_tags:60> comptags -T                                                                                                                                                   
+_tags:62> return                                                                                                                                                        
+_autocomplete.history_lines:3> _tags                                                                                                                                    
+_tags:3> local prev
+_tags:10> [[ '' = -- ]]
+_tags:15> ((  0  ))
+_tags:67> comptags -N
+_autocomplete.history_lines:5> _requested history-lines
+_requested:3> local __gopt
+_requested:5> __gopt=( ) 
+_requested:6> zparseopts -D -a __gopt 1 2 V J x
+_requested:8> comptags -R history-lines
+_requested:9> [[ 1 -gt 3 ]]
+_requested:11> [[ 1 -gt 1 ]]
+_requested:14> return 0
+_autocomplete.history_lines:8> local -A events=( )
+_autocomplete.history_lines:9> local -i min_lines max_lines
+_autocomplete.history_lines:10> zstyle -s :autocomplete:history-search:autocomplete.history-lines::: list-lines min_lines
+_autocomplete.history_lines:11> min_lines=16 
+_autocomplete.history_lines:12> ((  max_lines = min( min_lines, HISTNO - 1, LINES - BUFFERLINES ) +zsh_math_func_min:1> local result=16
+zsh_math_func_min:2> shift
+zsh_math_func_min:3> local arg
+zsh_math_func_min:4> arg=7
+zsh_math_func_min:5> ((  7 < result  ))
+zsh_math_func_min:5> result=7 
+zsh_math_func_min:4> arg=47
+zsh_math_func_min:5> ((  47 < result  ))
+zsh_math_func_min:7> ((  result  ))
 ))
+_autocomplete.history_lines:14> [[ -z '' ]]
+_autocomplete.history_lines:15> [[ history-search:autocomplete.history-lines:: == *-forward:* ]]
+_autocomplete.history_lines:18> local -i inc=-1 histno=7
+_autocomplete.history_lines:20> [[ -o histfindnodups ]]
+_autocomplete.history_lines:21> ((  0 < max_lines && 0 < histno && histno < HISTNO  ))
+_autocomplete.history_lines:22> [[ -v 'events[functions -t _autocomplete.history_lines]' ]]
+_autocomplete.history_lines:23> events[$history[$histno]]=7 
+_autocomplete.history_lines:24> ((  histno += inc  ))
+_autocomplete.history_lines:21> ((  1 < max_lines && 0 < histno && histno < HISTNO  ))
+_autocomplete.history_lines:22> [[ -v 'events[echo blah]' ]]
+_autocomplete.history_lines:23> events[$history[$histno]]=6 
+_autocomplete.history_lines:24> ((  histno += inc  ))
+_autocomplete.history_lines:21> ((  2 < max_lines && 0 < histno && histno < HISTNO  ))
+_autocomplete.history_lines:22> [[ -v 'events[pwd]' ]]
+_autocomplete.history_lines:23> events[$history[$histno]]=5 
+_autocomplete.history_lines:24> ((  histno += inc  ))
+_autocomplete.history_lines:21> ((  3 < max_lines && 0 < histno && histno < HISTNO  ))

+_autocomplete.history_lines:22> [[ -v 'events[]'_autocomplete.history_lines:22: invalid subscript
 ]]
% 

@marlonrichert
Copy link
Owner

I'm able to reproduce it now and I know how to fix it.

@marlonrichert marlonrichert self-assigned this Jun 7, 2021
marlonrichert added a commit that referenced this issue Jun 7, 2021
@marlonrichert
Copy link
Owner

marlonrichert commented Jun 7, 2021

Fixed.


If you use my software on a regular basis, please consider sponsoring me. 🙂

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants