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 requests
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
import os
|
||||||
import argparse
|
import argparse
|
||||||
import shlex
|
import shlex
|
||||||
|
|
||||||
|
@ -35,38 +36,51 @@ parser = argparse.ArgumentParser(
|
||||||
)
|
)
|
||||||
parser.add_argument("url", help="URL of the script")
|
parser.add_argument("url", help="URL of the script")
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-s",
|
"-i",
|
||||||
"--skip-pager",
|
"--interpreter",
|
||||||
action="store_true",
|
help="Choose interpreter to use (default: `bash`)",
|
||||||
help="Skip pager and confirmation; run script immediately",
|
default="bash",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
group = parser.add_mutually_exclusive_group()
|
||||||
|
group.add_argument(
|
||||||
"-p",
|
"-p",
|
||||||
"--pager",
|
"--pager",
|
||||||
help="Choose pager to use (default: `less`)",
|
help="Choose pager to use (default: `less`)",
|
||||||
default="less",
|
default="less",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
group.add_argument(
|
||||||
"-i",
|
"-s",
|
||||||
"--interpreter",
|
"--skip-pager",
|
||||||
help="Choose interpreter to use (default: `bash`)",
|
action="store_true",
|
||||||
default="bash",
|
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()
|
args = parser.parse_args()
|
||||||
url = args.url
|
url = args.url
|
||||||
pager = shlex.split(args.pager)
|
pager = shlex.split(args.pager)
|
||||||
interpreter = shlex.split(args.interpreter)
|
interpreter = shlex.split(args.interpreter)
|
||||||
|
|
||||||
|
if not args.quiet:
|
||||||
|
print(f"Downloading `{url}`...")
|
||||||
content = requests.get(url).content
|
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)
|
launch(interpreter, content)
|
||||||
else:
|
else:
|
||||||
launch(pager, content)
|
launch(pager, content)
|
||||||
|
|
||||||
response = yn("Do you want to run this script?")
|
response = yn("Do you want to run this script?")
|
||||||
if response == "y":
|
if response == "y":
|
||||||
print("=" * 20)
|
print("=" * os.get_terminal_size().columns)
|
||||||
launch(interpreter, content)
|
launch(interpreter, content)
|
||||||
else:
|
else:
|
||||||
|
print("=" * os.get_terminal_size().columns)
|
||||||
print("Script not run.")
|
print("Script not run.")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user