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

Evaluate lines beginning with a & using strformat's f-string syntax before executing them #26

Open
AngelEzquerra opened this issue Feb 7, 2023 · 0 comments

Comments

@AngelEzquerra
Copy link

AngelEzquerra commented Feb 7, 2023

Currently variables can be used in shell macros by using the ($variableName) syntax. For example:

var myString = "hello world"
shell:
    echo ($myString )

While this works, it introduces a custom mini-language that you must learn and that is less powerfull than nim's strformat f-string syntax.

I propose to add a way to use the strformat syntax within shell blocks. To do so, we could start a line with a "&" which is an invalid syntax in in Windows cmd.exe as well as in sh, bash and zsh, and has no effect in powershell. When a line started with & the shell macro would call strformat on it and then execute the result in the shell. This would let people use the syntax the already know in their shell blocks. In addition to that it would be much more powerful than the current syntax, since f-strings let you use complex expressions.

With this change the above example could be rewritten as:

var myString = "hello world"
shell:
    &echo {myString}

I don't know if we should deprecate the previous syntax. If it was deprecated, a user would be sure that as long as they did not begin a line with a & the command would be sent as is to the shell, which would be nice.

Given that starting a command with a & is basically invalid it probably would not be necessary to handle the case in which the user wanted to execute a command that started with a &. If we cared about that corner case, we could use a double && at the start of a command as a way to escape that initial &.

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

1 participant