Inspired by zx
#!/usr/bin/env shx
await $"cat setup.py | grep name"
branch = await $("git branch --show-current", capture='o')
await $f"dep deploy --branch={branch}"
await gather(
$"sleep 1; echo 1",
$"sleep 2; echo 2",
$"sleep 3; echo 3",
)
name = "foo bar"
await $f"mkdir /tmp/{Q(name)}"
(Take a look at more examples.)
shx makes your script writing experience better by taking the advantages of Python's sugary syntax, AsyncIO, and the extensive Python ecosystem. shx does three things:
import asyncio
from asyncio import *
from pathlib import Path
from shlex import quote as Q
import shutil
Note that shx does not perform quote escape automatically. Use function Q (alias of shlex.quote) to escape unsafe arguments.
pip install shx
Settings can either be task local (e.g. __.trace = True) or per-command (e.g. await $("echo 42", trace=True)):
Attributes:
Change working directory to cwd. Same as the task local settings, the changes are only effective within the current task.
input() with KeyboardInterrupt handling.
No magic, no meta-programming, and no hacking, whatsoever. Prior execution, the script is tokenized, and the following replacements occur:
where SHX is an async function wrapping around asyncio.create_subprocess_shell.
Author: Contextualist
Official Website: https://github.com/Contextualist/shx