From 4237861abae93f4ffdd2ebf5d17fc56ad17dda20 Mon Sep 17 00:00:00 2001 From: William Ting Date: Sun, 24 Feb 2013 23:45:22 -0600 Subject: [PATCH] v21.5.0: add --increase and --decrease options to manually change weight. --- bin/autojump | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/bin/autojump b/bin/autojump index f8fd5ef..cf3f6b7 100755 --- a/bin/autojump +++ b/bin/autojump @@ -34,7 +34,7 @@ import re import shutil from tempfile import NamedTemporaryFile -VERSION = 'release-v21.4.6' +VERSION = 'release-v21.5.0' MAX_KEYWEIGHT = 1000 MAX_STORED_PATHS = 1000 COMPLETION_SEPARATOR = '__' @@ -83,22 +83,24 @@ class Database: 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: self.data[path] = increment else: 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() - 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: - import math - self.data[path] = math.sqrt((self.data[path] ** 2) - (increment ** 2)) + if self.data[path] < increment: + self.data[path] = 0 + else: + self.data[path] -= increment self.save() def decay(self): @@ -232,8 +234,8 @@ def options(): help='directory to jump to') parser.add_argument('-a', '--add', '--increase', metavar='DIR', help='manually add path to database, or increase path weight for existing paths') - parser.add_argument('-d', '--decrease', metavar='DIR', - help='manually decrease path weight in the database') + parser.add_argument('-d', '--decrease', nargs='?', type=int, const=15, default=False, + help='manually decrease path weight in database') parser.add_argument('-b', '--bash', action="store_true", default=False, help='enclose directory quotes to prevent errors') parser.add_argument('--complete', action="store_true", default=False, @@ -257,7 +259,8 @@ def options(): if (ARGS.decrease): if(ARGS.decrease != os.path.expanduser("~")): db = Database(DB_FILE) - db.decrease(ARGS.decrease) + # FIXME: handle symlinks? + db.decrease(os.getcwd(), ARGS.decrease) return True if (ARGS.purge):