You need zsh and peco.
peco/peco: Simplistic interactive filtering tool
Put below script to your ~/.zsh
and source it.
incremental-select-command-history() {
if [ ! $(which peco) ]; then echo "You need peco" && exit 1; fi
local original_buffer="$BUFFER"
BUFFER=$( \
history 1 | \
sort -k1,1nr | \
perl -ne 'BEGIN { my @lines = (); } s/^\s*\d+\*?\s*//; $in=$_; if (!(grep {$in eq $_} @lines)) { push(@lines, $in); print $in; }' | \
peco --layout=bottom-up --on-cancel=error
)
# Keep original input when escape from select
if [ -z "$BUFFER" ]; then
BUFFER="$original_buffer"
fi
CURSOR=${#BUFFER}
}
zle -N incremental-select-command-history
bindkey '^[[A' incremental-select-command-history
- Push up arrow key and start incremental search
- Keep original input when incremental search canceled ( with Esc key )
- Select some command to input string to your console and hit Enter one more time to execute command.
So comfortable.
- zsh 5.5.1 (x86_64-apple-darwin17.5.0)
- peco version v0.5.1
- Mac OS X High sierra