Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to run block in the current shell? #725

Open
thevops opened this issue Jan 8, 2025 · 1 comment
Open

How to run block in the current shell? #725

thevops opened this issue Jan 8, 2025 · 1 comment

Comments

@thevops
Copy link

thevops commented Jan 8, 2025

I'd like to run block using the current shell without overwriting it since I use direnv.
I use Runme CLI.

I've found that when I set shellscript at the begging of the block then it works good, but every time I save the file in VSCode (with Runme extension) shellscript is replaced with sh and it's not working.

Current state

Block test1:

echo $PATH | tr ":" "\n"

Command: runme run --filename .runbooks/test.runme test1

On the output I got overwrited PATH. This is not what I have when I run echo $PATH in the current shell.

Expected state

Some switch or configuration that preserves shellscript option in file or a flag for Runme CLI that overwrites behavior.

@lalyos
Copy link
Contributor

lalyos commented Jan 18, 2025

I found this comment in the code: https://github.com/stateful/runme/blob/main/internal/command/config.go#L45-L48

	// shellscripts
	// TODO(adamb): breaking change: shellscript was removed to indicate
	// that it should be executed as a file. Consider adding it back and
	// using attributes to decide how a code block should be executed.

But as a workaround you can write a shell function:

  • which redirects runme run --dry-run output to a file .runme
  • delete the first 5 lines (shebang and set)
  • than executes the command in the same shell: source .runme

here is a poc

runme-here() {
  runme run "$@" --dry-run |& sed 1,5d > .runme
  source .runme
}

after that you just replace runme run with runme-here

# original command in a subshell
runme run  --filename .runbooks/test.runme test1 

# running dry-run output in the same shell
runme-here --filename .runbooks/test.runme test1

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

No branches or pull requests

2 participants