From 3eb4aafeb49218e0a6d051d4b16e25b561d1b84b Mon Sep 17 00:00:00 2001 From: PHO Date: Wed, 11 Sep 2013 16:24:36 +0900 Subject: [PATCH] Auto commit by The Sugar System. --- dot-files/_zshrc | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/dot-files/_zshrc b/dot-files/_zshrc index 2472a04..603cdd2 100644 --- a/dot-files/_zshrc +++ b/dot-files/_zshrc @@ -127,6 +127,53 @@ function print_directory_info() { fi } +function ppgrep() { + local -a percol_opts + + if [[ $# -gt 0 ]]; then + percol_opts=("--query" "$1") + fi + + ps aux | percol "${percol_opts[@]}" | awk '{ print $2 }' +} + +function ppkill() { + local -a ppgrep_opts + + if [[ $1 =~ "^[^-]" ]]; then + ppgrep_opts=("$1") + shift + fi + + ppgrep "${ppgrep_opts[@]}" | xargs kill "$@" +} + +function percol_select_history() { + local -a tac_cmd + + if which gtac >&/dev/null; then + tac_cmd=("gtac") + elif which tac >&/dev/null; then + tac_cmd=("tac") + else + tac_cmd=("cat") + fi + + BUFFER=$("${tac_cmd[@]}" "$HISTFILE" | \ + sed 's/^: [0-9]*:[0-9]*;//' | \ + percol --match-method regex --query "$LBUFFER") + CURSOR=$#BUFFER # move cursor to the end of line + zle redisplay + + if [[ -n $BUFFER ]]; then + zle accept-line + fi +} +if which percol >&/dev/null; then + zle -N percol_select_history + bindkey '^R' percol_select_history +fi + HISTFILE="$HOME/.zhistory" HISTSIZE=6000000 SAVEHIST=6000000 -- 2.40.0