Basically I want to type show and it checks if there is a show command or alias is defined and fire it and it is not defined fires git show.
For example rm should do rm but checkout should do git checkout.
Is it possible to program this in bashrc?
This is surprisingly easy:
This runs the usual
touchandrmcommands, but because there is noaddcommand it runsgit add fooand because there is nobranchcommand it runsgit branchThe trap command is run on any error, so not only when a command isn’t found. You would probably want to do something smarter e.g. run a script which checks whether
$?is 127 (the code bash sets when a command is not found) and then checks if running it with git instead would work (e.g. by checking for a command calledgit-xxxwherexxxis the first word of$BASH_COMMAND). I leave that as an exercise for the reader.