Create a gist now

Instantly share code, notes, and snippets.

@issm /gist:1071501
Last active Sep 26, 2015

What would you like to do?
function hs () {
local n_hist_default=1000000
local colors; colors=(32 33 34 35 36 31)
local n_hist=${1#-}
if [ ! "$1" = "" -a ! $n_hist = $1 ]; then
shift
if [ $n_hist -gt 0 ]; then
else
n_hist=$n_hist_default
fi
else
n_hist=$n_hist_default
fi
local words; words=($*)
local greps
local grep
local color
local i=0
for w in $words; do
if [ $i -lt $#colors[@] ]; then;
i=$(expr $i + 1)
fi
if [ "$HS_NOCOLOR" = "1" ]; then
grep="grep --color=no \"${w}\""
else
color=$colors[$i]
grep="GREP_COLOR=\"01;$color\" grep \"${w}\""
fi
greps="${greps} | ${grep}"
done
cmd="\history -${n_hist} ${greps}"
eval $cmd
}
function hspeco() {
local n_hist=${1#-}
if [ ! "$1" = "" -a ! $n_hist = $1 ]; then
shift
fi
HS_NOCOLOR=1 hs "$n_hist" $* | peco --query "$*" | sed -E 's/^[0-9]+[ ]+//g'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment