- (dir,name) = os.path.split(lastword)
- #log('\ncompleter: %r %r %r\n' % (qtype, lastword, text))
- try:
- n = pwd.resolve(dir)
- subs = list(filter(lambda x: x.name.startswith(name),
- n.subs()))
- except vfs.NoSuchFile, e:
- subs = []
- return (dir, name, qtype, lastword, subs)
-
-
-def find_readline_lib():
- """Return the name (and possibly the full path) of the readline library
- linked to the given readline module.
- """
- import readline
- f = open(readline.__file__, "rb")
- try:
- data = f.read()
- finally:
- f.close()
- import re
- m = re.search('\0([^\0]*libreadline[^\0]*)\0', data)
- if m:
- return m.group(1)
- return None
-
-
-def init_readline_vars():
- """Work around trailing space automatically inserted by readline.
- See http://bugs.python.org/issue5833"""
- try:
- import ctypes
- except ImportError:
- # python before 2.5 didn't have the ctypes module; but those
- # old systems probably also didn't have this readline bug, so
- # just ignore it.
- return
- lib_name = find_readline_lib()
- if lib_name is not None:
- lib = ctypes.cdll.LoadLibrary(lib_name)
- global rl_completion_suppress_append
- rl_completion_suppress_append = ctypes.c_int.in_dll(lib,
- "rl_completion_suppress_append")
+ dir, name = os.path.split(lastword.encode('iso-8859-1'))
+ dir_path = vfs.resolve(repo, dir or b'/')
+ _, dir_item = dir_path[-1]
+ if not dir_item:
+ subs = tuple()
+ else:
+ subs = tuple(dir_path + (entry,)
+ for entry in vfs.contents(repo, dir_item)
+ if (entry[0] != b'.' and entry[0].startswith(name)))
+ return qtype, lastword, subs