mirror of
				https://github.com/nvm-sh/nvm.git
				synced 2025-10-31 10:15:53 +08:00 
			
		
		
		
	[Fix] install.sh: Detect profile with $BASH_VERSION and $ZSH_VERSION
				
					
				
			Using `$(basename "/$SHELL")` to detect the shell would also choose bash on mac
This commit is contained in:
		
				
					committed by
					
						 Jordan Harband
						Jordan Harband
					
				
			
			
				
	
			
			
			
						parent
						
							68fe26a5e4
						
					
				
				
					commit
					8b71861d06
				
			
							
								
								
									
										10
									
								
								install.sh
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								install.sh
									
									
									
									
									
								
							| @@ -219,16 +219,14 @@ nvm_detect_profile() { | ||||
|  | ||||
|   local DETECTED_PROFILE | ||||
|   DETECTED_PROFILE='' | ||||
|   local SHELLTYPE | ||||
|   SHELLTYPE="$(basename "/$SHELL")" | ||||
|  | ||||
|   if [ "$SHELLTYPE" = "bash" ]; then | ||||
|   if [ -n "${BASH_VERSION-}" ]; then | ||||
|     if [ -f "$HOME/.bashrc" ]; then | ||||
|       DETECTED_PROFILE="$HOME/.bashrc" | ||||
|     elif [ -f "$HOME/.bash_profile" ]; then | ||||
|       DETECTED_PROFILE="$HOME/.bash_profile" | ||||
|     fi | ||||
|   elif [ "$SHELLTYPE" = "zsh" ]; then | ||||
|   elif [ -n "${ZSH_VERSION-}" ]; then | ||||
|     DETECTED_PROFILE="$HOME/.zshrc" | ||||
|   fi | ||||
|  | ||||
| @@ -330,8 +328,7 @@ nvm_do_install() { | ||||
|   PROFILE_INSTALL_DIR="$(nvm_install_dir | command sed "s:^$HOME:\$HOME:")" | ||||
|  | ||||
|   SOURCE_STR="\\nexport NVM_DIR=\"${PROFILE_INSTALL_DIR}\"\\n[ -s \"\$NVM_DIR/nvm.sh\" ] && \\. \"\$NVM_DIR/nvm.sh\"  # This loads nvm\\n" | ||||
|   ZSH_COMPLETION_STR='# Load compinit/compdef\n autoload -U compinit\n compinit' | ||||
|    | ||||
|  | ||||
|   # shellcheck disable=SC2016 | ||||
|   COMPLETION_STR='[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion\n' | ||||
|   BASH_OR_ZSH=false | ||||
| @@ -360,7 +357,6 @@ nvm_do_install() { | ||||
|     # shellcheck disable=SC2016 | ||||
|     if ${BASH_OR_ZSH} && ! command grep -qc '$NVM_DIR/bash_completion' "$NVM_PROFILE"; then | ||||
|       echo "=> Appending bash_completion source string to $NVM_PROFILE" | ||||
|       command printf "$ZSH_COMPLETION_STR" >> "$NVM_PROFILE" | ||||
|       command printf "$COMPLETION_STR" >> "$NVM_PROFILE" | ||||
|     else | ||||
|       echo "=> bash_completion source string already in ${NVM_PROFILE}" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user