mvdan / sh

A shell parser, formatter, and interpreter with bash support; includes shfmt
https://pkg.go.dev/mvdan.cc/sh/v3
BSD 3-Clause "New" or "Revised" License
6.98k stars 332 forks source link

Using for xonsh shell #988

Closed anki-code closed 1 year ago

anki-code commented 1 year ago

Hi! Thank you for awesome initiative!

Is it possible to use the parser to translate bash to another shell language i.e. bash to xonsh?

Thanks!

mvdan commented 1 year ago

The parser here supports bash pretty well, yes. There's no direct support for xonsh in this project, but you could likely parse some shell with this project and then translate the bash syntax tree to xonsh manually.

I don't intend to support more shell languages as part of this project right now; adding support for zsh will already be enough work as it is.

mvdan commented 1 year ago

Also note that you don't need to use the Go API to parse bash into a syntax tree. See shfmt --to-json.

anki-code commented 1 year ago

Thank you @mvdan! I've tried shfmt and it works! So it's possible to get the syntax tree in json format and convert it to xonsh shell syntax. Thanks!