Skip to content

Instantly share code, notes, and snippets.

@yaasita
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yaasita/e2347049ea35d2adf31c to your computer and use it in GitHub Desktop.
Save yaasita/e2347049ea35d2adf31c to your computer and use it in GitHub Desktop.
if type percol &>/dev/null
then
[ ! -e ~/.cd_history ] && pwd > ~/.cd_history
function _percol_log_delete {
local log=/tmp/percol-log
if [ -e $log ];then
\rm $log
fi
}
_replace_by_history() {
local line=$(HISTTIMEFORMAT= history | tac | \
perl -nle 's/^\s*\d+\s+//;print if ++$hash{$_}<2' | \
percol --query "$READLINE_LINE")
READLINE_LINE="$line"
READLINE_POINT=${#line}
_percol_log_delete
}
bind -x '"\C-x": _replace_by_history'
function cd {
builtin cd "$@" || return 1
local max_line=500
(perl -i -nle "exit if \$.>$max_line - 1;print '$PWD' if \$.==1;print if !m#^$PWD\$#" ~/.cd_history &) 2>/dev/null
}
function c {
local line=$(cat ~/.cd_history | percol )
cd "$line"
_percol_log_delete
}
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment