bash-lsp / bash-language-server

A language server for Bash

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

code formatting within a heredoc script

digitalsignalperson opened this issue · comments

commented

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