From 34cb53474a8f5db7eba7e39ae597e62c0b5aceb1 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Mon, 7 Dec 2020 17:59:34 -0800 Subject: [PATCH] Update eval.py, do_cmd.py, delete forline.py. Forline can be achieved by eval | do_cmd. --- do_cmd.py | 3 +-- eval.py | 25 ++++++++++++++++++------- forline.py | 14 -------------- 3 files changed, 19 insertions(+), 23 deletions(-) delete mode 100644 forline.py diff --git a/do_cmd.py b/do_cmd.py index 10e573b..4a40c66 100644 --- a/do_cmd.py +++ b/do_cmd.py @@ -2,6 +2,5 @@ import os from voussoirkit import pipeable - -for line in pipeable.go(): +for line in pipeable.go(strip=True, skip_blank=True): os.system(line) diff --git a/eval.py b/eval.py index 3928aa3..f0d2dcf 100644 --- a/eval.py +++ b/eval.py @@ -1,3 +1,4 @@ +import argparse import glob import math import os @@ -7,10 +8,6 @@ import sys from voussoirkit import pipeable - -lines = pipeable.input(sys.argv[1]) -pattern = sys.argv[2] - def quote(s): return '"%s"' % s @@ -23,6 +20,20 @@ def random_hex(length=12): token = token[:length] return token -for line in lines: - x = line - pipeable.output(eval(pattern)) +def eval_argparse(args): + for line in pipeable.input(args.lines): + x = line + pipeable.output(eval(args.eval_string)) + +def main(argv): + parser = argparse.ArgumentParser(description=__doc__) + + parser.add_argument('lines') + parser.add_argument('eval_string') + parser.set_defaults(func=eval_argparse) + + args = parser.parse_args(argv) + return args.func(args) + +if __name__ == '__main__': + raise SystemExit(main(sys.argv[1:])) diff --git a/forline.py b/forline.py deleted file mode 100644 index e21fe63..0000000 --- a/forline.py +++ /dev/null @@ -1,14 +0,0 @@ -import os -import sys - -from voussoirkit import clipext - -text = sys.argv[1] -command = sys.argv[2:] -command = ['"%s"' % x if (' ' in x or x == '%x') else x for x in command] -command = ' '.join(command) -text = clipext.resolve(text) - -for line in text.splitlines(): - thiscomm = command.replace('%x', line) - os.system(thiscomm)