mirror of
https://github.com/wting/autojump
synced 2024-10-27 20:34:07 +00:00
switch to unicode literals
This commit is contained in:
parent
a82db2762d
commit
5838226923
71
bin/autojump
71
bin/autojump
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
from __future__ import division
|
from __future__ import division
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import collections
|
import collections
|
||||||
import difflib
|
import difflib
|
||||||
@ -194,10 +195,6 @@ class Database:
|
|||||||
self.save()
|
self.save()
|
||||||
return removed
|
return removed
|
||||||
|
|
||||||
#
|
|
||||||
# Environment Functions
|
|
||||||
#
|
|
||||||
|
|
||||||
def config_defaults():
|
def config_defaults():
|
||||||
config = {}
|
config = {}
|
||||||
|
|
||||||
@ -301,7 +298,7 @@ def parse_args():
|
|||||||
|
|
||||||
if len(removed):
|
if len(removed):
|
||||||
for dir in removed:
|
for dir in removed:
|
||||||
output(dir)
|
print(dir)
|
||||||
|
|
||||||
print("Number of database entries removed: %d" % len(removed))
|
print("Number of database entries removed: %d" % len(removed))
|
||||||
|
|
||||||
@ -310,7 +307,7 @@ def parse_args():
|
|||||||
if args.stat:
|
if args.stat:
|
||||||
for path, weight in sorted(db.data.items(),
|
for path, weight in sorted(db.data.items(),
|
||||||
key=operator.itemgetter(1))[-100:]:
|
key=operator.itemgetter(1))[-100:]:
|
||||||
output("%.1f:\t%s" % (weight, path))
|
print("%.1f:\t%s" % (weight, path))
|
||||||
|
|
||||||
print("________________________________________\n")
|
print("________________________________________\n")
|
||||||
print("%d:\t total key weight" % sum(db.data.values()))
|
print("%d:\t total key weight" % sum(db.data.values()))
|
||||||
@ -327,57 +324,11 @@ def parse_args():
|
|||||||
config['args'] = args
|
config['args'] = args
|
||||||
return config
|
return config
|
||||||
|
|
||||||
#
|
def surround_quotes(config, text):
|
||||||
# Utilities
|
|
||||||
#
|
|
||||||
|
|
||||||
def is_python2():
|
|
||||||
return sys.version_info[0] == 2
|
|
||||||
|
|
||||||
def decode(text, encoding=None, errors='strict'):
|
|
||||||
"""
|
|
||||||
Decoding step for Python 2 which does not default to unicode.
|
|
||||||
"""
|
|
||||||
if is_python2():
|
|
||||||
if not encoding:
|
|
||||||
encoding = sys.getfilesystemencoding()
|
|
||||||
return text.decode(encoding, errors)
|
|
||||||
else:
|
|
||||||
return text
|
|
||||||
|
|
||||||
def unico(text):
|
|
||||||
"""
|
|
||||||
If Python 2, convert to a unicode object.
|
|
||||||
"""
|
|
||||||
if is_python2():
|
|
||||||
return unicode(text)
|
|
||||||
else:
|
|
||||||
return text
|
|
||||||
|
|
||||||
def output(text, encoding=None):
|
|
||||||
"""
|
|
||||||
Wrapper for the print function, using the filesystem encoding by default
|
|
||||||
to minimize encoding mismatch problems in directory names.
|
|
||||||
"""
|
|
||||||
if is_python2():
|
|
||||||
if not encoding:
|
|
||||||
encoding = sys.getfilesystemencoding()
|
|
||||||
print(unicode(text).encode(encoding))
|
|
||||||
else:
|
|
||||||
print(text)
|
|
||||||
|
|
||||||
def output_quotes(config, text):
|
|
||||||
quotes = ""
|
|
||||||
if config['args'].complete and config['args'].bash:
|
if config['args'].complete and config['args'].bash:
|
||||||
quotes = "'"
|
return "'%s'" % text
|
||||||
|
else:
|
||||||
result = "%s%s%s" % (quotes, text, quotes)
|
return text
|
||||||
output(result)
|
|
||||||
return result
|
|
||||||
|
|
||||||
#
|
|
||||||
# Main Logic
|
|
||||||
#
|
|
||||||
|
|
||||||
def match(path, pattern, only_end=False, ignore_case=False):
|
def match(path, pattern, only_end=False, ignore_case=False):
|
||||||
"""
|
"""
|
||||||
@ -521,13 +472,13 @@ def main():
|
|||||||
fuzzy=True)
|
fuzzy=True)
|
||||||
|
|
||||||
if tab_choice and len(results) > (tab_choice-1):
|
if tab_choice and len(results) > (tab_choice-1):
|
||||||
output_quotes(config, results[tab_choice-1])
|
print(surround_quotes(config, results[tab_choice-1]))
|
||||||
elif len(results) > 1 and config['args'].complete:
|
elif len(results) > 1 and config['args'].complete:
|
||||||
for n, r in enumerate(results[:9]):
|
for n, r in enumerate(results[:9]):
|
||||||
output_quotes(config, '%s%s%d%s%s' %
|
print(surround_quotes(config, '%s%s%d%s%s' %
|
||||||
(patterns[-1], sep, n+1, sep, r))
|
(patterns[-1], sep, n+1, sep, r)))
|
||||||
elif results:
|
elif results:
|
||||||
output_quotes(config, results[0])
|
print(surround_quotes(config, results[0]))
|
||||||
else:
|
else:
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user