I have a lot of aliases and functions in my terminal, in addition to the plethora of UNIX commands. If I’m not sure what the source of a command is, getting info on it can require multiple tries. First a
man check, then a
alias command to see if it’s custom, then a
man -k to see if I misspelled something, and so on. I eventually decided to just write an automated way to sift through those possibilities.
The function below will simply check if the command exists, then flip through “file,” “function,” and “alias” to see what kind it is, displaying the man page, typing out the function, or showing the alias depending on the result. It really just combines the
type functionality into one command.
The only switch is
-k, which will show the results of
man -k if no matching command is found.
I have this running with a modified version of bash-completion that scopes in the
halp command for tab-completing command names. Easy hack, so I won’t elaborate on that.
where? tool is also a handy companion to this if you have enough custom scripts and sourced files to make it useful.
Ryan Irelan has produced a series of shell trick videos based on BrettTerpstra.com posts. Readers can get 10% off using the coupon code