1
r""" %which magic command
3
%which <cmd> => search PATH for files matching PATH. Also scans aliases
8
ip = IPython.ipapi.get()
11
from fnmatch import fnmatch
13
fullpath = filter(os.path.isdir,os.environ['PATH'].split(os.pathsep))
15
if '.' not in fullpath:
16
fullpath = ['.'] + fullpath
19
for f in os.listdir(p):
20
head, ext = os.path.splitext(f)
21
if f == fn or fnmatch(head, fn):
22
yield os.path.join(p,f)
25
def which_alias(fname):
26
for al, tgt in ip.IP.alias_table.items():
27
if not (al == fname or fnmatch(al, fname)):
30
print "Callable alias",tgt
33
print "Docstring:\n",d
37
trans = ip.expand_alias(trg)
38
cmd = trans.split(None,1)[0]
40
for realcmd in which(cmd):
43
def which_f(self, arg):
44
r""" %which <cmd> => search PATH for files matching cmd. Also scans aliases.
46
Traverses PATH and prints all files (not just executables!) that match the
47
pattern on command line. Probably more useful in finding stuff
48
interactively than 'which', which only prints the first matching item.
50
Also discovers and expands aliases, so you'll see what will be executed
51
when you call an alias.
56
d -> ls -F --color=auto
57
== c:\cygwin\bin\ls.exe
62
== c:\cygwin\bin\diff3.exe
64
== c:\cygwin\bin\diff.exe
65
c:\cygwin\bin\diff.exe
66
c:\cygwin\bin\diff3.exe
75
ip.expose_magic("which",which_f)