6
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

zsh + peco-select-histroy でhistoryをユニークにする

Last updated at Posted at 2014-12-16

update: 同じことをしている方がいて、そちらのほうが優秀なので、下記参照


巷に公開されている peco-select-history だと、同じコマンドの履歴が沢山表示されて不便なので、ユニークに表示されるようにした。
ユニークにしたときに、順番が崩れないようにソートしなおしてる。

function peco-select-history() {
    BUFFER=$(\history 1 | \
                    sort -r -k 2 |\
                    uniq -1 | \
                    sort -r | \
                    awk '$1=$1' | \
                    cut -d" " -f 2- | \
                    peco --query "$LBUFFER")
    CURSOR=$#BUFFER
    zle clear-screen
}
zle -N peco-select-history
bindkey '^r' peco-select-history
6
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?