mirror of
https://github.com/shelljs/shelljs.git
synced 2026-01-18 16:03:37 +00:00
Merge pull request #306 from nfischer/cd-no-args
feat(cd): cd() (no args) changes to home directory
This commit is contained in:
commit
361eb93430
@ -154,8 +154,9 @@ target.bundle = function(argsArray) {
|
||||
All commands run synchronously, unless otherwise stated.
|
||||
|
||||
|
||||
### cd('dir')
|
||||
Changes to directory `dir` for the duration of the script
|
||||
### cd([dir])
|
||||
Changes to directory `dir` for the duration of the script. Changes to home
|
||||
directory if no argument is supplied.
|
||||
|
||||
|
||||
### pwd()
|
||||
|
||||
@ -2,11 +2,12 @@ var fs = require('fs');
|
||||
var common = require('./common');
|
||||
|
||||
//@
|
||||
//@ ### cd('dir')
|
||||
//@ Changes to directory `dir` for the duration of the script
|
||||
//@ ### cd([dir])
|
||||
//@ Changes to directory `dir` for the duration of the script. Changes to home
|
||||
//@ directory if no argument is supplied.
|
||||
function _cd(options, dir) {
|
||||
if (!dir)
|
||||
common.error('directory not specified');
|
||||
dir = common.getUserHome();
|
||||
|
||||
if (dir === '-') {
|
||||
if (!common.state.previousDir)
|
||||
|
||||
@ -17,9 +17,6 @@ shell.mkdir('tmp');
|
||||
// Invalids
|
||||
//
|
||||
|
||||
shell.cd();
|
||||
assert.ok(shell.error());
|
||||
|
||||
assert.equal(fs.existsSync('/asdfasdf'), false); // sanity check
|
||||
shell.cd('/adsfasdf'); // dir does not exist
|
||||
assert.ok(shell.error());
|
||||
@ -72,4 +69,10 @@ shell.cd('..');
|
||||
shell.cd('~'); // Change back to home
|
||||
assert.equal(process.cwd(), common.getUserHome());
|
||||
|
||||
// Goes to home directory if no arguments are passed
|
||||
shell.cd(cur);
|
||||
shell.cd();
|
||||
assert.ok(!shell.error());
|
||||
assert.equal(process.cwd(), common.getUserHome());
|
||||
|
||||
shell.exit(123);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user