mirror of
https://github.com/wting/autojump
synced 2024-10-27 20:34:07 +00:00
minor comments cleanup
This commit is contained in:
parent
24d8ccb48e
commit
616596c0dc
25
bin/autojump
25
bin/autojump
@ -90,9 +90,6 @@ def set_defaults():
|
|||||||
|
|
||||||
|
|
||||||
def parse_arguments():
|
def parse_arguments():
|
||||||
"""
|
|
||||||
Evaluate arguments and run appropriate logic, returning an error code.
|
|
||||||
"""
|
|
||||||
parser = ArgumentParser(
|
parser = ArgumentParser(
|
||||||
description='Automatically jump to directory passed as an \
|
description='Automatically jump to directory passed as an \
|
||||||
argument.',
|
argument.',
|
||||||
@ -127,30 +124,27 @@ def parse_arguments():
|
|||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
def add_path(data, path, increment=10):
|
def add_path(data, path, weight=10):
|
||||||
"""
|
"""
|
||||||
Add a new path or increment an existing one.
|
Add a new path or increment an existing one.
|
||||||
|
|
||||||
os.path.realpath() is not used because users prefer to have short,
|
os.path.realpath() is not used because it's preferable to use symlinks
|
||||||
symlinked paths with duplicate entries in the database than a single
|
with resulting duplicate entries in the database than a single canonical
|
||||||
canonical path.
|
path.
|
||||||
"""
|
"""
|
||||||
path = decode(path).rstrip(os.sep)
|
path = decode(path).rstrip(os.sep)
|
||||||
if path == os.path.expanduser('~'):
|
if path == os.path.expanduser('~'):
|
||||||
return data, Entry(path, 0)
|
return data, Entry(path, 0)
|
||||||
|
|
||||||
if path in data:
|
data[path] = sqrt((data.get(path, 0) ** 2) + (weight ** 2))
|
||||||
data[path] = sqrt((data[path] ** 2) + (increment ** 2))
|
|
||||||
else:
|
|
||||||
data[path] = increment
|
|
||||||
|
|
||||||
return data, Entry(path, data[path])
|
return data, Entry(path, data[path])
|
||||||
|
|
||||||
|
|
||||||
def decrease_path(data, path, increment=15):
|
def decrease_path(data, path, weight=15):
|
||||||
"""Decrease weight of existing path."""
|
"""Decrease or zero out a path."""
|
||||||
path = decode(path).rstrip(os.sep)
|
path = decode(path).rstrip(os.sep)
|
||||||
data[path] = max(0, data[path] - increment)
|
data[path] = max(0, data.get(path, 0) - weight)
|
||||||
return data, Entry(path, data[path])
|
return data, Entry(path, data[path])
|
||||||
|
|
||||||
|
|
||||||
@ -170,7 +164,6 @@ def find_matches(entries, needles):
|
|||||||
# tautology if current working directory no longer exists
|
# tautology if current working directory no longer exists
|
||||||
not_cwd = lambda x: True
|
not_cwd = lambda x: True
|
||||||
|
|
||||||
# from pprint import pprint as pp; import pdb; pdb.set_trace()
|
|
||||||
data = sorted(
|
data = sorted(
|
||||||
ifilter(not_cwd, entries),
|
ifilter(not_cwd, entries),
|
||||||
key=attrgetter('weight'),
|
key=attrgetter('weight'),
|
||||||
@ -293,7 +286,7 @@ def match_fuzzy(needles, haystack, ignore_case=False):
|
|||||||
(path="/foo/baz", weight=10),
|
(path="/foo/baz", weight=10),
|
||||||
(path="/foo/bar", weight=10)]
|
(path="/foo/bar", weight=10)]
|
||||||
|
|
||||||
This is a weak heuristic and be used as a last resort to find matches.
|
This is a weak heuristic and used as a last resort to find matches.
|
||||||
"""
|
"""
|
||||||
end_dir = lambda path: last(os.path.split(path))
|
end_dir = lambda path: last(os.path.split(path))
|
||||||
if ignore_case:
|
if ignore_case:
|
||||||
|
Loading…
Reference in New Issue
Block a user