rapid7/metasploit-framework — pull request #707 by kernelsmith (2012-08-20 05:41:59+00:00)
Title: adds command aliasing to msfconsole (and tab completion of aliases), ver 4

see commit history for details, but adds the 'alias' command to msfconsole.
Some other changes:
adds alias (cmd_alias) to core.rb
basically anything can be aliased using -f, except a few safe words like rm -rf and msfconsole, additionally an alias can't have the name alias otherwise a user could end up in a state where one cannot unalias an overaliased core command like 'set'.

Aliases will tab complete, and the alias command will tab complete with any loaded command or current alias (you can also alias an alias)
adds @Aliases to core, accessed via an attr_reader and changed via the cmd_alias method
adds @allow_aliases, accessed via an attr_reader and set as a protected attr_writer by initialization and defangedness
allow_aliases follows the same relationship that command_passthru has

in order to allow cmd_alias to verify valid aliases, some changes were made to dispatcher_shell:
is_valid_dispatcher_command? was added which can search all or a specified dispatcher and has an option for whether to search deprecated commands. This provides the basis for
get_responding_dispatcher, which was also added. As a result, run_single was simplified by updating it to use get_responding_dispatcher. Possibly some other code could be updated with these methods, but I didn't want to go too nuts.

Updated after some comments from egypt. Old PRs were #637, 675, 697.
#697 was closed because I noticed a flaw where tab-completion of aliases did not behave exactly the same as the raw command. E.g., if 'show' was aliased as 'muestra', and you entered 'muestra ' you would not be presented with the exact same options as when you ran 'show '. Also, AliasTranslateOnTab is now a datastore option which toggles whether an alias is translated to it's alias value when the alias is tab completed. So using the muestra alias above, if AliasTranslateOnTab is true and you run 'muestra ' your command line will be updated to 'show ', but it won't if AliasTranslateOnTab is false (default behavior)

This is super handy (see http://pastebin.com/rrS06amv) and can even be used to "translate" msfconsole commands into other (ASCII-based) languages (see http://pastebin.com/tMYWwSGH)