Last active
August 29, 2015 14:02
-
-
Save yaasita/e2347049ea35d2adf31c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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