mirror of
https://github.com/wting/autojump
synced 2024-10-27 20:34:07 +00:00
separate --increase from --add, print out directory weights, don't add home directory to database
This commit is contained in:
parent
fcd7465ed8
commit
96a2206931
56
bin/autojump
56
bin/autojump
@ -57,6 +57,9 @@ class Database:
|
|||||||
"""
|
"""
|
||||||
Increase weight of existing paths or initialize new ones to 10.
|
Increase weight of existing paths or initialize new ones to 10.
|
||||||
"""
|
"""
|
||||||
|
if path == self.config['home']:
|
||||||
|
return
|
||||||
|
|
||||||
path = path.rstrip(os.sep)
|
path = path.rstrip(os.sep)
|
||||||
|
|
||||||
if self.data[path]:
|
if self.data[path]:
|
||||||
@ -70,6 +73,9 @@ class Database:
|
|||||||
"""
|
"""
|
||||||
Decrease weight of existing path. Unknown ones are ignored.
|
Decrease weight of existing path. Unknown ones are ignored.
|
||||||
"""
|
"""
|
||||||
|
if path == self.config['home']:
|
||||||
|
return
|
||||||
|
|
||||||
if self.data[path] < increment:
|
if self.data[path] < increment:
|
||||||
self.data[path] = 0
|
self.data[path] = 0
|
||||||
else:
|
else:
|
||||||
@ -205,32 +211,30 @@ class Database:
|
|||||||
def set_defaults():
|
def set_defaults():
|
||||||
config = {}
|
config = {}
|
||||||
|
|
||||||
config['version'] = 'release-v21.6.0'
|
config['version'] = 'release-v21.6.1'
|
||||||
config['max_weight'] = 1000
|
config['max_weight'] = 1000
|
||||||
config['max_paths'] = 1000
|
config['max_paths'] = 1000
|
||||||
config['separator'] = '__'
|
config['separator'] = '__'
|
||||||
|
config['home'] = os.path.expanduser('HOME')
|
||||||
|
|
||||||
config['ignore_case'] = False
|
config['ignore_case'] = False
|
||||||
config['keep_entries'] = False
|
config['keep_entries'] = False
|
||||||
config['keep_symlinks'] = False
|
config['keep_symlinks'] = False
|
||||||
config['debug'] = False
|
config['debug'] = False
|
||||||
|
|
||||||
home = os.path.expanduser('HOME')
|
|
||||||
xdg_data = os.environ.get('XDG_DATA_HOME') or \
|
xdg_data = os.environ.get('XDG_DATA_HOME') or \
|
||||||
os.path.join(home, '.local', 'share')
|
os.path.join(config['home'], '.local', 'share')
|
||||||
config['data'] = os.path.join(xdg_data, 'autojump')
|
config['data'] = os.path.join(xdg_data, 'autojump')
|
||||||
config['db'] = config['data'] + '/autojump.txt'
|
config['db'] = config['data'] + '/autojump.txt'
|
||||||
|
|
||||||
return config
|
return config
|
||||||
|
|
||||||
def parse_env(config):
|
def parse_env(config):
|
||||||
home = os.path.expanduser('HOME')
|
|
||||||
|
|
||||||
if 'AUTOJUMP_DATA_DIR' in os.environ:
|
if 'AUTOJUMP_DATA_DIR' in os.environ:
|
||||||
config['data'] = os.environ.get('AUTOJUMP_DATA_DIR')
|
config['data'] = os.environ.get('AUTOJUMP_DATA_DIR')
|
||||||
config['db'] = config['data'] + '/autojump.txt'
|
config['db'] = config['data'] + '/autojump.txt'
|
||||||
|
|
||||||
if config['data'] == home:
|
if config['data'] == config['home']:
|
||||||
config['db'] = config['data'] + '/.autojump.txt'
|
config['db'] = config['data'] + '/.autojump.txt'
|
||||||
|
|
||||||
if 'AUTOJUMP_KEEP_ALL_ENTRIES' in os.environ and \
|
if 'AUTOJUMP_KEEP_ALL_ENTRIES' in os.environ and \
|
||||||
@ -256,9 +260,12 @@ def parse_arg(config):
|
|||||||
'directory', metavar='DIRECTORY', nargs='*', default='',
|
'directory', metavar='DIRECTORY', nargs='*', default='',
|
||||||
help='directory to jump to')
|
help='directory to jump to')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-a', '--add', '--increase', metavar='DIRECTORY',
|
'-a', '--add', metavar='DIRECTORY',
|
||||||
help='manually add path to database, or increase path weight for \
|
help='manually add path to database')
|
||||||
existing paths')
|
parser.add_argument(
|
||||||
|
'-i', '--increase', metavar='WEIGHT', nargs='?', type=int,
|
||||||
|
const=20, default=False,
|
||||||
|
help='manually increase path weight in database')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-d', '--decrease', metavar='WEIGHT', nargs='?', type=int,
|
'-d', '--decrease', metavar='WEIGHT', nargs='?', type=int,
|
||||||
const=15, default=False,
|
const=15, default=False,
|
||||||
@ -282,19 +289,23 @@ def parse_arg(config):
|
|||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
db = Database(config)
|
db = Database(config)
|
||||||
|
|
||||||
if (args.add):
|
if args.add:
|
||||||
if (args.add != os.path.expanduser("~")):
|
|
||||||
db.add(decode(args.add))
|
db.add(decode(args.add))
|
||||||
|
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
if (args.decrease):
|
if args.increase:
|
||||||
if (args.decrease != os.path.expanduser("~")):
|
print("%.2f:\t old directory weight" % db.get_weight(os.getcwd()))
|
||||||
|
db.add(os.getcwd(), args.increase)
|
||||||
|
print("%.2f:\t new directory weight" % db.get_weight(os.getcwd()))
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
if args.decrease:
|
||||||
|
print("%.2f:\t old directory weight" % db.get_weight(os.getcwd()))
|
||||||
db.decrease(os.getcwd(), args.decrease)
|
db.decrease(os.getcwd(), args.decrease)
|
||||||
|
print("%.2f:\t new directory weight" % db.get_weight(os.getcwd()))
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
if (args.purge):
|
if args.purge:
|
||||||
removed = db.purge()
|
removed = db.purge()
|
||||||
|
|
||||||
if len(removed):
|
if len(removed):
|
||||||
@ -305,7 +316,7 @@ def parse_arg(config):
|
|||||||
|
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
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(unico("%.1f:\t%s") % (weight, path))
|
output(unico("%.1f:\t%s") % (weight, path))
|
||||||
@ -313,8 +324,9 @@ def parse_arg(config):
|
|||||||
print("________________________________________\n")
|
print("________________________________________\n")
|
||||||
print("%d:\t total key weight" % sum(db.data.values()))
|
print("%d:\t total key weight" % sum(db.data.values()))
|
||||||
print("%d:\t stored directories" % len(db.data))
|
print("%d:\t stored directories" % len(db.data))
|
||||||
print("db file: %s" % config['db'])
|
print("%.2f:\t current directory weight" % db.get_weight(os.getcwd()))
|
||||||
|
|
||||||
|
print("\ndb file: %s" % config['db'])
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
config['args'] = args
|
config['args'] = args
|
||||||
@ -352,17 +364,17 @@ def unico(text):
|
|||||||
else:
|
else:
|
||||||
return unicode(text)
|
return unicode(text)
|
||||||
|
|
||||||
def match_last(pattern):
|
def match_last(config, pattern):
|
||||||
"""
|
"""
|
||||||
If the last pattern contains a full path, jump there.
|
If the last pattern contains a full path, jump there.
|
||||||
The regexp is because we need to support stuff like
|
The regexp is because we need to support stuff like
|
||||||
"j wo jo__3__/home/joel/workspace/joel" for zsh.
|
"j wo jo__3__/home/joel/workspace/joel" for zsh.
|
||||||
"""
|
"""
|
||||||
last_pattern_path = re.sub("(.*)"+COMPLETION_SEPARATOR, "", pattern[-1])
|
last_pattern_path = re.sub("(.*)"+config['separator'], "", pattern[-1])
|
||||||
if (len(last_pattern_path) > 0 and
|
if (len(last_pattern_path) > 0 and
|
||||||
last_pattern_path[0] == "/" and
|
last_pattern_path[0] == "/" and
|
||||||
os.path.exists(last_pattern_path)):
|
os.path.exists(last_pattern_path)):
|
||||||
if not ARGS.complete:
|
if not config['args'].complete:
|
||||||
output(last_pattern_path)
|
output(last_pattern_path)
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
@ -476,7 +488,7 @@ def main():
|
|||||||
|
|
||||||
# check last pattern for full path
|
# check last pattern for full path
|
||||||
# FIXME: disabled until zsh tab completion is fixed on the shell side
|
# FIXME: disabled until zsh tab completion is fixed on the shell side
|
||||||
# if match_last(patterns):
|
# if match_last(config, patterns):
|
||||||
# return True
|
# return True
|
||||||
|
|
||||||
# check for tab completion
|
# check for tab completion
|
||||||
|
Loading…
Reference in New Issue
Block a user