Skip to content

Any easy way to detect invoking of shortcuts, macros & aliases? #1369

Answered by kotfu
Sripadvallabh asked this question in Q&A
Discussion options

You must be logged in to vote

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:

  1. check the data passed into the hook and determine if the alias.macro has been applied
  2. do whatever logging you want

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 to
  • self.macros - contains a dictionary of all macros and what they exp…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@Sripadvallabh
Comment options

Comment options

You must be logged in to vote
1 reply
@Sripadvallabh
Comment options

Answer selected by Sripadvallabh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants