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

speed up when change directory in zsh #1264

Merged
merged 1 commit into from
Oct 14, 2016
Merged

speed up when change directory in zsh #1264

merged 1 commit into from
Oct 14, 2016

Conversation

iamxiaobo
Copy link

This pull request resolve two questions:

  1. For example, my project path is /home/user/work/nvm, in this project directory there is a .nvmrc file with v4.4.7, and my nvm default is v6.7.0。if i enter /home/user/work/nvm, nvm change node to v4.4.7 which is reasonable. but if i enter /home/user/work/nvm/public, nvm use default invoked and now the node become v6.7.0. use the new code, when enter /home/user/work/nvm/public, nvm not only check if .nvmrc exist in this directory, bus also check parents directory which can solve my problem.
  2. In current version of nvm, if my node version is v6.7.0 and the directory i enterd have .nvmrc file with content of v6.7.0, nvm also invoke nvm use and cost some time, it's meanless.

current=`pwd`
count=`echo $current | grep -o '/' | wc -l`
matchStatus='miss'
while [[ $count -ge 0 ]]
Copy link
Member

Choose a reason for hiding this comment

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

This code can get a lot simpler if you use nvm_find_nvmrc which will print out the first .nvmrc it finds - it's the same code nvm uses internally.

Copy link
Author

Choose a reason for hiding this comment

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

OK, I have updated my code by your suggestion

@ljharb ljharb added shell: zsh needs followup We need some info or action from whoever filed this issue/PR. informational labels Oct 13, 2016
local nvmrc_path="$(nvm_find_nvmrc)"

if [ -n "$nvmrc_path" ]; then
if [ "v$(cat $nvmrc_path)" != "$nodeversion" ]; then
Copy link
Member

Choose a reason for hiding this comment

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

this won't work because the .nvmrc file could contain 1 or v1.0 or v1.0.0 or foo (where "foo" is an alias) - you'd need $(nvm version "$(cat "${nvmrc_path}")")

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.

LGTM! mind rebasing this down to a commit?

@iamxiaobo
Copy link
Author

@ljharb , thanks for your review

@ljharb ljharb removed the needs followup We need some info or action from whoever filed this issue/PR. label Oct 14, 2016
@ljharb ljharb merged commit a338f98 into nvm-sh:master Oct 14, 2016
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.

2 participants