Minor fix to vimium script
This commit is contained in:
parent
99afad720c
commit
fb892470cb
|
@ -2,99 +2,98 @@
|
||||||
import json, argparse, os
|
import json, argparse, os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
if __name__ == '__main__':
|
parser = argparse.ArgumentParser(
|
||||||
parser = argparse.ArgumentParser(
|
description="Convert vimium's json config file to markdown");
|
||||||
description="Convert vimium's json config file to markdown");
|
parser.add_argument('vimium_options', type=Path,
|
||||||
parser.add_argument('vimium_options', type=Path,
|
help='File generated by "Click to download backup"');
|
||||||
help='File generated by "Click to download backup"');
|
parser.add_argument('output_file', type=Path,
|
||||||
parser.add_argument('output_file', type=Path,
|
help='Markdown file generated');
|
||||||
help='Markdown file generated');
|
args = parser.parse_args();
|
||||||
args = parser.parse_args();
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(args.vimium_options, mode='r') as vimium_json:
|
with open(args.vimium_options, mode='r') as vimium_json:
|
||||||
j = json.load(vimium_json)
|
j = json.load(vimium_json)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
print(f"`{args.vimium_options}` does not exist")
|
print(f"`{args.vimium_options}` does not exist")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
if os.path.isfile(args.output_file):
|
if os.path.isfile(args.output_file):
|
||||||
print(f"File `{args.output_file}` already exists. "
|
print(f"File `{args.output_file}` already exists. "
|
||||||
"Refusing to overwrite");
|
"Refusing to overwrite");
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
output = open(args.output_file, mode='w')
|
output = open(args.output_file, mode='w')
|
||||||
|
|
||||||
def writeln(string: str):
|
def writeln(string: str):
|
||||||
output.write(string + '\n')
|
output.write(string + '\n')
|
||||||
|
|
||||||
# Heading ====
|
# Heading ====
|
||||||
writeln("# Vimium's options backup")
|
writeln("# Vimium's options backup")
|
||||||
writeln(f"""\
|
writeln(f"""\
|
||||||
This is a markdown render of vimium's options version {j['settingsVersion']}. Copy/pasting them
|
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
|
into vimium should work with future versions too. Storing them as a markdown
|
||||||
file is better for version control (git and codeberg)
|
file is better for version control (git and codeberg)
|
||||||
""")
|
""")
|
||||||
|
|
||||||
# Save keys ====
|
# Save keys ====
|
||||||
writeln("## Excluded URLs and keys")
|
writeln("## Excluded URLs and keys")
|
||||||
|
|
||||||
left_width = len(max([p['pattern'] for p in j["exclusionRules"]], key=len));
|
left_width = len(max([p['pattern'] for p in j["exclusionRules"]], key=len));
|
||||||
title = "Patterns"
|
title = "Patterns"
|
||||||
|
|
||||||
writeln("```")
|
writeln("```")
|
||||||
writeln(f"{title:{left_width}} Excluded keys")
|
writeln(f"{title:{left_width}} Excluded keys")
|
||||||
for rule in j["exclusionRules"]:
|
for rule in j["exclusionRules"]:
|
||||||
writeln(f"{rule['pattern']:{left_width}} ::{(' ' + rule['passKeys']).strip()}")
|
writeln(f"{rule['pattern']:{left_width}} ::{(' ' + rule['passKeys']).strip()}")
|
||||||
writeln("```")
|
writeln("```")
|
||||||
|
|
||||||
# Key mappings ====
|
# Key mappings ====
|
||||||
writeln("\n## Custom key mappings")
|
writeln("\n## Custom key mappings")
|
||||||
writeln("Quotes are comments, just like in vimscript\n")
|
writeln("Quotes are comments, just like in vimscript\n")
|
||||||
writeln("```")
|
writeln("```")
|
||||||
for key in j['keyMappings'].split('\n'):
|
for key in j['keyMappings'].split('\n'):
|
||||||
writeln(key)
|
writeln(key)
|
||||||
writeln("```")
|
writeln("```")
|
||||||
|
|
||||||
# Seach engines ====
|
# Seach engines ====
|
||||||
writeln("\n## Custom search engines")
|
writeln("\n## Custom search engines")
|
||||||
writeln("These get activated through \"o\". Hashes are comments\n")
|
writeln("These get activated through \"o\". Hashes are comments\n")
|
||||||
writeln("```")
|
writeln("```")
|
||||||
for engine in j['searchEngines'].split('\n'):
|
for engine in j['searchEngines'].split('\n'):
|
||||||
writeln(engine)
|
writeln(engine)
|
||||||
writeln("```")
|
writeln("```")
|
||||||
|
|
||||||
writeln("\n# Advanced options")
|
writeln("\n# Advanced options")
|
||||||
|
|
||||||
# Checkbox options ====
|
# Checkbox options ====
|
||||||
writeln("\n## Miscellaneous options")
|
writeln("\n## Miscellaneous options")
|
||||||
b = lambda x: "Check" if x else "Blank";
|
b = lambda x: "Check" if x else "Blank";
|
||||||
writeln("```")
|
writeln("```")
|
||||||
writeln(f"{b(j['smoothScroll']):5} :: Use smooth scrolling")
|
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['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['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['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['regexFindMode']):5} :: Treat queries are JS regex expressions")
|
||||||
writeln(f"{b(j['ignoreKeyboardLayout']):5} :: Ignore keyboard layout")
|
writeln(f"{b(j['ignoreKeyboardLayout']):5} :: Ignore keyboard layout")
|
||||||
writeln("```\n")
|
writeln("```\n")
|
||||||
|
|
||||||
# More stuff ====
|
# More stuff ====
|
||||||
writeln("\n## More advanced options")
|
writeln("\n## More advanced options")
|
||||||
writeln("```")
|
writeln("```")
|
||||||
writeln(f" Scroll step size: {j['scrollStepSize']}px")
|
writeln(f" Scroll step size: {j['scrollStepSize']}px")
|
||||||
writeln(f"Characters used for link hints: {j['linkHintCharacters']}")
|
writeln(f"Characters used for link hints: {j['linkHintCharacters']}")
|
||||||
writeln(f" Previous patterns: {j['previousPatterns']}")
|
writeln(f" Previous patterns: {j['previousPatterns']}")
|
||||||
writeln(f" Next patterns: {j['nextPatterns']}")
|
writeln(f" Next patterns: {j['nextPatterns']}")
|
||||||
writeln(f" New tab URL: {j['newTabUrl']}")
|
writeln(f" New tab URL: {j['newTabUrl']}")
|
||||||
writeln(f" Default search engine: {j['searchUrl']}")
|
writeln(f" Default search engine: {j['searchUrl']}")
|
||||||
writeln("```")
|
writeln("```")
|
||||||
|
|
||||||
# CSS ====
|
# CSS ====
|
||||||
writeln("\n# Vimium CSS")
|
writeln("\n# Vimium CSS")
|
||||||
writeln("```css")
|
writeln("```css")
|
||||||
for line in j['userDefinedLinkHintCss'].split('\n'):
|
for line in j['userDefinedLinkHintCss'].split('\n'):
|
||||||
writeln(line.strip())
|
writeln(line.strip())
|
||||||
writeln("\n```")
|
writeln("\n```")
|
||||||
|
|
||||||
writeln("")
|
writeln("")
|
||||||
output.close()
|
output.close()
|
||||||
|
|
|
@ -22,7 +22,7 @@ set hidden
|
||||||
au BufWritePre [:;']* throw 'Forbidden file name: ' . expand('<afile>')
|
au BufWritePre [:;']* throw 'Forbidden file name: ' . expand('<afile>')
|
||||||
|
|
||||||
" Embedded code in markdown
|
" 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
|
" Human-facing settings
|
||||||
|
|
Loading…
Reference in a new issue