|
|
|
@ -1,30 +1,39 @@ |
|
|
|
from config import config |
|
|
|
from opts import * |
|
|
|
import searcher |
|
|
|
import opener |
|
|
|
import argparse |
|
|
|
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) |
|
|
|
debug = True |
|
|
|
if __name__ == '__main__': |
|
|
|
args = parser.parse_args() |
|
|
|
if not debug and __name__ == "__main__": |
|
|
|
print(args) |
|
|
|
ext = args.ext |
|
|
|
s = searcher.Searcher(ext,args.case_insensitive) |
|
|
|
if args.update: |
|
|
|
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.exact: |
|
|
|
if args.__dict__.pop('exact'): |
|
|
|
matches = s.exact(args.query) |
|
|
|
else: |
|
|
|
matches = s.search(args.query,args.regex) |
|
|
|
@ -34,17 +43,28 @@ if not debug and __name__ == "__main__": |
|
|
|
if len(matches) == 1: |
|
|
|
row = matches[0] |
|
|
|
else: |
|
|
|
row = picker(matches) |
|
|
|
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.args,args.windowless,args.cwd) |
|
|
|
opener.standalone(path,args.arg,args.windowless,args.start_in) |
|
|
|
else: |
|
|
|
if args.edit: |
|
|
|
opener.edit(path,args.args) |
|
|
|
opener.edit(path,args.arg) |
|
|
|
else: |
|
|
|
mode = 'execute' |
|
|
|
opener.dependant(path,args.args,mode,args.cwd) |
|
|
|
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) |