mirror of
https://github.com/wting/autojump
synced 2024-10-27 20:34:07 +00:00
parent
2c999dca83
commit
8ab23c01c4
25
bin/autojump
25
bin/autojump
@ -47,7 +47,7 @@ from autojump_data import save
|
|||||||
from autojump_utils import decode
|
from autojump_utils import decode
|
||||||
from autojump_utils import encode_local
|
from autojump_utils import encode_local
|
||||||
from autojump_utils import first
|
from autojump_utils import first
|
||||||
from autojump_utils import get_tab_needle_and_path
|
from autojump_utils import get_tab_entry_info
|
||||||
from autojump_utils import get_pwd
|
from autojump_utils import get_pwd
|
||||||
from autojump_utils import has_uppercase
|
from autojump_utils import has_uppercase
|
||||||
from autojump_utils import is_osx
|
from autojump_utils import is_osx
|
||||||
@ -185,11 +185,14 @@ def handle_tab_completion(needle, entries):
|
|||||||
if not needle:
|
if not needle:
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
tab_needle, path = get_tab_needle_and_path(needle, TAB_SEPARATOR)
|
tab_needle, tab_index, tab_path = get_tab_entry_info(needle, TAB_SEPARATOR)
|
||||||
|
|
||||||
if path:
|
if tab_path:
|
||||||
# found complete tab completion entry
|
print(encode_local(tab_path))
|
||||||
print(encode_local(path))
|
elif tab_index:
|
||||||
|
get_ith_path = lambda i, iterable: last(take(i, iterable)).path
|
||||||
|
print(encode_local(
|
||||||
|
get_ith_path(tab_index, find_matches(entries, tab_needle))))
|
||||||
elif tab_needle:
|
elif tab_needle:
|
||||||
# found partial tab completion entry
|
# found partial tab completion entry
|
||||||
print_tab_menu(
|
print_tab_menu(
|
||||||
@ -363,11 +366,15 @@ def main(args):
|
|||||||
else:
|
else:
|
||||||
entries = entriefy(load(config))
|
entries = entriefy(load(config))
|
||||||
needles = sanitize(args.directory)
|
needles = sanitize(args.directory)
|
||||||
_, path = get_tab_needle_and_path(first(needles), TAB_SEPARATOR)
|
tab_needle, tab_index, tab_path = \
|
||||||
|
get_tab_entry_info(first(needles), TAB_SEPARATOR)
|
||||||
|
|
||||||
if path:
|
if tab_path:
|
||||||
# found complete tab completion entry
|
print(encode_local(tab_path))
|
||||||
print(encode_local(path))
|
elif tab_index:
|
||||||
|
get_ith_path = lambda i, iterable: last(take(i, iterable)).path
|
||||||
|
print(encode_local(
|
||||||
|
get_ith_path(tab_index, find_matches(entries, tab_needle))))
|
||||||
else:
|
else:
|
||||||
print(encode_local(first(find_matches(entries, needles)).path))
|
print(encode_local(first(find_matches(entries, needles)).path))
|
||||||
|
|
||||||
|
@ -59,28 +59,30 @@ def first(xs):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_tab_needle_and_path(tab_entry, separator):
|
def get_tab_entry_info(entry, separator):
|
||||||
"""
|
"""
|
||||||
Given a tab entry in the following format return the needle and path:
|
Given a tab entry in the following format return needle, index, and path:
|
||||||
|
|
||||||
[needle]__[index]__[path]
|
[needle]__[index]__[path]
|
||||||
"""
|
"""
|
||||||
match_needle = re.search(r'(.*?)' + separator, tab_entry)
|
needle, index, path = None, None, None
|
||||||
|
|
||||||
|
match_needle = re.search(r'(.*?)' + separator, entry)
|
||||||
|
match_index = re.search(separator + r'([0-9]{1})', entry)
|
||||||
match_path = re.search(
|
match_path = re.search(
|
||||||
separator + r'[0-9]{1}' + separator + r'(.*)',
|
separator + r'[0-9]{1}' + separator + r'(.*)',
|
||||||
tab_entry)
|
entry)
|
||||||
|
|
||||||
if match_needle:
|
if match_needle:
|
||||||
tab_needle = match_needle.group(1)
|
needle = match_needle.group(1)
|
||||||
else:
|
|
||||||
tab_needle = None
|
if match_index:
|
||||||
|
index = int(match_index.group(1))
|
||||||
|
|
||||||
if match_path:
|
if match_path:
|
||||||
path = match_path.group(1)
|
path = match_path.group(1)
|
||||||
else:
|
|
||||||
path = None
|
|
||||||
|
|
||||||
return tab_needle, path
|
return needle, index, path
|
||||||
|
|
||||||
|
|
||||||
def get_pwd():
|
def get_pwd():
|
||||||
|
Loading…
Reference in New Issue
Block a user