Fzf: ctrl+r history results should be unique by command

Created on 10 Aug 2014  Â·  9Comments  Â·  Source: junegunn/fzf

I normally have used ctrl+r and hit it a few times to get the right command pre-fzf, which worked fine, and now with fzf, I can use my arrow keys to scroll the results, but I have _many_ more to scroll than before. I don't see any value in presenting numerous duplicate results here, and zsh's default ctrl+r behavior doesn't do this.

question tip

Most helpful comment

I want my history file to contain the duplicates, because I want to see my history. But I don't want them showing up in multiple entries when I search them through fzf. Can't we do that?

All 9 comments

How about adding setopt hist_ignore_dups to your zshrc?

(See the previous discussion here: https://github.com/junegunn/fzf/issues/49)

+1 cool, thank you!

@junegunn : that did not change the behavior. I still see duplicates.

@bnovc It works for me, see:

jg% fc -l 1
    1  fc -l 1
jg% echo 'hello'
hello
jg% echo 'hello'
hello
jg% echo 'hello'
hello
jg% fc -l 1
    1  fc -l 1
    2  echo 'hello'
    3  echo 'hello'
    4  echo 'hello'
jg% setopt hist_ignore_dups
jg% echo 'world'
world
jg% echo 'world'
world
jg% echo 'world'
world
jg% fc -l 1
    1  fc -l 1
    2  echo 'hello'
    3  echo 'hello'
    4  echo 'hello'
    5  fc -l 1
    6  setopt hist_ignore_dups
    7  echo 'world'
jg%

Ah, I didn't realize it would not collapse old commands. This is probably fine then.

Thank you

Sent from my iPhone

On Aug 13, 2014, at 5:49 PM, Junegunn Choi [email protected] wrote:

@bnovc It works for me, see:

jg% fc -l 1
1 fc -l 1
jg% echo 'hello'
hello
jg% echo 'hello'
hello
jg% echo 'hello'
hello
jg% fc -l 1
1 fc -l 1
2 echo 'hello'
3 echo 'hello'
4 echo 'hello'
jg% setopt hist_ignore_dups
jg% echo 'world'
world
jg% echo 'world'
world
jg% echo 'world'
world
jg% fc -l 1
1 fc -l 1
2 echo 'hello'
3 echo 'hello'
4 echo 'hello'
5 fc -l 1
6 setopt hist_ignore_dups
7 echo 'world'
jg%
—
Reply to this email directly or view it on GitHub.

Okay, I'm closing this issue.

@junegunn could you please provide an example on how to enable this option in fish? It doesn't have setopt.
I've tried adding

set hist_ignore_dups
set HIST_IGNORE_DUPS

in my working .config/fish/config.fish, but it has no effect on terminal restart. What is interesting though is that running set hist_ignore_dups actually makes it work, but I would like that to be set automatically on the start of each terminal session.

UPDATE: actually setting it with -g helped, so nothing to worry about [:

set -g hist_ignore_dups

I want my history file to contain the duplicates, because I want to see my history. But I don't want them showing up in multiple entries when I search them through fzf. Can't we do that?

It's not simple as it sounds so it's not supported. If you know some shell scripting, you should be able to implement your own version of the binding.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sassanh picture sassanh  Â·  3Comments

chrisamow picture chrisamow  Â·  3Comments

aleclarson picture aleclarson  Â·  3Comments

ahmedelgabri picture ahmedelgabri  Â·  3Comments

sandric picture sandric  Â·  3Comments