Commit 550f2a37 authored by adam j hartz's avatar adam j hartz

bookmark: allow writing bookmarks to disk

parent e6f28118
# Bookmark Plugin
# remember directories within a session, quickly move between them
# TODO: support for persistent bookmarks
# remember directories and quickly move between them
import os
import json
PLUGIN_SETTINGS.data = {}
......@@ -28,7 +27,34 @@ def _follow_bookmark(args, stdin=None):
return None, 'Error: unknown bookmark %r\n' % args[0], 1
else:
$TAKO_SETTINGS.aliases['cd']([PLUGIN_SETTINGS.data[args[0]]], stdin=None)
def _write_bookmarks(args, stdin=None):
if len(args) > 1:
return None, 'Error: too many arguments\n', 1
if len(args) == 1:
fname = args[1]
else:
fname = os.path.join($TAKO_SETTINGS.data_dir, 'plugins', 'bookmark', 'bookmarks.json')
os.makedirs(os.path.dirname(fname), exist_ok=True)
to_write = {k:v for k,v in PLUGIN_SETTINGS.data.items() if not k.startswith('_')}
with open(fname, 'w') as f:
json.dump(to_write, f)
def _load_bookmarks(args, stdin=None):
if len(args) > 1:
return None, 'Error: too many arguments\n', 1
if len(args) == 1:
fname = args[1]
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)
PLUGIN_SETTINGS.aliases['bmark'] = _add_bookmark
PLUGIN_SETTINGS.aliases['bgo'] = _follow_bookmark
PLUGIN_SETTINGS.aliases['bwrite'] = _write_bookmarks
PLUGIN_SETTINGS.aliases['bload'] = _load_bookmarks
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