You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

70 lines
2.3 KiB

from config import config
from opts import *
from util import picker
import argparse
import opener
import pyperclip
import searcher
parser = argparse.ArgumentParser(prog='ext-open',prefix_chars=prefix_char)
for opt in prefix:
parser.add_argument(*opt.pop('ostring'),**opt)
sub_parsers = parser.add_subparsers(dest='ext')
exe_parser = sub_parsers.add_parser('exe',prefix_chars=prefix_char)
for opt in exe:
opt = opt.copy()
exe_parser.add_argument(*opt.pop('ostring'),**opt)
for ext in exts:
sub_parser = sub_parsers.add_parser(ext['ext'],prefix_chars=prefix_char)
for opt in ext['opts']+common:
opt = opt.copy()
sub_parser.add_argument(*opt.pop('ostring'),**opt)
if __name__ == '__main__':
args = parser.parse_args()
print(args)
ext = args.ext
s = searcher.Searcher(ext,args.case_sensitive)
if args.trim_history is not None:
if args.trim_history.lower() == 'all':
if input('Are you sure?\n(y/n): ') == 'y':
s.clear()
elif args.trim_history.isdecimal:
n = int(args.trim_history)
s.clean(n)
del args.__dict__['trim_history']
if args.__dict__.pop('update'):
s.update()
if args.__dict__.pop('exact'):
matches = s.exact(args.query)
else:
matches = s.search(args.query,args.regex)
if len(matches) == 0:
print('No matches')
quit()
if len(matches) == 1:
row = matches[0]
else:
if len(matches) <= 20:
row = picker(matches)
else:
row = picker(matches,True)
path = row[-1]
if args.path:
print(path)
pyperclip.copy(path)
else:
if args.ext == 'exe':
opener.standalone(path,args.arg,args.windowless,args.start_in)
else:
if args.edit:
opener.edit(path,args.arg)
else:
mode = 'execute'
ext_argnames = cur.get(args.ext).argnames
bools = filter(lambda arg: isinstance(args.__dict__[arg],bool),args.__dict__.keys())
canidates = filter(lambda arg: arg in ext_argnames,bools)
for canidate in canidates:
if canidate in config[ext].keys():
mode = canidate
break
opener.dependant(path,args.arg,mode,args.start_in)