MCPcopy
hub / github.com/shelljs/shelljs / _pushd

Function _pushd

src/dirs.js:60–99  ·  view source on GitHub ↗
(options, dir)

Source from the content-addressed store, hash-verified

58//@
59//@ Save the current directory on the top of the directory stack and then `cd` to `dir`. With no arguments, `pushd` exchanges the top two directories. Returns an array of paths in the stack.
60function _pushd(options, dir) {
61 if (_isStackIndex(options)) {
62 dir = options;
63 options = '';
64 }
65
66 options = common.parseOptions(options, {
67 'n': 'no-cd',
68 'q': 'quiet',
69 });
70
71 var dirs = _actualDirStack();
72
73 if (dir === '+0') {
74 return dirs; // +0 is a noop
75 } else if (!dir) {
76 if (dirs.length > 1) {
77 dirs = dirs.splice(1, 1).concat(dirs);
78 } else {
79 return common.error('no other directory');
80 }
81 } else if (_isStackIndex(dir)) {
82 var n = _parseStackIndex(dir);
83 dirs = dirs.slice(n).concat(dirs.slice(0, n));
84 } else if (options['no-cd']) {
85 dirs.splice(1, 0, dir);
86 } else {
87 dirs.unshift(dir);
88 }
89
90 if (options['no-cd']) {
91 dirs = dirs.slice(1);
92 } else {
93 dir = path.resolve(dirs.shift());
94 _cd('', dir);
95 }
96
97 _dirStack = dirs;
98 return _dirs(options.quiet ? '-q' : '');
99}
100exports.pushd = _pushd;
101
102//@

Callers

nothing calls this directly

Calls 5

_isStackIndexFunction · 0.85
_actualDirStackFunction · 0.85
_parseStackIndexFunction · 0.85
_cdFunction · 0.85
_dirsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…