diff options
author | terminaldweller <thabogre@gmail.com> | 2021-06-05 21:31:14 +0000 |
---|---|---|
committer | terminaldweller <thabogre@gmail.com> | 2021-06-05 21:31:14 +0000 |
commit | acf6683d531ca50c97e4f553faad7a8bfb86ed0e (patch) | |
tree | aa452b333e7f1e7c05b9d884e5dc4ffcdb41d3cb /bin | |
parent | fixed the w3m script problems. now using exa. some other small stuff (diff) | |
download | scripts-acf6683d531ca50c97e4f553faad7a8bfb86ed0e.tar.gz scripts-acf6683d531ca50c97e4f553faad7a8bfb86ed0e.zip |
too much to talk about...
Diffstat (limited to '')
-rwxr-xr-x | bin/exclude_ip_list | 18 | ||||
-rwxr-xr-x | bin/vwtags.py | 82 |
2 files changed, 100 insertions, 0 deletions
diff --git a/bin/exclude_ip_list b/bin/exclude_ip_list new file mode 100755 index 0000000..2fa3e6f --- /dev/null +++ b/bin/exclude_ip_list @@ -0,0 +1,18 @@ +#!/usr/bin/env python3 +from ipaddress import ip_network + +start = '0.0.0.0/0' +exclude = ['127.0.0.1', '192.168.1.0/24', '185.126.202.69', '87.236.209.206'] + +result = [ip_network(start)] +for x in exclude: + n = ip_network(x) + new = [] + for y in result: + if y.overlaps(n): + new.extend(y.address_exclude(n)) + else: + new.append(y) + result = new + +print(','.join(str(x) for x in sorted(result))) diff --git a/bin/vwtags.py b/bin/vwtags.py new file mode 100755 index 0000000..3ac8d93 --- /dev/null +++ b/bin/vwtags.py @@ -0,0 +1,82 @@ +#! /usr/bin/env python3 +# -*- coding: utf-8 -*- + +from __future__ import print_function + +help_text = """ +Extracts tags from Vimwiki files. Useful for the Tagbar plugin. + +Usage: +Install Tagbar (http://majutsushi.github.io/tagbar/). Then, put this file +anywhere and add the following to your .vimrc: + +let g:tagbar_type_vimwiki = { + \ 'ctagstype':'vimwiki' + \ , 'kinds':['h:header'] + \ , 'sro':'&&&' + \ , 'kind2scope':{'h':'header'} + \ , 'sort':0 + \ , 'ctagsbin':'/path/to/vwtags.py' + \ , 'ctagsargs': 'default' + \ } + +The value of ctagsargs must be one of 'default', 'markdown' or 'media', +whatever syntax you use. However, if you use multiple wikis with different +syntaxes, you can, as a workaround, use the value 'all' instead. Then, Tagbar +will show markdown style headers as well as default/mediawiki style headers, +but there might be erroneously shown headers. +""" + +import sys +import re + +if len(sys.argv) < 3: + print(help_text) + exit() + +syntax = sys.argv[1] +filename = sys.argv[2] +rx_default_media = r"^\s*(={1,6})([^=].*[^=])\1\s*$" +rx_markdown = r"^\s*(#{1,6})([^#].*)$" + +if syntax in ("default", "media"): + rx_header = re.compile(rx_default_media) +elif syntax == "markdown": + rx_header = re.compile(rx_markdown) +else: + rx_header = re.compile(rx_default_media + "|" + rx_markdown) + +file_content = [] +try: + with open(filename, "r") as vim_buffer: + file_content = vim_buffer.readlines() +except: + exit() + +state = [""]*6 +for lnum, line in enumerate(file_content): + + match_header = rx_header.match(line) + + if not match_header: + continue + + match_lvl = match_header.group(1) or match_header.group(3) + match_tag = match_header.group(2) or match_header.group(4) + + cur_lvl = len(match_lvl) + cur_tag = match_tag.strip() + cur_searchterm = "^" + match_header.group(0).rstrip("\r\n") + "$" + cur_kind = "h" + + state[cur_lvl-1] = cur_tag + for i in range(cur_lvl, 6): + state[i] = "" + + scope = "&&&".join( + [state[i] for i in range(0, cur_lvl-1) if state[i] != ""]) + if scope: + scope = "\theader:" + scope + + print('{0}\t{1}\t/{2}/;"\t{3}\tline:{4}{5}'.format( + cur_tag, filename, cur_searchterm, cur_kind, str(lnum+1), scope)) |