2022-10-15 16:33:13 -06:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import json, argparse, os
|
|
|
|
from pathlib import Path
|
|
|
|
|
2022-10-15 18:18:55 -06:00
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description="Convert vimium's json config file to markdown");
|
|
|
|
parser.add_argument('vimium_options', type=Path,
|
|
|
|
help='File generated by "Click to download backup"');
|
|
|
|
parser.add_argument('output_file', type=Path,
|
|
|
|
help='Markdown file generated');
|
|
|
|
args = parser.parse_args();
|
|
|
|
|
|
|
|
try:
|
|
|
|
with open(args.vimium_options, mode='r') as vimium_json:
|
|
|
|
j = json.load(vimium_json)
|
|
|
|
except FileNotFoundError:
|
|
|
|
print(f"`{args.vimium_options}` does not exist")
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
if os.path.isfile(args.output_file):
|
|
|
|
print(f"File `{args.output_file}` already exists. "
|
|
|
|
"Refusing to overwrite");
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
output = open(args.output_file, mode='w')
|
|
|
|
|
|
|
|
def writeln(string: str):
|
|
|
|
output.write(string + '\n')
|
|
|
|
|
|
|
|
# Heading ====
|
|
|
|
writeln("# Vimium's options backup")
|
|
|
|
writeln(f"""\
|
2022-10-15 16:33:13 -06:00
|
|
|
This is a markdown render of vimium's options version {j['settingsVersion']}. Copy/pasting them
|
|
|
|
into vimium should work with future versions too. Storing them as a markdown
|
|
|
|
file is better for version control (git and codeberg)
|
|
|
|
""")
|
|
|
|
|
2022-10-15 18:18:55 -06:00
|
|
|
# Save keys ====
|
|
|
|
writeln("## Excluded URLs and keys")
|
|
|
|
|
|
|
|
left_width = len(max([p['pattern'] for p in j["exclusionRules"]], key=len));
|
|
|
|
title = "Patterns"
|
|
|
|
|
|
|
|
writeln("```")
|
|
|
|
writeln(f"{title:{left_width}} Excluded keys")
|
|
|
|
for rule in j["exclusionRules"]:
|
|
|
|
writeln(f"{rule['pattern']:{left_width}} ::{(' ' + rule['passKeys']).strip()}")
|
|
|
|
writeln("```")
|
|
|
|
|
|
|
|
# Key mappings ====
|
|
|
|
writeln("\n## Custom key mappings")
|
|
|
|
writeln("Quotes are comments, just like in vimscript\n")
|
|
|
|
writeln("```")
|
|
|
|
for key in j['keyMappings'].split('\n'):
|
|
|
|
writeln(key)
|
|
|
|
writeln("```")
|
|
|
|
|
|
|
|
# Seach engines ====
|
|
|
|
writeln("\n## Custom search engines")
|
|
|
|
writeln("These get activated through \"o\". Hashes are comments\n")
|
|
|
|
writeln("```")
|
|
|
|
for engine in j['searchEngines'].split('\n'):
|
|
|
|
writeln(engine)
|
|
|
|
writeln("```")
|
|
|
|
|
|
|
|
writeln("\n# Advanced options")
|
|
|
|
|
|
|
|
# Checkbox options ====
|
|
|
|
writeln("\n## Miscellaneous options")
|
|
|
|
b = lambda x: "Check" if x else "Blank";
|
|
|
|
writeln("```")
|
|
|
|
writeln(f"{b(j['smoothScroll']):5} :: Use smooth scrolling")
|
|
|
|
writeln(f"{b(j['filterLinkHints']):5} :: Use link characters for link-hint filtering")
|
|
|
|
writeln(f"{b(j['grabBackFocus']):5} :: Don't let pages steal focus on load")
|
|
|
|
writeln(f"{b(j['hideHud']):5} :: Hide Heads Up Display in insert mode")
|
|
|
|
writeln(f"{b(j['regexFindMode']):5} :: Treat queries are JS regex expressions")
|
|
|
|
writeln(f"{b(j['ignoreKeyboardLayout']):5} :: Ignore keyboard layout")
|
|
|
|
writeln("```\n")
|
|
|
|
|
|
|
|
# More stuff ====
|
|
|
|
writeln("\n## More advanced options")
|
|
|
|
writeln("```")
|
|
|
|
writeln(f" Scroll step size: {j['scrollStepSize']}px")
|
|
|
|
writeln(f"Characters used for link hints: {j['linkHintCharacters']}")
|
|
|
|
writeln(f" Previous patterns: {j['previousPatterns']}")
|
|
|
|
writeln(f" Next patterns: {j['nextPatterns']}")
|
|
|
|
writeln(f" New tab URL: {j['newTabUrl']}")
|
|
|
|
writeln(f" Default search engine: {j['searchUrl']}")
|
|
|
|
writeln("```")
|
|
|
|
|
|
|
|
# CSS ====
|
|
|
|
writeln("\n# Vimium CSS")
|
|
|
|
writeln("```css")
|
|
|
|
for line in j['userDefinedLinkHintCss'].split('\n'):
|
|
|
|
writeln(line.strip())
|
|
|
|
writeln("\n```")
|
|
|
|
|
|
|
|
writeln("")
|
|
|
|
output.close()
|