mirror of
https://github.com/wting/autojump
synced 2024-10-27 20:34:07 +00:00
remove unused imports, minor formatting cleanup
This commit is contained in:
parent
1c8a4c13cd
commit
80a3f0da4d
3
Makefile
3
Makefile
@ -13,6 +13,9 @@ docs:
|
||||
pandoc -s -w man docs/manpage_header.md docs/header.md docs/body.md -o docs/autojump.1
|
||||
pandoc -s -w markdown docs/header.md docs/install.md docs/development.md docs/body.md -o README.md
|
||||
|
||||
lint:
|
||||
flake8 ./
|
||||
|
||||
release: docs
|
||||
# Check for tag existence
|
||||
# git describe release-$(VERSION) 2>&1 >/dev/null || exit 1
|
||||
|
17
bin/autojump
17
bin/autojump
@ -22,13 +22,11 @@
|
||||
from __future__ import print_function
|
||||
|
||||
from difflib import SequenceMatcher
|
||||
from functools import partial
|
||||
from itertools import chain
|
||||
from math import sqrt
|
||||
from operator import attrgetter
|
||||
from operator import itemgetter
|
||||
import os
|
||||
import platform
|
||||
import re
|
||||
import sys
|
||||
|
||||
@ -61,7 +59,6 @@ from utils import last
|
||||
from utils import print_entry
|
||||
from utils import print_tab_menu
|
||||
from utils import sanitize
|
||||
from utils import second
|
||||
from utils import surround_quotes
|
||||
from utils import take
|
||||
|
||||
@ -142,7 +139,7 @@ def add_path(data, path, increment=10):
|
||||
return data, Entry(path, 0)
|
||||
|
||||
if path in data:
|
||||
data[path] = sqrt((data[path]**2) + (increment**2))
|
||||
data[path] = sqrt((data[path] ** 2) + (increment ** 2))
|
||||
else:
|
||||
data[path] = increment
|
||||
|
||||
@ -152,7 +149,7 @@ def add_path(data, path, increment=10):
|
||||
def decrease_path(data, path, increment=15):
|
||||
"""Decrease weight of existing path."""
|
||||
path = decode(path).rstrip(os.sep)
|
||||
data[path] = max(0, data[path]-increment)
|
||||
data[path] = max(0, data[path] - increment)
|
||||
return data, Entry(path, data[path])
|
||||
|
||||
|
||||
@ -212,7 +209,10 @@ def match_anywhere(needles, haystack, ignore_case=False):
|
||||
"""
|
||||
regex_needle = '.*' + '.*'.join(needles) + '.*'
|
||||
regex_flags = re.IGNORECASE | re.UNICODE if ignore_case else re.UNICODE
|
||||
found = lambda haystack: re.search(regex_needle, haystack.path, flags=regex_flags)
|
||||
found = lambda haystack: re.search(
|
||||
regex_needle,
|
||||
haystack.path,
|
||||
flags=regex_flags)
|
||||
return ifilter(found, haystack)
|
||||
|
||||
|
||||
@ -289,8 +289,7 @@ def match_fuzzy(needles, haystack, ignore_case=False):
|
||||
match_percent = lambda entry: SequenceMatcher(
|
||||
a=needle,
|
||||
b=end_dir(entry.path)).ratio()
|
||||
meets_threshold = lambda entry: match_percent(entry) \
|
||||
>= FUZZY_MATCH_THRESHOLD
|
||||
meets_threshold = lambda entry: match_percent(entry) >= FUZZY_MATCH_THRESHOLD
|
||||
return ifilter(meets_threshold, haystack)
|
||||
|
||||
|
||||
@ -344,7 +343,7 @@ def main(args):
|
||||
old_data = load(config)
|
||||
new_data = dictify(purge_missing_paths(entriefy(old_data)))
|
||||
save(config, new_data)
|
||||
print("Purged %d entries." % (len(old_data)-len(new_data)))
|
||||
print("Purged %d entries." % (len(old_data) - len(new_data)))
|
||||
elif args.stat:
|
||||
print_stats(load(config), config['data_path'])
|
||||
else:
|
||||
|
@ -4,7 +4,6 @@ from __future__ import print_function
|
||||
|
||||
from codecs import open
|
||||
from collections import namedtuple
|
||||
from operator import itemgetter
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
@ -68,8 +67,12 @@ def load(config):
|
||||
tupleize = lambda x: (x[1], float(x[0]))
|
||||
|
||||
try:
|
||||
with open(config['data_path'], 'r', encoding='utf-8', errors='replace') as f:
|
||||
return dict(imap(tupleize, ifilter(correct_length, imap(parse, f))))
|
||||
with open(
|
||||
config['data_path'],
|
||||
'r', encoding='utf-8',
|
||||
errors='replace') as f:
|
||||
return dict(
|
||||
imap(tupleize, ifilter(correct_length, imap(parse, f))))
|
||||
except (IOError, EOFError):
|
||||
return load_backup(config)
|
||||
|
||||
|
21
bin/utils.py
21
bin/utils.py
@ -3,7 +3,6 @@
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
from collections import Iterable
|
||||
import errno
|
||||
from itertools import islice
|
||||
import os
|
||||
@ -14,11 +13,9 @@ import sys
|
||||
import unicodedata
|
||||
|
||||
if sys.version_info[0] == 3:
|
||||
ifilter = filter
|
||||
imap = map
|
||||
os.getcwdu = os.getcwd
|
||||
else:
|
||||
from itertools import ifilter
|
||||
from itertools import imap
|
||||
|
||||
|
||||
@ -68,7 +65,7 @@ def get_needle(tab_entry, separator):
|
||||
|
||||
[needle]__
|
||||
"""
|
||||
return re.match(r'(.*)'+separator, tab_entry).group(1)
|
||||
return re.match(r'(.*)' + separator, tab_entry).group(1)
|
||||
|
||||
|
||||
def get_needle_and_index(tab_entry, separator):
|
||||
@ -78,9 +75,9 @@ def get_needle_and_index(tab_entry, separator):
|
||||
[needle]__[index]__[possible_match]
|
||||
"""
|
||||
matches = re.search(
|
||||
r'(.*)' + \
|
||||
separator + \
|
||||
r'([0-9]{1})' + \
|
||||
r'(.*)' +
|
||||
separator +
|
||||
r'([0-9]{1})' +
|
||||
separator, tab_entry)
|
||||
return matches.group(1), int(matches.group(2))
|
||||
|
||||
@ -126,15 +123,15 @@ def is_tab_entry(needle, separator):
|
||||
[needle]__[index]__[possible_match]
|
||||
"""
|
||||
pattern = re.compile(
|
||||
'.*' + \
|
||||
separator + \
|
||||
'[0-9]{1}' + \
|
||||
'.*' +
|
||||
separator +
|
||||
'[0-9]{1}' +
|
||||
separator)
|
||||
return re.search(pattern, needle)
|
||||
|
||||
|
||||
def is_tab_partial_match(needle, separator):
|
||||
return re.match(r'(.*)'+separator, needle)
|
||||
return re.match(r'(.*)' + separator, needle)
|
||||
|
||||
|
||||
def is_windows():
|
||||
@ -186,7 +183,7 @@ def print_tab_menu(needle, tab_entries, separator):
|
||||
'%s%s%d%s%s' % (
|
||||
needle,
|
||||
separator,
|
||||
i+1,
|
||||
i + 1,
|
||||
separator,
|
||||
entry.path))))
|
||||
|
||||
|
@ -4,27 +4,31 @@ IPython autojump magic
|
||||
Written by keith hughitt <keith.hughitt@gmail.com>, based on an earlier
|
||||
version by Mario Pastorelli <pastorelli.mario@gmail.com>.
|
||||
|
||||
To install, `create a new IPython user profile <http://ipython.org/ipython-doc/stable/config/ipython.html#configuring-ipython>`_
|
||||
if you have not already done so by running:
|
||||
To install, create a new IPython user profile by running:
|
||||
|
||||
ipython profile create
|
||||
|
||||
And copy this file into the "startup" folder of your new profile (e.g.
|
||||
And copy this file into the "startup" folder of your new profile (e.g.
|
||||
"$HOME/.config/ipython/profile_default/startup/").
|
||||
|
||||
@TODO: extend %cd to call "autojump -a"
|
||||
"""
|
||||
import os
|
||||
import subprocess as sub
|
||||
from IPython.core.magic import (register_line_magic, register_cell_magic,
|
||||
register_line_cell_magic)
|
||||
from subprocess import Popen
|
||||
from subprocess import PIPE
|
||||
|
||||
from IPython.core.magic import register_line_magic
|
||||
|
||||
ip = get_ipython()
|
||||
|
||||
|
||||
@register_line_magic
|
||||
def j(path):
|
||||
cmd = ['autojump'] + path.split()
|
||||
newpath = sub.Popen(cmd, stdout=sub.PIPE, shell=False).communicate()[0].strip()
|
||||
newpath = Popen(
|
||||
cmd,
|
||||
stdout=PIPE,
|
||||
shell=False).communicate()[0].strip()
|
||||
|
||||
if newpath:
|
||||
ip.magic('cd %s' % newpath.decode('utf-8'))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user