[IPython-user] Custom command completers implemented in SVN

John Hunter jdhunter at ace.bsd.uchicago.edu
Tue Oct 31 13:52:21 CST 2006


>>>>> "John" == John Hunter <jdhunter at ace.bsd.uchicago.edu> writes:

    John> and Voila!

    John> ...very nice...

Oh boy, this is fun

import os, glob
def listdirs(self, event):
    cd, relpath = event['line'].split(' ', 1)
    if relpath.startswith('~'):
        relpath = os.path.expanduser(relpath)
    return [f for f in  glob.glob(relpath+'*') if os.path.isdir(f)]

ip.set_hook('complete_command', listdirs, re_key = 'cd .*')

def runlistpy(self, event):
    relpath = event['line'].split(' ')[-1]
    if relpath.startswith('~'):
        relpath = os.path.expanduser(relpath)
    dirs = [f for f in  glob.glob(relpath+'*') if os.path.isdir(f)]
    pys =  [f for f in  glob.glob(relpath+'*.py')]
    return dirs + pys

ip.set_hook('complete_command', runlistpy, re_key = 'run .*')        


More information about the IPython-user mailing list