1 | # Shx
|
2 |
|
3 | [![Travis](https://img.shields.io/travis/shelljs/shx/master.svg?style=flat-square&label=unix)](https://travis-ci.org/shelljs/shx)
|
4 | [![AppVeyor](https://img.shields.io/appveyor/ci/ariporad/shx/master.svg?style=flat-square&label=windows)](https://ci.appveyor.com/project/ariporad/shx/branch/master)
|
5 | [![Codecov](https://img.shields.io/codecov/c/github/shelljs/shx/master.svg?style=flat-square&label=coverage)](https://codecov.io/gh/shelljs/shx)
|
6 | [![npm version](https://img.shields.io/npm/v/shx.svg?style=flat-square)](https://www.npmjs.com/package/shx)
|
7 | [![npm downloads](https://img.shields.io/npm/dm/shx.svg?style=flat-square)](https://www.npmjs.com/package/shx)
|
8 |
|
9 | `shx` is a wrapper around [ShellJS](https://github.com/shelljs/shelljs) Unix
|
10 | commands, providing an easy solution for simple Unix-like, cross-platform
|
11 | commands in npm package scripts.
|
12 |
|
13 | ## Install
|
14 |
|
15 | ```shell
|
16 | npm install shx --save-dev
|
17 | ```
|
18 | This will allow using `shx` in your `package.json` scripts.
|
19 |
|
20 | ## Usage
|
21 |
|
22 | ### Command Line
|
23 |
|
24 | If you'd like to use `shx` on the command line, install it globally with the `-g` flag.
|
25 | The following code can be run *either a Unix or Windows* command line:
|
26 |
|
27 | ```Bash
|
28 | $ shx pwd # ShellJS commands are supported automatically
|
29 | /home/username/path/to/dir
|
30 |
|
31 | $ shx ls # files are outputted one per line
|
32 | file.txt
|
33 | file2.txt
|
34 |
|
35 | $ shx rm *.txt # a cross-platform way to delete files!
|
36 |
|
37 | $ shx ls
|
38 |
|
39 | $ shx echo "Hi there!"
|
40 | Hi there!
|
41 |
|
42 | $ shx touch helloworld.txt
|
43 |
|
44 | $ shx cp helloworld.txt foobar.txt
|
45 |
|
46 | $ shx mkdir sub
|
47 |
|
48 | $ shx ls
|
49 | foobar.txt
|
50 | helloworld.txt
|
51 | sub
|
52 |
|
53 | $ shx rm -r sub # options work as well
|
54 |
|
55 | $ shx --silent ls fakeFileName # silence error output
|
56 | ```
|
57 |
|
58 | All commands internally call the ShellJS corresponding function, guaranteeing
|
59 | cross-platform compatibility.
|
60 |
|
61 | ### package.json
|
62 |
|
63 | ShellJS is good for writing long scripts. If you want to write bash-like,
|
64 | platform-independent scripts, we recommend you go with that.
|
65 |
|
66 | However, `shx` is ideal for one-liners inside `package.json`:
|
67 |
|
68 | ```javascript
|
69 | {
|
70 | "scripts": {
|
71 | "clean": "shx rm -rf build dist && shx echo Done"
|
72 | }
|
73 | }
|
74 | ```
|
75 |
|
76 | ## Unsupported Commands
|
77 |
|
78 | Due to the differences in execution environments between ShellJS and `shx` (JS vs CLI) some commands are not supported:
|
79 |
|
80 | | Unsupported command | Recommend workaround |
|
81 | | ------------------- | -------------------- |
|
82 | | `shx cd` | Just use plain old `cd` (it's the same on windows too) |
|
83 | | `shx pushd` | No workaround |
|
84 | | `shx popd` | No workaround |
|
85 | | `shx dirs` | No workaround |
|
86 | | `shx set` | See below |
|
87 | | `shx exit` | Just use plain old `exit` |
|
88 | | `shx exec` | Instead of `shx exec cmd`, just use plain old `cmd` |
|
89 | | `shx ShellString` | No workaround (but why would you want this?) |
|
90 |
|
91 | ### Shx options
|
92 |
|
93 | Shx allows you to modify its behavior by passing arguments. Here's a list of
|
94 | supported options:
|
95 |
|
96 | | [`set`](https://github.com/shelljs/shelljs#setoptions) flag | [`shell.config`](https://github.com/shelljs/shelljs#configuration) setting | shx command | Effect |
|
97 | |:---:| --- | --- | --- |
|
98 | | `-e` | `config.fatal = true` | Not supported | Exit upon first error |
|
99 | | `-v` | `config.verbose = true` | `shx --verbose cd foo` | Log the command as it's run |
|
100 | | `-f` | `config.noglob = true` | `shx --noglob cat '*.txt'` | Don't expand wildcards |
|
101 | | N/A | `config.silent = true` | `shx --silent cd noexist` | Don't show error output |
|
102 |
|
103 | ## Team
|
104 |
|
105 | | [![Nate Fischer](https://avatars.githubusercontent.com/u/5801521?s=130)](https://github.com/nfischer) | [![Ari Porad](https://avatars1.githubusercontent.com/u/1817508?v=3&s=130)](http://github.com/ariporad) | [![Levi Thomason](https://avatars1.githubusercontent.com/u/5067638?v=3&s=130)](https://github.com/levithomason) |
|
106 | |:---:|:---:|:---:|
|
107 | | [Nate Fischer](https://github.com/nfischer) | [Ari Porad](http://github.com/ariporad) | [Levi Thomason](https://github.com/levithomason) |
|