LoginSignup
40
52

More than 5 years have passed since last update.

【peco】たった4つの設定で最高の環境を手に入れる

Posted at

pecoを使い続けて早1年。
pecoを使うと、さまざまな場面でインクリメンタルサーチベースでコマンドを実行することができます。

あまりに便利なので、pecoを絡めたコマンドを毎日のように使っています。
この1年でいろんな使い方をしてみましたが、最終的に4つに集約されました。

ということで、毎日のように利用している4つのコマンドを紹介してみる。

環境

OS: macOS High Sierra
ターミナル: iTerm2
シェル: Zsh  ※ インストールは $ brew install zsh

【Histroy】検索

とにかくオススメ。通常の履歴検索にはもう戻れない。

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

select-history.gif

ghq】Gitリポジトリにcd

シェル起動 → 「g」 の安定の流れ。

.zshrc
alias g='cd $(ghq root)/$(ghq list | peco)'

ghq.gif

Git】ブランチ切り替え

増えがちなローカルブランチに一瞬で切り替えれる。

.zshrc
alias -g lb='`git branch | peco --prompt "GIT BRANCH>" | head -n 1 | sed -e "s/^\*\s*//g"`'

git-co-lb.gif

Docker】コンテナ内に入る

docker ps でコンテナ名調べて...コピーして...みたいなのがなくなり最高。

.zshrc
alias dps='docker ps --format "{{.ID}}\t{{.Image}}\t{{.Status}}\t{{.Command}}\t{{.RunningFor}}"'
alias de='docker exec -it `dps | peco | cut -f 1` /bin/bash'

docker-ps.gif

40
52
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
40
52