Skip to content

Instantly share code, notes, and snippets.

@issm
Last active September 26, 2015 08:48
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 issm/1071501 to your computer and use it in GitHub Desktop.
Save issm/1071501 to your computer and use it in GitHub Desktop.
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