LoginSignup
75
66

More than 5 years have passed since last update.

oh-my-zsh の環境で、peco-select-history が動かない

Last updated at Posted at 2014-07-03

Pecoを導入してzshのhistoryに使うようにした
http://blog.kenjiskywalker.org/blog/2014/06/12/peco/

こちらの記事などで紹介されている peco-select-history が、
oh-my-zsh を使っている環境下だと動かなかった。

原因は、history -n 1 の部分で、以下のようなエラーが出るため。

$ history -n 1
fc: event not found: -n

oh-my-zsh の設定で history コマンドが fc コマンドに alias 設定されているらしい。
https://github.com/robbyrussell/oh-my-zsh/issues/739

以下のように、historyの前にバックスラッシュを追記した。
(@syohexさんと@hisaichi5518さんにこの方法を教えていただきました。ありがとうございます!)

~/.zshrc
function peco-select-history() {
    local tac
    if which tac > /dev/null; then
        tac="tac"
    else
        tac="tail -r"
    fi
    BUFFER=$(\history -n 1 | \
        eval $tac | \
        peco --query "$LBUFFER")
    CURSOR=$#BUFFER
    zle clear-screen
}
zle -N peco-select-history
bindkey '^r' peco-select-history

これで、無事に peco-select-history が使用できるようになった。

75
66
2

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
75
66