Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bash_completion fixes #1375

Merged
merged 3 commits into from
Mar 15, 2017
Merged

Conversation

PeterDaveHello
Copy link
Collaborator

  1. Since NVM_PROFILE will be a full path, the detection was not working properly without */ prefix.
  2. The origin bash_completion source prompt in installation was:
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
 && [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

Which will cause this error if you don't manually remove the comment:

-bash: x: line 2: syntax error near unexpected token `&&'
-bash: x: line 2: ` && [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion'

Which is inconvenient, so I removed the && prefix, and let the bash_completion to detect if nvm loaded.

  1. bash_completion didn't detect if nvm already loaded or not, so it'll work even if nvm is not loaded, now it'll detect if nvm loaded yet.

@@ -2,6 +2,10 @@

# bash completion for Node Version Manager (NVM)

if ! nvm &> /dev/null; then
return
Copy link
Member

Choose a reason for hiding this comment

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

should this error out, instead of just returning?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Refer to the common bash_completions, I think it's fine to just silently do nothing, but we can print error message if you want.

Copy link
Member

Choose a reason for hiding this comment

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

I guess this is fine as-is.

install.sh Outdated
@@ -306,7 +306,7 @@ nvm_do_install() {
command printf "${SOURCE_STR}"
else
case "${NVM_PROFILE-}" in
".bashrc" | ".bash_profile" | ".zshrc")
*"/.bashrc" | *"/.bash_profile" | *"/.zshrc")
Copy link
Member

Choose a reason for hiding this comment

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

How did this work in your original testing? Can we add "install script" tests that would have caught this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Since I can't run the tests locally, I might mess it up when manually mocking up the variables, or something like that, I'll be happy to write test, which part would you like to have?

Copy link
Member

Choose a reason for hiding this comment

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

Ideally I'd like a test that fails without the */, and passes with it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Then should we separate this part of detection out to a single function?

Copy link
Member

Choose a reason for hiding this comment

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

It's already in nvm_do_install - if that's not tested or is hard to test, then splitting it into a separate function is fine.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not sure if I understand it, looks like test/install_script/nvm_do_install is just for testing nvm_do_install function available?

Copy link
Member

Choose a reason for hiding this comment

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

Right - so let's refactor out the detection into a separate function, and make tests just for it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@ljharb updated! would you please help me review? Thanks!

@PeterDaveHello PeterDaveHello force-pushed the fix-bash-completion-install branch 2 times, most recently from 18eaabf to f8fd9bf Compare January 15, 2017 09:04
@PeterDaveHello
Copy link
Collaborator Author

Hello @ljharb, is the update fine with you 😄 ? Thanks.

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

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

Thanks, looks good. It'd be good to rebase this down to one commit on latest master, but I can take care of it when I get a chance to merge it if you don't have the time :-)

@PeterDaveHello
Copy link
Collaborator Author

@ljharb no problem, branch rebased, hope could be merged this time, thanks.

@ljharb ljharb merged commit 952d006 into nvm-sh:master Mar 15, 2017
@PeterDaveHello PeterDaveHello deleted the fix-bash-completion-install branch March 15, 2017 11:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants