mirror of
				https://github.com/nvm-sh/nvm.git
				synced 2025-10-31 18:25:52 +08:00 
			
		
		
		
	[Refactor] Improve profile detection in install script
This commit is contained in:
		
				
					committed by
					
						 Jordan Harband
						Jordan Harband
					
				
			
			
				
	
			
			
			
						parent
						
							d4e3f0943b
						
					
				
				
					commit
					e84bcaabdc
				
			
							
								
								
									
										30
									
								
								install.sh
									
									
									
									
									
								
							
							
						
						
									
										30
									
								
								install.sh
									
									
									
									
									
								
							| @@ -183,6 +183,13 @@ install_nvm_as_script() { | |||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | nvm_try_profile() { | ||||||
|  |   if [ -z "${1-}" ] || [ ! -f "${1}" ]; then | ||||||
|  |     return 1 | ||||||
|  |   fi | ||||||
|  |   echo "${1}" | ||||||
|  | } | ||||||
|  |  | ||||||
| # | # | ||||||
| # Detect profile file if not specified as environment variable | # Detect profile file if not specified as environment variable | ||||||
| # (eg: PROFILE=~/.myprofile) | # (eg: PROFILE=~/.myprofile) | ||||||
| @@ -211,15 +218,12 @@ nvm_detect_profile() { | |||||||
|   fi |   fi | ||||||
|  |  | ||||||
|   if [ -z "$DETECTED_PROFILE" ]; then |   if [ -z "$DETECTED_PROFILE" ]; then | ||||||
|     if [ -f "$HOME/.profile" ]; then |     for EACH_PROFILE in ".profile" ".bashrc" ".bash_profile" ".zshrc" | ||||||
|       DETECTED_PROFILE="$HOME/.profile" |     do | ||||||
|     elif [ -f "$HOME/.bashrc" ]; then |       if DETECTED_PROFILE="$(nvm_try_profile "${HOME}/${EACH_PROFILE}")"; then | ||||||
|       DETECTED_PROFILE="$HOME/.bashrc" |         break | ||||||
|     elif [ -f "$HOME/.bash_profile" ]; then |       fi | ||||||
|       DETECTED_PROFILE="$HOME/.bash_profile" |     done | ||||||
|     elif [ -f "$HOME/.zshrc" ]; then |  | ||||||
|       DETECTED_PROFILE="$HOME/.zshrc" |  | ||||||
|     fi |  | ||||||
|   fi |   fi | ||||||
|  |  | ||||||
|   if [ ! -z "$DETECTED_PROFILE" ]; then |   if [ ! -z "$DETECTED_PROFILE" ]; then | ||||||
| @@ -362,10 +366,10 @@ nvm_do_install() { | |||||||
| # during the execution of the install script | # during the execution of the install script | ||||||
| # | # | ||||||
| nvm_reset() { | nvm_reset() { | ||||||
|   unset -f nvm_reset nvm_has nvm_latest_version \ |   unset -f nvm_has nvm_install_dir nvm_latest_version nvm_profile_is_bash_or_zsh \ | ||||||
|     nvm_source nvm_download install_nvm_as_script install_nvm_from_git \ |     nvm_source nvm_node_version nvm_download install_nvm_from_git nvm_install_node \ | ||||||
|     nvm_detect_profile nvm_check_global_modules nvm_do_install \ |     install_nvm_as_script nvm_try_profile nvm_detect_profile nvm_check_global_modules \ | ||||||
|     nvm_install_dir nvm_node_version nvm_install_node |     nvm_do_install nvm_reset | ||||||
| } | } | ||||||
|  |  | ||||||
| [ "_$NVM_ENV" = "_testing" ] || nvm_do_install | [ "_$NVM_ENV" = "_testing" ] || nvm_do_install | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user