Commit 13be6df8 authored by Jeremy Kaplan's avatar Jeremy Kaplan

Fix bugs with loading/reading nonexistent/empty bookmark files

parent ee5e0821
......@@ -84,14 +84,15 @@ def _load_bookmarks(args, stdin=None):
else:
fname = os.path.join($TAKO_SETTINGS.data_dir, 'plugins', 'bookmark', 'bookmarks.json')
os.makedirs(os.path.dirname(fname), exist_ok=True)
with open(fname) as f:
PLUGIN_SETTINGS.data = json.load(f)
if os.path.isfile(fname):
with open(fname) as f:
PLUGIN_SETTINGS.data = json.load(f)
def _list_bookmarks(args, stdin=None):
if len(args) > 0:
return None, _LIST_USAGE, 1
leftside_len = max(len(i) for i in PLUGIN_SETTINGS.data) + 3
leftside_len = max(len(i) for i in PLUGIN_SETTINGS.data, default=0) + 3
out = ''
for k, v in sorted(PLUGIN_SETTINGS.data.items()):
out += '%s \033[0;36m%s\033[0m %s\n' % (k, '.' * (leftside_len-len(k)), v)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment