180 Commits

Author SHA1 Message Date
Alana Gilston
bfd06fa096
Add -B, -A, and -C options to grep (#1206)
Adds the -B (before context), -A (after context), and -C (before+after context) options to grep. Example usage:

```
grep -B <num> [args...]
grep -A <num> [args...]
```
2025-04-19 08:26:51 -07:00
Nate Fischer
d43d91533e chore: rename master -> main
No change to logic. This updates the main branch name.
2025-03-23 16:16:35 -07:00
Nate Fischer
c3d6ce62bf chore: update maintainers list
Update list of project maintainers.
2025-02-21 15:42:53 -08:00
Nate Fischer
65baedbf52 feat: expose new shell.cmd()
shell.cmd() was originally implemented in #866, however was not yet
exposed. This command should be ready for people to try out, so this
exposes the command by default.

This is still not a full implementation of everything in the
https://shelljs.page.link/cmd-design design doc, however this completes
the initial phase and is likely good enough to replace most use cases of
synchronous shell.exec().

Fixes #495
2025-02-20 00:26:35 -08:00
Nate Fischer
13cfe8a258 refactor: switch to fast-glob
This removes `node-glob` in favor of `fast-glob`. The main motivation
for this is because `node-glob` has a security warning and I can't
update to `node-glob@9` unless we drop compatibility for node v8.

Switching to `fast-glob` seems to be fairly straightforward, although
some options need to be changed by default for bash compatibility.

Fixes #828
Fixes #1149
2025-02-19 23:08:27 -08:00
Nate Fischer
03d2f20e27 refactor: unescape quotes
This swaps out quote characters to limit how often we need to escape
strings. This is just to improve code readability.

Almost all of the changes could be done without changes to .eslintrc,
however this amends the lint rule to also permit backtick strings which
can be useful to eliminate a few extra instances of quote escaping.

Fixes issue #788
Test: npm run lint
2025-02-19 22:35:39 -08:00
Nate Fischer
7e71b2686d chore: drop support for old node versions
Dropping support for everything before node v18, which is the current
maintenance LTS and also the version in Ubuntu 24.04 LTS.

This also updates all devDependencies while trying to minimize the
required source code changes. Some devDependencies can go higher still
(ava, chalk), but this is going to require extensive refactoring.

Test: npm run test-with-coverage
Test: npm run lint
Test: npm run check-node-support
2025-02-17 22:31:10 -08:00
Nate Fischer
9e51217484 chore: switch to testing LTS releases only
No change to official support. We will still accept patches for non-LTS
versions when it's reasonable to support them, especially for the most
recent Node release (whether that is odd-numbered or even-numbered).
This just lightens up the workload on CI because most of our users are
probably running node LTS.
2025-02-16 11:04:39 -08:00
Nate Fischer
d81c32535b deprecate config.globOptions
This deprecates support for configuring `config.globOptions`. Exposing
this variable makes it difficult to change (or upgrade) our glob
library. This discourages users from depending on this config option
going forward.

If anyone is using `config.globOptions` then it should continue to
function, however this support is not promised for the long-term.

As far as I know, this is not a commonly used option:
https://github.com/shelljs/shelljs/issues?q=globOptions currently shows
no GitHub issues of users using this option, and there was never really
a motivation for why this needed to be exposed (#400 exposed the option
just because we could, not because we should).

This is one step toward supporting Issue #828.
2024-06-14 13:07:33 -07:00
Nate Fischer
a6d1e49f18 docs: change GitHub Actions README badge
This changes the README to use a standard shields.io badge for GitHub
Actions. The custom badge
(https://github.com/Atrox/github-actions-badge) was cool, but the
atrox.dev link doesn't work reliably. I noticed that shields has support
for this now, so there's no reason to use a custom badge.

One notably difference is that this badge says the build is passing even
if there's a job still in progress.
2023-12-06 23:16:14 -08:00
Andreas Deininger
626973367f
Fixing typos (#1137)
This PR fixes a few typos that I spotted in the project.
2023-11-12 21:06:23 -08:00
Nate Fischer
4b6b17a635 docs(touch): clarify docs for touch() command
No change to logic. This expands on the `touch()` command documentation
to make it more obvious how to use multiple options, long options, etc.
This also renames a variable in a test case to make the usage more
obvious.
2022-02-13 17:38:11 -08:00
Nate Fischer
5f0eab152c docs(import): document es6 import command
No change to logic. This documents that we support importing via
`import shell from 'shelljs'`.

Related to issue #1071, although some more investigation is required to
understand why the other syntax doesn't work.
2022-02-13 17:24:12 -08:00
Nate Fischer
9a0e5f6694
Add preserve option to cp (#869)
Co-authored-by: dwi2 <dwi2@dwi2.com>
2022-01-26 22:41:40 -08:00
fhanrath
5af16d5c38
Feature/grep n (#1057) 2022-01-15 13:39:41 -08:00
JessieFrance
403a57cb9f
Feature: Expose Error Code (#1036) 2022-01-15 13:19:47 -08:00
Nate Fischer
1a8e38d6f2 docs(chmod): briefly mention Windows file perms
File permissions on Windows are weird. This adds a brief note into the
README that this is something to watch out for. As far as I'm aware, WSL
completely avoids the weirdness because it's actually Linux (and so it
follows POSIX).
2022-01-15 12:59:19 -08:00
Nate Fischer
f45d256940 docs(ls): document the toString() override
No change to logic. This documents `shell.ls('-l')`'s `.toString()`
override. I noticed this feature was not documented. This string format
should not be depended on by programmatic usage, but it's useful to make
things more human readable.
2022-01-15 12:59:05 -08:00
Ian
ad911973cd
Removed mentions of documentup website (#1056) 2021-12-16 23:31:18 -08:00
Nate Fischer
d0a45166fd
chore: set up GitHub Actions CI (#1055) 2021-11-29 23:34:38 -08:00
TagawaHirotaka
0ae1dd681e
Fix test command example (#1043) 2021-09-02 23:34:41 -07:00
Nate Fischer
54049d49d8
chore: change supported node versions (#1011)
This adds testing for node v14. This removes testing for node v6 and v7
because codecov breaks on these versions. This omits node v15 because
appveyor doesn't seem to support this version. The nodejs org currently
supports [10, 12, 14, 15].

This makes a couple minor edits to the check-node-support script for
consistency with shelljs/shx#186.

This bumps the shx dependency because it seems we're hitting issue #973
on node v14.

Test: npm run check-node-support
2020-10-26 16:44:47 -07:00
Zachary Snow
ba5d782fc2
Update ls with glob example. (#1006) 2020-09-02 23:31:59 -07:00
Jakob Krigovsky
9d0bdd6302 Update “OS X” to “macOS” (#977)
This updates documentation to refer to the new name for the Apple operating system.
2019-11-11 12:28:39 -08:00
Wes Cossick
4e38240eda Add boolean fatal option to exec() function (#961)
This PR introduces a new boolean fatal option for the exec() function. Like the existing silent option, this new option allows you to override the global fatal configuration parameter on a per-command basis.
2019-10-01 23:43:54 -07:00
Nate Fischer
7aa8ce4ebd
docs(exec): minor wording changes on security doc (#951)
This is a follow-up to #950, to emphasize the message.
2019-06-26 09:39:24 -07:00
Nate Fischer
68c382221e
docs(exec): document security concerns (#950)
No change to logic.

This adds documentation about `shell.exec()`'s inherent vulnerability to
command injection and links to a more detailed security notice.

Issue #103, #143, #495, #765, #766, #810, #842, #938, #945
2019-06-26 08:10:59 -07:00
st-sloth
619d23493c docs(sed): clarify using sed with newlines (#949)
Also remove example featuring line deletion as it does not work since the regex with '\n' will never match anything, because the file content is split by '\n' so there are no '\n's to match at all.
2019-06-26 01:08:09 -07:00
Jason Cooke
6d83d3509b docs: fix typo (#943) 2019-06-07 20:14:54 -07:00
Nate Fischer
9237f66c52
docs: clarify which methods return ShellStrings (#934)
No change to logic, only docs.

In v0.7.0, we introduced ShellStrings and changed most methods to return
them. Docs weren't appropriately updated, so this PR cross-links these
methods to the ShellString docs.

This also expands on the ShellString docs themselves, since there was
room to make this clearer.

Fixes #933
2019-03-06 03:39:08 -08:00
Nate Fischer
1560ffdc5f
feat(options): initial support for long options (#926)
* feat(options): initial support for long options

This adds initial support for long options. This integration tests them
with `shell.touch()` and unit tests them in `test/common.js`. This
documents the new syntax.

This also refactors some of the common internals:

 * Creates a new CommandError type to replace the `'earlyExit'` hack
 * Clearer Error types for `parseOptions()` exceptions
 * Removes side effects from a test which modifies `common.config`
 * Fixes appveyor and travis config to run lint (regressed in #920)

Issue #924
Test: touch.js, common.js

* small refactor for errorOptions
2019-01-05 00:54:30 -08:00
Nate Fischer
5371e1629f
test(touch): add coverage for -d option (#925)
No change to production logic.

We never had coverage for `touch({'-d': ...})`, so this adds test
coverage. This also updates documentation to clarify the parameter
should be an instance of the `Date` type.

Test: `handles date argument` case
2019-01-04 02:02:04 -08:00
Nate Fischer
3bb72eda8b
chore(node): drop node v4 and v5 (#917)
This drops support for node v4 and v5. Neither is currently supported by
the Node.js team, nor by the `npm` CLI team, so it's hard to justify we
continue to support it.

The new minimum supported version is v6.

Fixes #873
2018-12-01 20:23:46 -08:00
Nate Fischer
06450b8070
chore: script to bump supported node versions (#913)
No change to node support, this just adds a script.

This adds a script to check that we correctly configure all supported
node versions, since we need to update quite a few spots (README.md,
package.json, travis, appveyor).

Issue #873
Test: manual
2018-12-01 19:21:45 -08:00
Nate Fischer
d079515653
docs: remove gitter badge (#880)
No change to logic.

We don't really use the gitter chatroom right now, so we shouldn't
direct users to chat there. It's best to have issues reported directly
on Github.

This PR removes the gitter badge from the README.
2018-10-09 19:28:20 -07:00
Peng Zhao
4113a72c16 grep includes the i flag (#876)
grep includes the i flag to ignored upper/lower case differences
2018-07-22 20:38:13 -07:00
Zearin
9035b27403 docs: fix typos and adjust markdown formatting (#825)
Miscellaneous docs/markdown changes. No change to logic.
2018-02-19 22:21:17 -08:00
Nate Fischer
8f8119cfae
docs: announce plugin API (#812)
Fixes #391
2018-01-11 21:12:42 -08:00
Nate Fischer
a187bd1b36 Provide an API to pass parameters which resemble options (#792)
This adds the special option string `--`, which means "no options". This can be
passed if the first parameter looks like an option (starts with a `-` followed
by 1+ letters).

Fixes #778
2017-10-26 21:29:26 -07:00
Alexander Regueiro
cea0e58250 Added -q (quiet) option to push, popd, dirs functions. (#777)
* Added `-q` (quiet) option to `push`, `popd`, `dirs` functions.

* Added unit tests for pushd/popd quiet mode.

* Added tests for `pushd` and `popd` with quiet mode off.

* Updated docs for `pushd` and `popd` functions.

* Moved preliminary `pushd` commands for `popd` tests before disabling of silent flag.
2017-10-09 20:53:17 -07:00
cristHian Gz
c889075f78 feat(cat): number output lines (#750) (#775) 2017-09-22 21:27:42 -07:00
Brandon Freitag
dcead1be86 Add "encoding" option to exec (#763)
* Add 'encoding' option to shell.exec

* Add 'encoding' option to docs

* Add exec encoding option tests

* Clarify use of encoding with fs.readFileSync

* Add check for stderr buffer
2017-09-13 16:18:28 -07:00
Vojtech Jasny
c16fb7dac9 Remove PDF.js mention from README.md (#738)
Fixes #737.
2017-06-16 15:55:25 -07:00
Nate Fischer
18034486a5 Echo stdout (#677)
* Add newline to output of echo (#557)

* Add newline to output of echo

* Add test

* Throw an error if the options string does not start with '-' (#615)

* Throw an error if the options string does not start with '-'

* Add test

* Change message grammar

* Add -n option to echo

* Fix null argument issue

* Add -n tests

* Add documentation

* Add -en escaped character test

* Add function to parse options for echo

* Use parseOptions to parse echo options

* Simplify control flow

* parseOptions throws now

* Allow null to be echoed

* Prevent echo stderr on unrecognized option

* Add test to check stderr of returned value

* Use consistent variable name

* Change test message, leave TODO about console output
2017-06-06 21:10:27 -07:00
Nate Fischer
f74e783890 chore: remove v0.12 and iojs support (#648)
Fixes #647
2017-06-06 21:10:27 -07:00
Christian Zommerfelds
80d590ec05 Small clarification of verbose flag (#691)
* small clarification of verbose flag

* nfischer's documentation suggestion

* verbose flag documentation in source file
2017-03-30 20:30:30 -07:00
Nate Fischer
eb5230a53c chore: add codecov (#682)
* chore: add codecov

Add codecov to ShellJS

Partial fix for #671

* Add codecov badge to README
2017-03-04 17:53:37 -08:00
Nate Fischer
5318fdc43a docs: miscellaneous README changes (#661)
- Add @freitagbr to the bottom of the README
 - Remove docs about shjs (it's not well supported)
 - Remove docs about coffeescript (we don't do anything special for
   coffeescript anyway)
 - Modify the section about shelljs/global, since we strongly recommend
   avoiding this now
 - Rewrite the code example to use `require('shelljs')` instead of
   shelljs/global
 - Mention ESLint next to JSHint
 - Reformat sections with long lines to be 80 columns
2017-03-04 01:07:23 -08:00
Fran Dios
df06ac4a8a ls -L (follow symlinks) (#665)
* feat: -L (follow symlinks) option for ls

* test: ls -L option

* docs: Add ls -L option to readme

* fix: ls -L ternary operator

* Revert "test: ls -L option"

This reverts commit dbb057ac087b23aa2c1358018d3c832dd546c5f2.

* test: ls -L option

* test: Remove duplicate test
2017-02-27 20:53:32 -08:00
George Kalpakas
434ed592de docs(chmod): document options argument (#663) 2017-02-20 15:45:46 -08:00