Skip to content

Instantly share code, notes, and snippets.

@qinshulei
Forked from fideloper/h.sh
Last active August 29, 2015 14:15
Show Gist options
  • Save qinshulei/c786c766cd14cbdaab1b to your computer and use it in GitHub Desktop.
Save qinshulei/c786c766cd14cbdaab1b to your computer and use it in GitHub Desktop.
improve history command with grep and percol
#! /bin/bash
function show_usage {
cat <<- _EOF_
Search Bash History using Grep and Percol
Examples:
$ h ssh
$ h 'ssh user@'
_EOF_
exit 1
}
#Sanity check - Need one argument
if [ $# -ne 1 ]; then
show_usage
fi
#If bash_history doesn't exist
if [ -f ~/.zsh_history ]; then
cat ~/.zsh_history | grep $1 | percol
elif [ -f ~/.bash_history ]; then
cat ~/.zsh_history | grep $1 | percol
else
show_usage
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment