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