13
15

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.

bash で peco を使っています

Last updated at Posted at 2014-08-22

peco-history

hisotry から検索して実行する。Ctrl+r にわりあてるといいかもしれない。

function peco-hist() {
    time_column=`echo $HISTTIMEFORMAT | awk '{printf("%s",NF)}'`
    column=`expr $time_column + 3`
    cmd=`history | tac | peco | sed -e 's/^ //' | sed -e 's/ +/ /g' | cut -d " " -f $column-`
    history -s "$cmd"
    eval $cmd
}

peco-kill

px aux から検索して kill する。
よく kill するし、pid を手で入力するのは怖いので便利なきがする。

function peco-kill(){
    proc=`ps aux | peco`
    pid=`echo "$proc" | awk '{print $2}'`
    echo "kill pid:$pid. [$proc]"
    kill $pid
}

peco git grep vi

git grep の結果から vi でそのファイルのその行を開く。

function peco-gvi(){
    # -n 行番号を表示
    result=$(git grep -n $1 | peco)
    # peco の戻り ( 複数行返ったときは知らない ) からファイルパスを取得
    file=$(echo $result | cut -d ":" -f 1)
    # 2カラム目の 行番号を取得
    linenumber=$(echo $result| cut -d ":" -f 2)
    # ファイルパスが空でなければ
    if [ $file != "" ]; then
        cmd="vi -c $linenumber $file"
        # history に履歴を追加して
        history -s $cmd
        # 行番号を指定して vi で開く
        $cmd
    fi
}
13
15
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
13
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?