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