Skip to content

Commit dfaa78a

Browse files
committed
feat(cd): cd() (no args) changes to home directory
1 parent c422069 commit dfaa78a

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,9 @@ target.bundle = function(argsArray) {
154154
All commands run synchronously, unless otherwise stated.
155155

156156

157-
### cd('dir')
158-
Changes to directory `dir` for the duration of the script
157+
### cd([dir])
158+
Changes to directory `dir` for the duration of the script. Changes to home
159+
directory if no argument is supplied.
159160

160161

161162
### pwd()

src/cd.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ var fs = require('fs');
22
var common = require('./common');
33

44
//@
5-
//@ ### cd('dir')
6-
//@ Changes to directory `dir` for the duration of the script
5+
//@ ### cd([dir])
6+
//@ Changes to directory `dir` for the duration of the script. Changes to home
7+
//@ directory if no argument is supplied.
78
function _cd(options, dir) {
89
if (!dir)
9-
common.error('directory not specified');
10+
dir = common.getUserHome();
1011

1112
if (dir === '-') {
1213
if (!common.state.previousDir)

test/cd.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ shell.mkdir('tmp');
1717
// Invalids
1818
//
1919

20-
shell.cd();
21-
assert.ok(shell.error());
22-
2320
assert.equal(fs.existsSync('/asdfasdf'), false); // sanity check
2421
shell.cd('/adsfasdf'); // dir does not exist
2522
assert.ok(shell.error());
@@ -72,4 +69,10 @@ shell.cd('..');
7269
shell.cd('~'); // Change back to home
7370
assert.equal(process.cwd(), common.getUserHome());
7471

72+
// Goes to home directory if no arguments are passed
73+
shell.cd(cur);
74+
shell.cd();
75+
assert.ok(!shell.error());
76+
assert.equal(process.cwd(), common.getUserHome());
77+
7578
shell.exit(123);

0 commit comments

Comments
 (0)