MCPcopy Index your code
hub / github.com/shelljs/shelljs / _cd

Function _cd

src/cd.js:12–39  ·  view source on GitHub ↗
(options, dir)

Source from the content-addressed store, hash-verified

10//@ directory if no argument is supplied. Returns a
11//@ [ShellString](#shellstringstr) to indicate success or failure.
12function _cd(options, dir) {
13 if (!dir) dir = os.homedir();
14
15 if (dir === '-') {
16 if (!process.env.OLDPWD) {
17 common.error('could not find previous directory');
18 } else {
19 dir = process.env.OLDPWD;
20 }
21 }
22
23 try {
24 var curDir = process.cwd();
25 process.chdir(dir);
26 process.env.OLDPWD = curDir;
27 } catch (e) {
28 // something went wrong, let's figure out the error
29 var err;
30 try {
31 common.statFollowLinks(dir); // if this succeeds, it must be some sort of file
32 err = 'not a directory: ' + dir;
33 } catch (e2) {
34 err = 'no such file or directory: ' + dir;
35 }
36 if (err) common.error(err);
37 }
38 return '';
39}
40module.exports = _cd;

Callers 2

_pushdFunction · 0.85
_popdFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected