Merge pull request #383 from shelljs/cd-use-env-var

refactor(cd): use process.env.OLDPWD to store previous dir
This commit is contained in:
Ari Porad 2016-03-04 21:43:24 -08:00
commit 3e441e4923
2 changed files with 5 additions and 4 deletions

View File

@ -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;

View File

@ -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;