Any easy way to detect invoking of shortcuts, macros & aliases? #1369
-
I wanted to check the number of times a shortcut or alias or macro was invoked as opposed to the command itself. Is there an easy way to do it? Currently i feel using a hook & checking the data.statement values:
But there is no straightforward way to detect if its a macro or shortcut or alias that was invoked. May i know if this is possible. I just want to have some statistics on how the commands are invoked in general. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Off-hand, I don't think we built in any easy way to detect this as we intend them to be fully equivalent. We have always been completely agnostic when it comes to how end users choose to do logging and metrics. |
Beta Was this translation helpful? Give feedback.
-
I think you are on the right track, but you'll have to write a little bit of code in your hook. I'd suggest you utilize a precommand hook. The precommand hook will be called by
For step 1, you may find the following
In your hook you can check if |
Beta Was this translation helpful? Give feedback.
I think you are on the right track, but you'll have to write a little bit of code in your hook.
I'd suggest you utilize a precommand hook. The precommand hook will be called by
cmd2
after the user input has been parsed (and the aliases expanded), but before the command is executed. In that hook, you'll have to write a bit of code, which will do two things:For step 1, you may find the following
cmd2
instance variables to be useful:self.aliases
- contains a dictionary of all aliases and what they expand toself.macros
- contains a dictionary of all macros and what they exp…