Compare commits
4 Commits
9f6ec508ce
...
d8c3cd2e36
Author | SHA1 | Date | |
---|---|---|---|
d8c3cd2e36 | |||
3e3c44075a | |||
50292eb2cb | |||
3ab5be69a1 |
38
netrun.py
38
netrun.py
|
@ -2,6 +2,7 @@
|
|||
import requests
|
||||
import subprocess
|
||||
import sys
|
||||
import os
|
||||
import argparse
|
||||
import shlex
|
||||
|
||||
|
@ -35,38 +36,51 @@ parser = argparse.ArgumentParser(
|
|||
)
|
||||
parser.add_argument("url", help="URL of the script")
|
||||
parser.add_argument(
|
||||
"-s",
|
||||
"--skip-pager",
|
||||
action="store_true",
|
||||
help="Skip pager and confirmation; run script immediately",
|
||||
"-i",
|
||||
"--interpreter",
|
||||
help="Choose interpreter to use (default: `bash`)",
|
||||
default="bash",
|
||||
)
|
||||
parser.add_argument(
|
||||
group = parser.add_mutually_exclusive_group()
|
||||
group.add_argument(
|
||||
"-p",
|
||||
"--pager",
|
||||
help="Choose pager to use (default: `less`)",
|
||||
default="less",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-i",
|
||||
"--interpreter",
|
||||
help="Choose interpreter to use (default: `bash`)",
|
||||
default="bash",
|
||||
group.add_argument(
|
||||
"-s",
|
||||
"--skip-pager",
|
||||
action="store_true",
|
||||
help="Skip pager and confirmation; run script immediately",
|
||||
)
|
||||
group.add_argument(
|
||||
"-q",
|
||||
"--quiet",
|
||||
action="store_true",
|
||||
help="Skip pager and confirmation; run script immediately; do not print anything",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
url = args.url
|
||||
pager = shlex.split(args.pager)
|
||||
interpreter = shlex.split(args.interpreter)
|
||||
|
||||
if not args.quiet:
|
||||
print(f"Downloading `{url}`...")
|
||||
content = requests.get(url).content
|
||||
if not args.quiet:
|
||||
print("Download successful.")
|
||||
print("=" * os.get_terminal_size().columns)
|
||||
|
||||
if args.skip_pager:
|
||||
if args.skip_pager or args.quiet:
|
||||
launch(interpreter, content)
|
||||
else:
|
||||
launch(pager, content)
|
||||
|
||||
response = yn("Do you want to run this script?")
|
||||
if response == "y":
|
||||
print("=" * 20)
|
||||
print("=" * os.get_terminal_size().columns)
|
||||
launch(interpreter, content)
|
||||
else:
|
||||
print("=" * os.get_terminal_size().columns)
|
||||
print("Script not run.")
|
||||
|
|
Loading…
Reference in New Issue
Block a user