Make the list of URL prefixes configurable
This commit is contained in:
parent
57cf789c75
commit
ad706f9924
@ -21,7 +21,8 @@ def remote_control(args):
|
|||||||
|
|
||||||
|
|
||||||
def runpy(args):
|
def runpy(args):
|
||||||
exec(' '.join(args[1:]))
|
sys.argv = ['kitty'] + args[2:]
|
||||||
|
exec(args[1])
|
||||||
|
|
||||||
|
|
||||||
def launch(args):
|
def launch(args):
|
||||||
|
|||||||
@ -185,20 +185,20 @@ def mark(finditer, line, index_map):
|
|||||||
return line, marks
|
return line, marks
|
||||||
|
|
||||||
|
|
||||||
def run(source_file=None, regex=None, program=None):
|
def run(args, source_file=None):
|
||||||
if source_file is None:
|
if source_file is None:
|
||||||
text = read_from_stdin()
|
text = read_from_stdin()
|
||||||
else:
|
else:
|
||||||
with open(source_file, 'r') as f:
|
with open(source_file, 'r') as f:
|
||||||
text = f.read()
|
text = f.read()
|
||||||
if regex is None:
|
if args.regex is None:
|
||||||
from .url_regex import url_delimiters
|
from .url_regex import url_delimiters
|
||||||
url_pat = '(?:{})://[^{}]{{3,}}'.format(
|
url_pat = '(?:{})://[^{}]{{3,}}'.format(
|
||||||
'|'.join(URL_PREFIXES), url_delimiters
|
'|'.join(args.url_prefixes.split(',')), url_delimiters
|
||||||
)
|
)
|
||||||
finditer = partial(find_urls, re.compile(url_pat))
|
finditer = partial(find_urls, re.compile(url_pat))
|
||||||
else:
|
else:
|
||||||
finditer = partial(regex_finditer, re.compile(regex))
|
finditer = partial(regex_finditer, re.compile(args.regex))
|
||||||
lines = []
|
lines = []
|
||||||
index_map = {}
|
index_map = {}
|
||||||
for line in text.splitlines():
|
for line in text.splitlines():
|
||||||
@ -209,11 +209,11 @@ def run(source_file=None, regex=None, program=None):
|
|||||||
handler = URLHints(lines, index_map)
|
handler = URLHints(lines, index_map)
|
||||||
loop.loop(handler)
|
loop.loop(handler)
|
||||||
if handler.chosen and loop.return_code == 0:
|
if handler.chosen and loop.return_code == 0:
|
||||||
open_url(handler.chosen, program=program or 'default')
|
open_url(handler.chosen, program=args.program or 'default')
|
||||||
raise SystemExit(loop.return_code)
|
raise SystemExit(loop.return_code)
|
||||||
|
|
||||||
|
|
||||||
OPTIONS = '''\
|
OPTIONS = partial('''\
|
||||||
--program
|
--program
|
||||||
What program to use to open matched URLs. Defaults
|
What program to use to open matched URLs. Defaults
|
||||||
to the default URL open program for the operating system.
|
to the default URL open program for the operating system.
|
||||||
@ -222,14 +222,21 @@ to the default URL open program for the operating system.
|
|||||||
--regex
|
--regex
|
||||||
Instead of searching for URLs search for the specified regular
|
Instead of searching for URLs search for the specified regular
|
||||||
expression instead.
|
expression instead.
|
||||||
'''
|
|
||||||
|
|
||||||
|
--url-prefixes
|
||||||
|
default={0}
|
||||||
|
Comma separeted list of recognized URL prefixes. Defaults to:
|
||||||
|
{0}
|
||||||
|
'''.format, ','.join(sorted(URL_PREFIXES)))
|
||||||
|
|
||||||
|
|
||||||
def main(args=sys.argv):
|
def main(args=sys.argv):
|
||||||
msg = 'Highlight URLs inside the specified text'
|
msg = 'Highlight URLs inside the specified text'
|
||||||
args, items = parse_args(args[1:], OPTIONS, '[path to file or omit to use stdin]', msg, 'url_hints')
|
try:
|
||||||
run((items or [None])[0], args.regex, args.program)
|
args, items = parse_args(args[1:], OPTIONS, '[path to file or omit to use stdin]', msg, 'url_hints')
|
||||||
|
except SystemExit as e:
|
||||||
|
print(e.args[0], file=sys.stderr)
|
||||||
if __name__ == '__main__':
|
input('Press enter to quit...')
|
||||||
main()
|
return 1
|
||||||
|
run(args, (items or [None])[0])
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user