+
+function nfgrep() {
+ fgrep --with-filename --line-number --context=1 --colour=always "$@" | $PAGER
+}
+
+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 find_tac_command() {
+ if which gtac >&/dev/null; then
+ echo "gtac"
+ elif which tac >&/dev/null; then
+ echo "tac"
+ else
+ echo "tail -r"
+ fi
+}
+
+function percol_select_history() {
+ local -a tac_cmd
+ tac_cmd=($(find_tac_command))
+
+ local selected
+ selected=$("${tac_cmd[@]}" "$HISTFILE" | \
+ sed 's/^: [0-9]*:[0-9]*;//' | \
+ awk 'seen[$0] {next} {seen[$0]++; print}' | \
+ percol --match-method regex --query "$LBUFFER")
+
+ if [[ $? -eq 0 ]]; then
+ BUFFER="$selected"
+ CURSOR="$#BUFFER" # move cursor to the end of line
+ zle redisplay
+ #zle accept-line # uncomment this to execute the selected one immediately.
+ else
+ zle redisplay
+ fi
+}
+if which percol >&/dev/null; then
+ zle -N percol_select_history
+ bindkey '^R' percol_select_history
+fi