"Say goodbye to those gnarly Bash scripts!" -- @arturadib, ShellJS README
Want to try out ShellJS but don't want to go through the effort of porting all your scripts? Look no further.
Easily transpile your Bash scripts to ShellJS. Try it out here on the web. Just type, copy-paste, or drag-and-drop your favorite shell script and see the results.
Have a lot of scripts to transpile? Install this globally to use sh2js
to
transpile scripts from the command line.
Let me know by giving it a star on Github.
Contributions would be awesome! I'd really like to propel this project forward, but don't have much time. You can help me out by:
- sending me scripts you'd like to be able to translate, but haven't been able to
- finding bugs or thinking of features
- taking up one of the help-wanted issues
- helping refactor the grammar so that other people can use it too.
- spreading the word (more awareness = more contributors)
Note: this may not handle all Bash syntax until v1.0. If your script doesn't get translated successfully, please file a Github issue.
$ npm install -g shelljs-transpiler # this lets you use `sh2js`
What version of ShellJS is this compatible with? Can I run this code? Do I need a special version of Node? Will this translate anything correctly?
Your best bet are the latest versions of NodeJS and ShellJS. Some translations are significantly easier to do using ES6 features, so I use them where convenient. Also, ShellJS is still under development, so we're always adding new features to help give it the best of both JavaScript and Bash.
I'll sometimes write translations that take advantage of my not-yet-implemented ShellJS feature ideas--some of which may never get implemented. If your translated script relies on a feature that doesn't exist yet in ShellJS, let me know and I'll fix the transpiler to use a ShellJS feature that's available here and now.
The sh2js
CLI transpiler is still somewhat experimental, but feel free to
check it out! Usage:
$ sh2js [options] <shell script input> [JavaScript output]
If you want to take advantage of shelljs plugins in the translated script,
you're free to do so! Simply use the --plugins
flag to supply a
space-separated list of the plugins you want to use.
short option | long option | behavior |
---|---|---|
-v |
--version |
Output version information and quit |
-h |
--help |
Output help information and quit |
N/A | --plugins="<names>" |
Use each ShellJS plugin listed in the space-separated list <names> |
Ex. usage:
$ sh2js testFile.sh outputFile.js # overwrites outputFile.js
$ sh2js testFile.sh # writes to stdout
$ sh2js --plugins="tr open clear" testFile.sh # takes advantage of these plugins
As stated above, contributions are welcome! If you're interested in helping out, let me know by posting an issue or shooting me an email.
First, install it (and the git submodule dependencies!)
$ git clone --recursive https://github.com/nfischer/shelljs-transpiler.git
$ cd shelljs-transpiler/
$ npm install
Next, run it in the browser using npm start
, run unit tests using npm test
,
or try a script with path/to/shelljs-transpiler/bin/sh2js someScript.sh
.