Don't check path existence when displaying tab completion menu.

The check is to avoided since tab menu paths may be on slow IO devices (network
mounts, low power devices, etc).

Closes #258.
pull/262/head
William Ting 11 years ago
parent 1f045c2658
commit 681068a2bc

@ -160,32 +160,40 @@ def detect_smartcase(needles):
return not any(imap(has_uppercase, needles)) return not any(imap(has_uppercase, needles))
def find_matches(entries, needles): def find_matches(entries, needles, check_entries=True):
"""Return an iterator to matching entries.""" """Return an iterator to matching entries."""
ignore_case = detect_smartcase(needles)
try: try:
os.getcwdu() pwd = os.getcwdu()
not_cwd = lambda entry: entry.path != os.getcwdu()
except OSError: except OSError:
# tautology if current working directory no longer exists pwd = None
not_cwd = lambda _: True
# using closure and comparing vs string to prevent constantly hitting hdd
def not_cwd(entry):
return entry.path != pwd
if check_entries:
exists = lambda entry: os.path.exists(entry.path)
else:
exists = lambda _: True
data = sorted( data = sorted(
ifilter(not_cwd, entries), entries,
key=attrgetter('weight'), key=attrgetter('weight'),
reverse=True) reverse=True)
ignore_case = detect_smartcase(needles)
exists = lambda entry: os.path.exists(entry.path)
return ifilter( return ifilter(
exists, not_cwd,
chain( ifilter(
match_consecutive(needles, data, ignore_case), exists,
match_fuzzy(needles, data, ignore_case), chain(
match_anywhere(needles, data, ignore_case), match_consecutive(needles, data, ignore_case),
# default return value so calling shell functions have an match_fuzzy(needles, data, ignore_case),
# argument to `cd` to match_anywhere(needles, data, ignore_case),
[Entry('.', 0)])) # default return value so calling shell functions have an
# argument to `cd` to
[Entry('.', 0)])))
def handle_tab_completion(needle, entries): def handle_tab_completion(needle, entries):
@ -198,17 +206,25 @@ def handle_tab_completion(needle, entries):
print_local(tab_path) print_local(tab_path)
elif tab_index: elif tab_index:
get_ith_path = lambda i, iterable: last(take(i, iterable)).path get_ith_path = lambda i, iterable: last(take(i, iterable)).path
print_local(get_ith_path(tab_index, find_matches(entries, tab_needle))) print_local(get_ith_path(
tab_index,
find_matches(entries, tab_needle, check_entries=False)))
elif tab_needle: elif tab_needle:
# found partial tab completion entry # found partial tab completion entry
print_tab_menu( print_tab_menu(
tab_needle, tab_needle,
take(TAB_ENTRIES_COUNT, find_matches(entries, tab_needle)), take(TAB_ENTRIES_COUNT, find_matches(
entries,
tab_needle,
check_entries=False)),
TAB_SEPARATOR) TAB_SEPARATOR)
else: else:
print_tab_menu( print_tab_menu(
needle, needle,
take(TAB_ENTRIES_COUNT, find_matches(entries, needle)), take(TAB_ENTRIES_COUNT, find_matches(
entries,
needle,
check_entries=False)),
TAB_SEPARATOR) TAB_SEPARATOR)

Loading…
Cancel
Save