mirror of
https://github.com/shelljs/shelljs.git
synced 2026-02-01 16:56:47 +00:00
refactor(cd): use process.env.OLDPWD to store previous dir
This commit is contained in:
parent
da6d06830d
commit
0861056a4b
@ -10,16 +10,16 @@ function _cd(options, dir) {
|
||||
dir = common.getUserHome();
|
||||
|
||||
if (dir === '-') {
|
||||
if (!common.state.previousDir)
|
||||
if (!process.env.OLDPWD)
|
||||
common.error('could not find previous directory');
|
||||
else
|
||||
dir = common.state.previousDir;
|
||||
dir = process.env.OLDPWD;
|
||||
}
|
||||
|
||||
try {
|
||||
var curDir = process.cwd();
|
||||
process.chdir(dir);
|
||||
common.state.previousDir = curDir;
|
||||
process.env.OLDPWD = curDir;
|
||||
} catch (e) {
|
||||
// something went wrong, let's figure out the error
|
||||
var err;
|
||||
|
||||
@ -21,11 +21,12 @@ exports.config = config;
|
||||
var state = {
|
||||
error: null,
|
||||
currentCmd: 'shell.js',
|
||||
previousDir: null,
|
||||
tempDir: null
|
||||
};
|
||||
exports.state = state;
|
||||
|
||||
process.env.OLDPWD = null; // initially, there's no previous directory
|
||||
|
||||
var platform = os.type().match(/^Win/) ? 'win' : 'unix';
|
||||
exports.platform = platform;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user