From e67dc42f0201d9e78ce69ac80ec45d1a12a997c0 Mon Sep 17 00:00:00 2001 From: moculus Date: Wed, 10 Dec 2008 05:54:53 +0000 Subject: [PATCH] better filename completion --HG-- branch : pmacs2 --- completer.py | 13 ++----------- default.py | 3 +-- util.py | 3 ++- 3 files changed, 5 insertions(+), 14 deletions(-) diff --git a/completer.py b/completer.py index 402675a..ce9ef3c 100644 --- a/completer.py +++ b/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): diff --git a/default.py b/default.py index f2b59b9..22826da 100644 --- a/default.py +++ b/default.py @@ -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) diff --git a/util.py b/util.py index 983252e..41bfc29 100644 --- a/util.py +++ b/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