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
|
||||
|
11
bin/autojump
11
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
|
||||
|
||||
@ -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)
|
||||
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
15
bin/utils.py
15
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
|
||||
|
||||
|
||||
@ -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,9 +123,9 @@ 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)
|
||||
|
||||
|
@ -4,8 +4,7 @@ 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
|
||||
|
||||
@ -14,17 +13,22 @@ And copy this file into the "startup" folder of your new profile (e.g.
|
||||
|
||||
@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