Fzf: Avoid duplicate entry when fzf-ing shell history

Created on 15 Jun 2016  路  8Comments  路  Source: junegunn/fzf

  • Category

    • [X] fzf binary

    • [ ] fzf-tmux script

    • [ ] Key bindings

    • [ ] Completion

    • [ ] Vim

    • [ ] Neovim

    • [ ] Etc.

  • Shell

    • [ ] bash

    • [X] zsh

    • [ ] fish

I would like to know if it's possible to limit the duplication in fzf specially in the shell history command? Or maybe I'm do it it wrong?

capture d ecran 2016-06-15 a 09 40 39

duplicate question

Most helpful comment

Using setopt HIST_IGNORE_ALL_DUPS on zsh did the trick in my case.

All 8 comments

Hi, this is one of the recurring questions. Please see #49, #88, #492. Thanks.

Thanks @junegunn and sorry for the duplicate

For other people encoutering this issue, here is the changes I've made to remove duplicates :

``` __fzf_history__() { local line countskip="$(history | tail -n 1 | grep -E '^[0-9]+' -o | wc -c)" countskip="$(( countskip + 1 ))" line=$( HISTTIMEFORMAT= history | grep '.\{1,79\}' | sed 's/ *$//g' | tac | nauniq --skip-chars="$countskip" | tac | $(__fzfcmd) +s --tac +m -n2..,.. --tiebreak=index --toggle-sort=ctrl-r | \grep '^ *[0-9]') && sed 's/ *\([0-9]*\)\** .*/!\1/' <<< "$line" }

It requires nanuniq https://metacpan.org/pod/distribution/App-nauniq/bin/nauniq
``````

perl -ne 'print if !$seen{$_}++' should do.

Using setopt HIST_IGNORE_ALL_DUPS on zsh did the trick in my case.

There are rare, desperate, cases, where I appreciate to browse through the history, in order to reconstruct something.

On ZSH one might use HIST_FIND_NO_DUPS to suppress duplicates in the search. Dups still get written to history, as opposed to HIST_IGNORE_ALL_DUPS.

if you're using ZSH, put this in your ~/.zsh file -

export HISTFILE=~/.zsh_history
export HISTFILESIZE=1000000000
export HISTSIZE=1000000000
setopt INC_APPEND_HISTORY
export HISTTIMEFORMAT="[%F %T] "
setopt EXTENDED_HISTORY
setopt HIST_FIND_NO_DUPS
setopt HIST_IGNORE_ALL_DUPS

Look here for a better explanation

I wanted the same feature (removing repeated lines after fzf filtering) and wrote this small Rust program to satisfy my need: semiuniq. The program removes repeated lines by scanning a window of user-specified fixed size over the input in a single pass without sorting. I'd appreciate comments and pull requests. cc/ #49, #88, #492.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

leonklingele picture leonklingele  路  3Comments

olethanh picture olethanh  路  3Comments

aleclarson picture aleclarson  路  3Comments

jberglinds picture jberglinds  路  3Comments

alistaircolling picture alistaircolling  路  3Comments