Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bellstrand/bash2js
Convert bash output to JavaScript Arrays/Objects and use JavaScript functions on it
https://github.com/bellstrand/bash2js
Last synced: about 1 month ago
JSON representation
Convert bash output to JavaScript Arrays/Objects and use JavaScript functions on it
- Host: GitHub
- URL: https://github.com/bellstrand/bash2js
- Owner: bellstrand
- License: mit
- Created: 2016-07-21T07:28:08.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-07-23T07:49:39.000Z (over 8 years ago)
- Last Synced: 2024-10-03T09:29:20.152Z (3 months ago)
- Language: JavaScript
- Size: 12.7 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# bash2js
[![Build Status](https://travis-ci.org/bellstrand/bash2js.svg?branch=master)](https://travis-ci.org/bellstrand/bash2js)
[![npm Version](https://img.shields.io/npm/v/bash2js.svg)](https://www.npmjs.com/package/bash2js)bash2js converts bash output to JavaScript Arrays/Objects and lets you use JavaScript functions on it
## Installation
```bash
# required NodeJS to work https://nodejs.org/
npm install -g bash2js
```## How to use
```bash
command | bash2js # converts output from "command" to an array/object and prints it
command | bash2js "map(col => col[0])" # converts output from "command", loops through it and prints column of index 0 from each line (expects output to be an array)
command | bash2js test # converts output from "command", prints property with key "test" (expects output to be an object)
command | bash2js "[0]" # converts output from "command", prints first index in the array (expects output to be an array)
command | bash2js > test.json # converts output from "command", saved output to "test.json"
```## Examples
```bash
ls -l # outputs
total 10
-rwxr-xr-x 1 user 1049089 1013 jul 22 11:18 index.js*
-rw-r--r-- 1 user 1049089 1074 jul 21 09:22 LICENSE
-rw-r--r-- 1 user 1049089 533 jul 22 11:20 package.json
-rw-r--r-- 1 user 1049089 74 jul 21 09:23 README.mdls -l | bash2js # converts ls -l to an array and prints it
[
[ "total", 10 ],
[ "-rwxr-xr-x", 1, "user", 1049089, 1013, "jul", 22, "11:18", "index.js*" ],
[ "-rw-r--r--", 1, "user", 1049089, 1074, "jul", 21, "09:22", "LICENSE" ],
[ "-rw-r--r--", 1, "user", 1049089, 533, "jul", 22, "11:20", "package.json" ],
[ "-rw-r--r--", 1, "user", 1049089, 74, "jul", 21, "09:23", "README.md" ]
]ls -l | bash2js "map(col => col[8])" # converts ls -l to an array of arrays and prints the element at index 8 in each array
index.js*
LICENSE
package.json
README.mdcat package.json | bash2js repository # converts package.json to a object and prints the repository field
{
"type": "git",
"url": "git+https://github.com/bellstrand/bash2js.git"
}
```