Skip to content

Commit

Permalink
Merge pull request #306 from nfischer/cd-no-args
Browse files Browse the repository at this point in the history
feat(cd): cd() (no args) changes to home directory
  • Loading branch information
ariporad committed Jan 24, 2016
2 parents c422069 + dfaa78a commit 361eb93
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
5 changes: 3 additions & 2 deletions README.md
Expand Up @@ -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()
Expand Down
7 changes: 4 additions & 3 deletions src/cd.js
Expand Up @@ -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)
Expand Down
9 changes: 6 additions & 3 deletions test/cd.js
Expand Up @@ -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());
Expand Down Expand Up @@ -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);

0 comments on commit 361eb93

Please sign in to comment.