Been messing around with some of the internals of PyCmd again, and I ended yo setting up a way to register hooks at a few different parts of the runtime cycle from init.py. Right now, I have it set up so that the init.py can register a hook at initialization (though in hindsight, that's probably not really necessary since any necessary initialization can easily be handled in init.py itself), during the main loop (in run_cmd, to be exact), and at tab completion.
For instance, hooking into the main_loop:
def print_tokens(cmd, args):
print cmd, args
return (False, (cmd, args))
So with that in my init.py, running ls --color=always would look like this:
[PyCmd]$ ls --color=always
ANSI32.dll init.py pycmd_public.py
custom_commands.py old.rar pycmd_public.pyc
custom_commands.pyo PyCmd.exe pycmd_public.pyo
A hook registered with the type MAIN_HOOK excepts a a return of a tuple containing either (handled, (cmd, args)) or (handled, None) with handled being whether or not the hook handled execution of the cmd. (if True, run_cmd would then return) (cmd, args) is only needed if the hook wants to modify the original cmd and args specified. If no modification is necessary, that can simple be None.
I did it so that I could implement linux-style aliases, so that I could do stuff like:
[PyCmd]$ alias -p
[PyCmd]$ gitcl git://pycmd.git.sourceforge.net/gitroot/pycmd/pycmd pycmd
Cloning into pycmd...
remote: Counting objects: 511, done.
remote: Compressing objects: 100% (507/507), done.
remote: Total 511 (delta 328), reused 0 (delta 0)Receiving objects: 36% (184/511)
Receiving objects: 100% (511/511), 143.97 KiB, done.
Resolving deltas: 100% (328/328), done.
Doesn't really conform to cmd.exe compatibility, so I understand if it wont work. Anyways, if you're interested, I'll need to remove a couple of other things I've been messing around with, and then I'll attach a patch here.
Log in to post a comment.