Based on @salutis's answer I created a script which I called comp and stored in ~/bin/comp that searches commands', aliases, and builtins, (option flag -cab see the bash man entry), with an optional second parameter which, if present, pipes the output to grep and searches for the second parameter.
Usage: comp string [keyword-for-grep]
Code:
#!/bin/bash
if [ -z "$1" ]; then
echo usage: comp string [keyword-for-grep]
echo
exit
fi
if [ -z "$2" ]; then
compgen -cab -- $1
exit
fi
compgen -cab -- $1 | grep -i $2
Personally I would also be interested in figuring out a way to remove the last command from the shell history in the script (something related to history -d) so that when searching bash history I won't find comp entries. I know I can also do this with HISTIGNORE but linux is pretty powerful so there must be a way to do it from the script file, too - right?
grepregex?(y or n or g[rep])? I hate to sound pessimistic, but I doubt this could be done without adding it to the bash code. – Kevin Nov 3 '11 at 17:41