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:
parent
b8901586cb
commit
4237861aba
21
bin/autojump
21
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,7 +83,7 @@ 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
|
||||
@ -92,13 +92,15 @@ class Database:
|
||||
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):
|
||||
|
Loading…
Reference in New Issue
Block a user