Skip to content

Conversation

@taoyuan
Copy link

@taoyuan taoyuan commented Oct 17, 2014

No description provided.

@oNaiPs
Copy link

oNaiPs commented Nov 17, 2015

+1

@nfischer
Copy link
Member

@taoyuan Thanks for submitting the PR!

@taoyuan @oNaiPs What is the benefit of this PR vs. the following?

cd('path/to/dir');
exec('git status');
cd('-'); // <- the "jump back" feature used here will be released in 6.x, but it's currently merged on master

This has 3 lines of code, but it's very intuitive to a bash programmer. If there's an advantage to the cwd option, then we can consider merging 👍

@oNaiPs
Copy link

oNaiPs commented Jan 28, 2016

If you want to use shelljs asynchronously, it makes things more difficult to manage.

cd('path/to/dir1');
exec('git status', function(){
   cd('-');
});

cd('path/to/dir2');
exec('git status', function(){
   cd('-');
});

Would this even work?

@nfischer
Copy link
Member

@oNaiPs I think it would look a bit like this, right?

cd('path/to/dir1');
exec('git status', {async: true}); // executes asynchronously in directory 1
cd('-');

cd('path/to/dir2');
exec('git status', {async: true}); // executes asynchronously in directory 2
cd('-');

Correct me if I'm missing something

@ariporad
Copy link
Contributor

@nfischer: I think that this is a good idea. There are a whole host of reasons you might want to specify a cwd for exec. And it makes it closer to the builtin exec.

@taoyuan
Copy link
Author

taoyuan commented Jan 30, 2016

@nfischer Yes. It works fine in most cases. But in some case, I want to exec command without change current directory, so I must wrap a function:

funciton exec(..., opts) {
  ...
  var owd = process.cwd();

  if (opts.cwd) sh.cd(opts.cwd);
  result = sh.exec(command, opts); 
  if (opts.cwd) sh.cd(owd);
}

If we support options.cwd, It will be simple :

sh.exec(command, opts); 

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this change in the comments. Run scripts/generate-docs.js to generate the README

@nfischer
Copy link
Member

@taoyuan Could you please rebase off master? We've had quite a few changes, and there are now merge conflicts. Also, please remove the section about env. Feel free to open that as another PR, but I'm less in favor of that. If someone needs that flexibility, they can always use child_process.exec(). This is supposed to be a simple wrapper for shell-like use cases.

I left a comment above that should be addressed. Also, please add a unit test to test the cwd option. Perhaps you could run git status in the .. directory and check that it fails, and run git status without the cwd option and check that it succeeds.

Edit: npm commands are also suitable candidates instead of git commands. It just needs to be some command that runs on both Windows and Unix. git commands are mostly guaranteed to be available, npm commands are probably a safer guarantee even.

@ariporad
Copy link
Contributor

ariporad commented Feb 4, 2016

@taoyuan: As much as I hate to reject a PR, it looks like this has been fixed by #335, so I have to close this. Sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants