Last active
September 26, 2015 08:48
-
-
Save issm/1071501 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
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