Minor fix to vimium script

This commit is contained in:
Akemi Izuko 2022-10-15 18:18:55 -06:00
parent e2a504f3f1
commit ad6e75e451
No known key found for this signature in database
GPG key ID: 905D444F6A5E4BE4
2 changed files with 77 additions and 78 deletions

View file

@ -2,99 +2,98 @@
import json, argparse, os
from pathlib import Path
if __name__ == '__main__':
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();
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)
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)
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')
output = open(args.output_file, mode='w')
def writeln(string: str):
output.write(string + '\n')
def writeln(string: str):
output.write(string + '\n')
# Heading ====
writeln("# Vimium's options backup")
writeln(f"""\
# Heading ====
writeln("# Vimium's options backup")
writeln(f"""\
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)
""")
# Save keys ====
writeln("## Excluded URLs and keys")
# Save keys ====
writeln("## Excluded URLs and keys")
left_width = len(max([p['pattern'] for p in j["exclusionRules"]], key=len));
title = "Patterns"
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("```")
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("```")
# 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("```")
# 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")
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")
# 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("```")
# 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```")
# CSS ====
writeln("\n# Vimium CSS")
writeln("```css")
for line in j['userDefinedLinkHintCss'].split('\n'):
writeln(line.strip())
writeln("\n```")
writeln("")
output.close()
writeln("")
output.close()

View file

@ -22,7 +22,7 @@ set hidden
au BufWritePre [:;']* throw 'Forbidden file name: ' . expand('<afile>')
" Embedded code in markdown
let g:markdown_fenced_languages = ['bash', 'rust', 'javascript', 'c', 'toml']
let g:markdown_fenced_languages = ['bash', 'rust', 'javascript', 'c', 'toml', 'css']
" ===================================================================
" Human-facing settings