parent
2ab43f264f
commit
e67dc42f02
13
completer.py
13
completer.py
|
@ -51,12 +51,7 @@ class Completer(object):
|
|||
class FileCompleter(Completer):
|
||||
def get_candidates(self, s, w=None):
|
||||
s = util.expand_tilde(s)
|
||||
if s.startswith('~'):
|
||||
users = ['~%s' % (x[0]) for x in pwd.getpwall()]
|
||||
candidates = [util.expand_tilde(user) for user in users if user.startswith(s)]
|
||||
else:
|
||||
candidates = glob.glob(s + '*')
|
||||
candidates = [util.normal_path(p) for p in candidates]
|
||||
candidates = [util.normal_path(p) for p in glob.glob(s + '*')]
|
||||
|
||||
# ignore some suffixes by default, unless the only possible completions
|
||||
# ALL have ignored-suffixes, in which case just return them all.
|
||||
|
@ -69,13 +64,9 @@ class FileCompleter(Completer):
|
|||
break
|
||||
if ok:
|
||||
candidates2.append(c)
|
||||
|
||||
if candidates2:
|
||||
candidates = candidates2
|
||||
|
||||
for i in range(0, len(candidates)):
|
||||
c = candidates[i]
|
||||
if os.path.isdir(os.path.realpath(c)):
|
||||
candidates[i] = c + '/'
|
||||
return candidates
|
||||
|
||||
class BufferCompleter(Completer):
|
||||
|
|
|
@ -31,8 +31,7 @@ def current_working_dir(w):
|
|||
|
||||
def path_dirname(w):
|
||||
if hasattr(w.buffer, 'path'):
|
||||
path = os.path.dirname(w.buffer.path)
|
||||
return util.normal_path(path) + '/'
|
||||
return util.normal_path(os.path.dirname(w.buffer.path))
|
||||
else:
|
||||
return current_working_dir(w)
|
||||
|
||||
|
|
3
util.py
3
util.py
|
@ -3,9 +3,10 @@ import os, pwd, regex
|
|||
def normal_path(path):
|
||||
path = os.path.realpath(path)
|
||||
home = os.getenv('HOME')
|
||||
isdir = os.path.isdir(path)
|
||||
if path.startswith(home):
|
||||
path = path.replace(home, '~', 1)
|
||||
if os.path.isdir(path):
|
||||
if isdir and not path.endswith('/'):
|
||||
return path + '/'
|
||||
else:
|
||||
return path
|
||||
|
|
Loading…
Reference in New Issue