I'm not sure what you specifically ask is possible. However, if you are ready to solve your problem in a different way. Every day I use a tool that can do what you ask for, or at least as close as I think you can get.
SSMS Tools Pack is a plugin for SQL Server Management Studio that has a number or really great features. You may be interested in the history of the current window. This is a window with all the commands that were launched from this tab. Although he does not do what you originally requested, I feel that this is at least in the spirit of what you were trying to accomplish.

source share