All Projects → shelljs → Shx

shelljs / Shx

Licence: mit
Portable Shell Commands for Node

Programming Languages

javascript
184084 projects - #8 most used programming language
bash
514 projects

Labels

Projects that are alternatives of or similar to Shx

Goridge
High-performance PHP-to-Golang IPC bridge
Stars: ✭ 950 (-14.49%)
Mutual labels:  unix
Errand Boy
A memory-conscious alternative to os.fork() and subprocess.Popen().
Stars: ✭ 34 (-96.94%)
Mutual labels:  unix
Gpg Encrypt
Use GPG to encrypt a file using our best settings
Stars: ✭ 53 (-95.23%)
Mutual labels:  unix
Je
A distributed job execution engine for the execution of batch jobs, workflows, remediations and more.
Stars: ✭ 30 (-97.3%)
Mutual labels:  unix
Glfw
A multi-platform library for OpenGL, OpenGL ES, Vulkan, window and input
Stars: ✭ 8,416 (+657.52%)
Mutual labels:  unix
Ed
A modern UNIX ed (line editor) clone written in Go
Stars: ✭ 44 (-96.04%)
Mutual labels:  unix
Sortpem
➿ Sorting utility for PEM files
Stars: ✭ 11 (-99.01%)
Mutual labels:  unix
Skalibs
The skarnet.org C system programming library
Stars: ✭ 58 (-94.78%)
Mutual labels:  unix
Posnk
An operating system project.
Stars: ✭ 34 (-96.94%)
Mutual labels:  unix
Xsuspender
👀 💻 💤 🔋 Save battery by auto-suspending unfocused X11 applications.
Stars: ✭ 53 (-95.23%)
Mutual labels:  unix
Illumos Gate
An open-source Unix operating system
Stars: ✭ 952 (-14.31%)
Mutual labels:  unix
Awesome Unix
All the UNIX and UNIX-Like: Linux, BSD, macOS, Illumos, 9front, and more.
Stars: ✭ 973 (-12.42%)
Mutual labels:  unix
Luneta
command-line fuzzy finder
Stars: ✭ 49 (-95.59%)
Mutual labels:  unix
Unitial
🖥 My rc / configs / dotfiles 📂
Stars: ✭ 29 (-97.39%)
Mutual labels:  unix
Cmd
A simple package to execute shell commands on linux, windows and osx
Stars: ✭ 56 (-94.96%)
Mutual labels:  unix
Notes
📝 Simple delightful note taking, with more unix and less lock-in.
Stars: ✭ 939 (-15.48%)
Mutual labels:  unix
Crypt
Pure Go crypt(3) Implementation
Stars: ✭ 39 (-96.49%)
Mutual labels:  unix
Angel Ps1
Your fancy shell prompt fed by your guardian angel
Stars: ✭ 60 (-94.6%)
Mutual labels:  unix
Parsrs
CSV, JSON, XML text parsers and generators written in pure POSIX shellscript
Stars: ✭ 56 (-94.96%)
Mutual labels:  unix
Painless
Painless parameter handling for easy exploration
Stars: ✭ 51 (-95.41%)
Mutual labels:  unix

Shx

Travis AppVeyor Codecov npm version npm downloads

shx is a wrapper around ShellJS Unix commands, providing an easy solution for simple Unix-like, cross-platform commands in npm package scripts.

shx is proudly tested on every node release since v8!

Difference Between ShellJS and shx

  • ShellJS: Good for writing long scripts, all in JS, running via NodeJS (e.g. node myScript.js).
  • shx: Good for writing one-off commands in npm package scripts (e.g. "clean": "shx rm -rf out/").

Install

npm install shx --save-dev

This will allow using shx in your package.json scripts.

Usage

Command Line

If you'd like to use shx on the command line, install it globally with the -g flag. The following code can be run either a Unix or Windows command line:

$ shx pwd                       # ShellJS commands are supported automatically
/home/username/path/to/dir

$ shx ls                        # files are outputted one per line
file.txt
file2.txt

$ shx rm *.txt                  # a cross-platform way to delete files!

$ shx ls

$ shx echo "Hi there!"
Hi there!

$ shx touch helloworld.txt

$ shx cp helloworld.txt foobar.txt

$ shx mkdir sub

$ shx ls
foobar.txt
helloworld.txt
sub

$ shx rm -r sub                 # options work as well

$ shx --silent ls fakeFileName  # silence error output

All commands internally call the ShellJS corresponding function, guaranteeing cross-platform compatibility.

package.json

ShellJS is good for writing long scripts. If you want to write bash-like, platform-independent scripts, we recommend you go with that.

However, shx is ideal for one-liners inside package.json:

{
  "scripts": {
    "clean": "shx rm -rf build dist && shx echo Done"
  }
}

Tip: because Windows treats single quotes (ex. 'some string') differently than double quotes, we recommend wrapping your arguments in double quotes for cross platform compatibility (ex. "some string").

Command reference

Shx exposes most ShellJS commands. If a command is not listed here, assume it's supported!

sed

Shx provides unix-like syntax on top of shell.sed(). So ShellJS code like:

shell.sed('-i', /original string/g, 'replacement', 'filename.txt');

would turn into the following Shx command:

shx sed -i "s/original string/replacement/g" filename.txt

Note: like unix sed, shx sed treats / as a special character, and this must be escaped (as \/ in the shell, or \\/ in package.json) if you intend to use this character in either the regex or replacement string. Do not escape / characters in the file path.

Unsupported Commands

As mentioned above, most ShellJS commands are supported in ShellJS. Due to the differences in execution environments between ShellJS and shx (JS vs CLI) the following commands are not supported:

Unsupported command Recommend workaround
shx cd Just use plain old cd (it's the same on windows too)
shx pushd Just use plain old pushd. Use forward slashes and double-quote the path. (e.g. pushd "../docs". This would fail on Windows without the quotes)
shx popd Just use plain old popd
shx dirs No workaround
shx set See below
shx exit Just use plain old exit
shx exec Instead of shx exec cmd, just use plain old cmd
shx ShellString No workaround (but why would you want this?)

Shx options

Shx allows you to modify its behavior by passing arguments. Here's a list of supported options:

set flag shell.config setting shx command Effect
-e config.fatal = true Not supported Exit upon first error
-v config.verbose = true shx --verbose cd foo Log the command as it's run
-f config.noglob = true shx --noglob cat '*.txt' Don't expand wildcards
N/A config.silent = true shx --silent cd noexist Don't show error output

Team

Nate Fischer Ari Porad Levi Thomason
Nate Fischer Ari Porad Levi Thomason
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].