mirror of
https://github.com/shelljs/shelljs.git
synced 2026-01-25 16:07:37 +00:00
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:
commit
3e441e4923
@ -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