1
0
mirror of https://github.com/wting/autojump synced 2024-10-27 20:34:07 +00:00

v21.5.0: add --increase and --decrease options to manually change weight.

This commit is contained in:
William Ting 2013-02-24 23:45:22 -06:00
parent b8901586cb
commit 4237861aba

View File

@ -34,7 +34,7 @@ import re
import shutil import shutil
from tempfile import NamedTemporaryFile from tempfile import NamedTemporaryFile
VERSION = 'release-v21.4.6' VERSION = 'release-v21.5.0'
MAX_KEYWEIGHT = 1000 MAX_KEYWEIGHT = 1000
MAX_STORED_PATHS = 1000 MAX_STORED_PATHS = 1000
COMPLETION_SEPARATOR = '__' COMPLETION_SEPARATOR = '__'
@ -83,22 +83,24 @@ class Database:
def add(self, path, increment = 10): def add(self, path, increment = 10):
""" """
Increase wheight of existing paths or initialize new ones to 10. Increase weight of existing paths or initialize new ones to 10.
""" """
if path not in self.data: if path not in self.data:
self.data[path] = increment self.data[path] = increment
else: else:
import math import math
self.data[path] = math.sqrt((self.data[path]**2)+(increment**2)) self.data[path] = math.sqrt((self.data[path]**2) + (increment**2))
self.save() self.save()
def decrease(self, path, increment=10): def decrease(self, path, increment = 15):
""" """
Decrease wheight of existing path. Unknown ones are ignored. Decrease weight of existing path. Unknown ones are ignored.
""" """
if path in self.data: if path in self.data:
import math if self.data[path] < increment:
self.data[path] = math.sqrt((self.data[path] ** 2) - (increment ** 2)) self.data[path] = 0
else:
self.data[path] -= increment
self.save() self.save()
def decay(self): def decay(self):
@ -232,8 +234,8 @@ def options():
help='directory to jump to') help='directory to jump to')
parser.add_argument('-a', '--add', '--increase', metavar='DIR', parser.add_argument('-a', '--add', '--increase', metavar='DIR',
help='manually add path to database, or increase path weight for existing paths') help='manually add path to database, or increase path weight for existing paths')
parser.add_argument('-d', '--decrease', metavar='DIR', parser.add_argument('-d', '--decrease', nargs='?', type=int, const=15, default=False,
help='manually decrease path weight in the database') help='manually decrease path weight in database')
parser.add_argument('-b', '--bash', action="store_true", default=False, parser.add_argument('-b', '--bash', action="store_true", default=False,
help='enclose directory quotes to prevent errors') help='enclose directory quotes to prevent errors')
parser.add_argument('--complete', action="store_true", default=False, parser.add_argument('--complete', action="store_true", default=False,
@ -257,7 +259,8 @@ def options():
if (ARGS.decrease): if (ARGS.decrease):
if(ARGS.decrease != os.path.expanduser("~")): if(ARGS.decrease != os.path.expanduser("~")):
db = Database(DB_FILE) db = Database(DB_FILE)
db.decrease(ARGS.decrease) # FIXME: handle symlinks?
db.decrease(os.getcwd(), ARGS.decrease)
return True return True
if (ARGS.purge): if (ARGS.purge):