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

code formatting within a heredoc script #1066

Open
digitalsignalperson opened this issue Dec 13, 2023 · 0 comments
Open

code formatting within a heredoc script #1066

digitalsignalperson opened this issue Dec 13, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@digitalsignalperson
Copy link

What is the problem this feature will solve?

I often have bash scripts with lots of heredocs. It's very convenient to consolidate many scripts and code snippets into one bash script. However, the lack of formatting within the heredocs makes it harder to spot mistakes if editing for example, a bash script within a heredoc.

What is the feature you are proposing to solve the problem?

Having code formatting in the individual heredoc sections, provided a shebang exists to indicate the language.

#!/bin/bash

echo "code is formatted here"

cat > /my/path << 'EOF'
#!/bin/bash

echo "code is also formatted here"
var="oops forgot a closing double quotes, help!

EOF

cat > /my/path2 << EOF
#!/bin/python

print("it would be cool if this could be formatted too in whatever language the shebang corresponds to")
EOF

cat > /my/path3 << EOF
This is not formatted
EOF


The only way formatting should work is if a shebang was provided, otherwise the heredoc could be for any purpose.

It would be really cool if this worked for any language in the heredoc's shebang, but I could imagine that being trickier. This feels similar to what markdown formatting is like:

# This is markdown

```bash
echo "bash code formatted in markdown codeblock. similar idea to a heredoc"
```

```python
print('python formatting in this code block in markdown)
```


What alternatives have you considered?

No response

@digitalsignalperson digitalsignalperson added the enhancement New feature or request label Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant