Skip to content

Conversation

@ashermancinelli
Copy link

Similar to set -x in bash, echos the command to stdout before executing anything.

One of my biggest complaints about using sh in place of shell scripting is that I can't bake-in something that echos the commands that are about to be run, so my scripts are littered with prints. I would love to be able to add _x=True to my bake arguments and see what's going to be run.

Given that set -x is specific to the shells I'm used to, I could also imagine _trace=True or _explicit=True being more approachable. Thanks in advance for any suggestions!

Similar to `set -x` in bash, echos the command to stdout before
executing anything.
@ashermancinelli
Copy link
Author

Unrelated FWIW:

adding this section to pyproject.toml would make it easier to develop this with uv

diff --git a/pyproject.toml b/pyproject.toml
index 0e8bb2f..eac408e 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,3 +1,7 @@
+[project]
+name = "sh"
+version = "2.2.2"
+
 [tool.poetry]
 name = "sh"
 version = "2.2.2"

uv complains with

> uv sync                          
error: No `project` table found in: `~/workspace/sh/pyproject.toml`

@ecederstrand
Copy link
Contributor

@amoffat may have a different opinion, but in my opinion sh is a subprocess replacement, not a bash replacement. As such, implementing -x isn't entirely in line with the purpose of sh.

If you want to print commands before execution, you can enable logging: https://sh.readthedocs.io/en/latest/sections/faq.html#how-do-i-see-the-commands-sh-is-running

@ashermancinelli
Copy link
Author

That works for me, thank you!

@ashermancinelli
Copy link
Author

If someone comes across this in the future, this gist might be useful.

with SetX: # prints commands from 'sh' module like 'set -x' does
    sh.opt('foo.ll', '-S', '-o', '-', passes='instcombine')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants