| 
									
										
										
										
											2024-07-14 16:18:26 -04:00
										 |  |  | # Documentation defined in Library/Homebrew/cmd/shellenv.rb | 
					
						
							| 
									
										
										
										
											2018-09-13 09:27:43 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-28 20:47:39 +09:00
										 |  |  | # HOMEBREW_CELLAR and HOMEBREW_PREFIX are set by extend/ENV/super.rb | 
					
						
							|  |  |  | # HOMEBREW_REPOSITORY is set by bin/brew | 
					
						
							| 
									
										
										
										
											2024-07-05 10:59:36 +08:00
										 |  |  | # Leading colon in MANPATH prepends default man dirs to search path in Linux and macOS. | 
					
						
							| 
									
										
										
										
											2022-09-15 21:51:27 +08:00
										 |  |  | # Please do not submit PRs to remove it! | 
					
						
							| 
									
										
										
										
											2021-04-28 20:47:39 +09:00
										 |  |  | # shellcheck disable=SC2154 | 
					
						
							| 
									
										
										
										
											2018-09-13 09:27:43 +01:00
										 |  |  | homebrew-shellenv() { | 
					
						
							| 
									
										
										
										
											2021-12-09 18:55:33 +08:00
										 |  |  |   if [[ "${HOMEBREW_PATH%%:"${HOMEBREW_PREFIX}"/sbin*}" == "${HOMEBREW_PREFIX}/bin" ]] | 
					
						
							| 
									
										
										
										
											2021-09-16 01:04:06 +08:00
										 |  |  |   then | 
					
						
							|  |  |  |     return | 
					
						
							|  |  |  |   fi | 
					
						
							| 
									
										
										
										
											2021-08-03 16:17:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												Allow brew shellenv to accept a shell name param
Resolves #15358
With this change, `brew shellenv` will accept a shell name parameter to
override its default output (based on `/bin/ps`) for advanced use cases
such as with dotfile templating and caching with
[twpayne/chezmoi](https://github.com/twpayne/chezmoi/discussions/2971).
When running under `fish`, this is the output:
```console
$ brew shellenv pwsh
[System.Environment]::SetEnvironmentVariable('HOMEBREW_PREFIX','/opt/homebrew',[System.EnvironmentVariableTarget]::Process)
[System.Environment]::SetEnvironmentVariable('HOMEBREW_CELLAR','/opt/homebrew/Cellar',[System.EnvironmentVariableTarget]::Process)
[System.Environment]::SetEnvironmentVariable('HOMEBREW_REPOSITORY','/opt/homebrew',[System.EnvironmentVariableTarget]::Process)
[System.Environment]::SetEnvironmentVariable('PATH',$('/opt/homebrew/bin:/opt/homebrew/sbin:'+$ENV:PATH),[System.EnvironmentVariableTarget]::Process)
[System.Environment]::SetEnvironmentVariable('MANPATH',$('/opt/homebrew/share/man'+$(if(${ENV:MANPATH}){':'+${ENV:MANPATH}})+':'),[System.EnvironmentVariableTarget]::Process)
[System.Environment]::SetEnvironmentVariable('INFOPATH',$('/opt/homebrew/share/info'+$(if(${ENV:INFOPATH}){':'+${ENV:INFOPATH}})),[System.EnvironmentVariableTarget]::Process)
$ brew shellenv
set -gx HOMEBREW_PREFIX "/opt/homebrew";
set -gx HOMEBREW_CELLAR "/opt/homebrew/Cellar";
set -gx HOMEBREW_REPOSITORY "/opt/homebrew";
set -q PATH; or set PATH ''; set -gx PATH "/opt/homebrew/bin" "/opt/homebrew/sbin" $PATH;
set -q MANPATH; or set MANPATH ''; set -gx MANPATH "/opt/homebrew/share/man" $MANPATH;
set -q INFOPATH; or set INFOPATH ''; set -gx INFOPATH "/opt/homebrew/share/info" $INFOPATH;
```
The specific case presented in the mentioned discussion could be
mitigated by an additional level of indirection (`{{ output "fish" "-c"
"'brew shellenv'" | trim }}`), that requires that the running system
have the target shells installed, when they are not strictly necessary
with `brew shellenv`.
											
										 
											2023-05-04 10:28:11 -04:00
										 |  |  |   if [[ -n "$1" ]] | 
					
						
							|  |  |  |   then | 
					
						
							|  |  |  |     HOMEBREW_SHELL_NAME="$1" | 
					
						
							|  |  |  |   else | 
					
						
							| 
									
										
										
										
											2023-05-08 11:06:30 -04:00
										 |  |  |     HOMEBREW_SHELL_NAME="$(/bin/ps -p "${PPID}" -c -o comm=)" | 
					
						
							| 
									
										
											  
											
												Allow brew shellenv to accept a shell name param
Resolves #15358
With this change, `brew shellenv` will accept a shell name parameter to
override its default output (based on `/bin/ps`) for advanced use cases
such as with dotfile templating and caching with
[twpayne/chezmoi](https://github.com/twpayne/chezmoi/discussions/2971).
When running under `fish`, this is the output:
```console
$ brew shellenv pwsh
[System.Environment]::SetEnvironmentVariable('HOMEBREW_PREFIX','/opt/homebrew',[System.EnvironmentVariableTarget]::Process)
[System.Environment]::SetEnvironmentVariable('HOMEBREW_CELLAR','/opt/homebrew/Cellar',[System.EnvironmentVariableTarget]::Process)
[System.Environment]::SetEnvironmentVariable('HOMEBREW_REPOSITORY','/opt/homebrew',[System.EnvironmentVariableTarget]::Process)
[System.Environment]::SetEnvironmentVariable('PATH',$('/opt/homebrew/bin:/opt/homebrew/sbin:'+$ENV:PATH),[System.EnvironmentVariableTarget]::Process)
[System.Environment]::SetEnvironmentVariable('MANPATH',$('/opt/homebrew/share/man'+$(if(${ENV:MANPATH}){':'+${ENV:MANPATH}})+':'),[System.EnvironmentVariableTarget]::Process)
[System.Environment]::SetEnvironmentVariable('INFOPATH',$('/opt/homebrew/share/info'+$(if(${ENV:INFOPATH}){':'+${ENV:INFOPATH}})),[System.EnvironmentVariableTarget]::Process)
$ brew shellenv
set -gx HOMEBREW_PREFIX "/opt/homebrew";
set -gx HOMEBREW_CELLAR "/opt/homebrew/Cellar";
set -gx HOMEBREW_REPOSITORY "/opt/homebrew";
set -q PATH; or set PATH ''; set -gx PATH "/opt/homebrew/bin" "/opt/homebrew/sbin" $PATH;
set -q MANPATH; or set MANPATH ''; set -gx MANPATH "/opt/homebrew/share/man" $MANPATH;
set -q INFOPATH; or set INFOPATH ''; set -gx INFOPATH "/opt/homebrew/share/info" $INFOPATH;
```
The specific case presented in the mentioned discussion could be
mitigated by an additional level of indirection (`{{ output "fish" "-c"
"'brew shellenv'" | trim }}`), that requires that the running system
have the target shells installed, when they are not strictly necessary
with `brew shellenv`.
											
										 
											2023-05-04 10:28:11 -04:00
										 |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-02 17:32:05 +08:00
										 |  |  |   if [[ -n "${HOMEBREW_MACOS}" ]] && | 
					
						
							|  |  |  |      [[ "${HOMEBREW_MACOS_VERSION_NUMERIC}" -ge "140000" ]] && | 
					
						
							|  |  |  |      [[ -x /usr/libexec/path_helper ]] | 
					
						
							|  |  |  |   then | 
					
						
							|  |  |  |     HOMEBREW_PATHS_FILE="${HOMEBREW_PREFIX}/etc/paths" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if [[ ! -f "${HOMEBREW_PATHS_FILE}" ]] | 
					
						
							|  |  |  |     then | 
					
						
							| 
									
										
										
										
											2024-09-11 02:23:26 +08:00
										 |  |  |       printf '%s/bin\n%s/sbin\n' "${HOMEBREW_PREFIX}" "${HOMEBREW_PREFIX}" 2>/dev/null >"${HOMEBREW_PATHS_FILE}" | 
					
						
							| 
									
										
										
										
											2024-09-02 17:32:05 +08:00
										 |  |  |     fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if [[ -r "${HOMEBREW_PATHS_FILE}" ]] | 
					
						
							|  |  |  |     then | 
					
						
							|  |  |  |       PATH_HELPER_ROOT="${HOMEBREW_PREFIX}" | 
					
						
							|  |  |  |     fi | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												Allow brew shellenv to accept a shell name param
Resolves #15358
With this change, `brew shellenv` will accept a shell name parameter to
override its default output (based on `/bin/ps`) for advanced use cases
such as with dotfile templating and caching with
[twpayne/chezmoi](https://github.com/twpayne/chezmoi/discussions/2971).
When running under `fish`, this is the output:
```console
$ brew shellenv pwsh
[System.Environment]::SetEnvironmentVariable('HOMEBREW_PREFIX','/opt/homebrew',[System.EnvironmentVariableTarget]::Process)
[System.Environment]::SetEnvironmentVariable('HOMEBREW_CELLAR','/opt/homebrew/Cellar',[System.EnvironmentVariableTarget]::Process)
[System.Environment]::SetEnvironmentVariable('HOMEBREW_REPOSITORY','/opt/homebrew',[System.EnvironmentVariableTarget]::Process)
[System.Environment]::SetEnvironmentVariable('PATH',$('/opt/homebrew/bin:/opt/homebrew/sbin:'+$ENV:PATH),[System.EnvironmentVariableTarget]::Process)
[System.Environment]::SetEnvironmentVariable('MANPATH',$('/opt/homebrew/share/man'+$(if(${ENV:MANPATH}){':'+${ENV:MANPATH}})+':'),[System.EnvironmentVariableTarget]::Process)
[System.Environment]::SetEnvironmentVariable('INFOPATH',$('/opt/homebrew/share/info'+$(if(${ENV:INFOPATH}){':'+${ENV:INFOPATH}})),[System.EnvironmentVariableTarget]::Process)
$ brew shellenv
set -gx HOMEBREW_PREFIX "/opt/homebrew";
set -gx HOMEBREW_CELLAR "/opt/homebrew/Cellar";
set -gx HOMEBREW_REPOSITORY "/opt/homebrew";
set -q PATH; or set PATH ''; set -gx PATH "/opt/homebrew/bin" "/opt/homebrew/sbin" $PATH;
set -q MANPATH; or set MANPATH ''; set -gx MANPATH "/opt/homebrew/share/man" $MANPATH;
set -q INFOPATH; or set INFOPATH ''; set -gx INFOPATH "/opt/homebrew/share/info" $INFOPATH;
```
The specific case presented in the mentioned discussion could be
mitigated by an additional level of indirection (`{{ output "fish" "-c"
"'brew shellenv'" | trim }}`), that requires that the running system
have the target shells installed, when they are not strictly necessary
with `brew shellenv`.
											
										 
											2023-05-04 10:28:11 -04:00
										 |  |  |   case "${HOMEBREW_SHELL_NAME}" in | 
					
						
							| 
									
										
										
										
											2021-07-29 22:39:26 +08:00
										 |  |  |     fish | -fish) | 
					
						
							| 
									
										
										
										
											2024-09-12 16:49:23 +08:00
										 |  |  |       echo "set --global --export HOMEBREW_PREFIX \"${HOMEBREW_PREFIX}\";" | 
					
						
							|  |  |  |       echo "set --global --export HOMEBREW_CELLAR \"${HOMEBREW_CELLAR}\";" | 
					
						
							|  |  |  |       echo "set --global --export HOMEBREW_REPOSITORY \"${HOMEBREW_REPOSITORY}\";" | 
					
						
							|  |  |  |       echo "fish_add_path --global --move --path \"${HOMEBREW_PREFIX}/bin\" \"${HOMEBREW_PREFIX}/sbin\";" | 
					
						
							|  |  |  |       echo "if test -n \"\$MANPATH[1]\"; set --global --export MANPATH '' \$MANPATH; end;" | 
					
						
							|  |  |  |       echo "if not contains \"${HOMEBREW_PREFIX}/share/info\" \$INFOPATH; set --global --export INFOPATH \"${HOMEBREW_PREFIX}/share/info\" \$INFOPATH; end;" | 
					
						
							| 
									
										
										
										
											2019-02-20 10:10:31 +00:00
										 |  |  |       ;; | 
					
						
							| 
									
										
										
										
											2021-07-29 22:39:26 +08:00
										 |  |  |     csh | -csh | tcsh | -tcsh) | 
					
						
							| 
									
										
										
										
											2021-04-28 20:47:39 +09:00
										 |  |  |       echo "setenv HOMEBREW_PREFIX ${HOMEBREW_PREFIX};" | 
					
						
							|  |  |  |       echo "setenv HOMEBREW_CELLAR ${HOMEBREW_CELLAR};" | 
					
						
							|  |  |  |       echo "setenv HOMEBREW_REPOSITORY ${HOMEBREW_REPOSITORY};" | 
					
						
							| 
									
										
										
										
											2024-09-02 17:32:05 +08:00
										 |  |  |       if [[ -n "${PATH_HELPER_ROOT}" ]] | 
					
						
							|  |  |  |       then | 
					
						
							| 
									
										
										
										
											2024-09-02 21:12:36 +08:00
										 |  |  |         PATH_HELPER_ROOT="${PATH_HELPER_ROOT}" PATH="${HOMEBREW_PATH}" /usr/libexec/path_helper -c | 
					
						
							| 
									
										
										
										
											2024-09-02 17:32:05 +08:00
										 |  |  |       else | 
					
						
							|  |  |  |         echo "setenv PATH ${HOMEBREW_PREFIX}/bin:${HOMEBREW_PREFIX}/sbin:\$PATH;" | 
					
						
							|  |  |  |       fi | 
					
						
							| 
									
										
										
										
											2024-08-04 02:52:14 +08:00
										 |  |  |       echo "test \${?MANPATH} -eq 1 && setenv MANPATH :\${MANPATH};" | 
					
						
							|  |  |  |       echo "setenv INFOPATH ${HOMEBREW_PREFIX}/share/info\`test \${?INFOPATH} -eq 1 && echo :\${INFOPATH}\`;" | 
					
						
							| 
									
										
										
										
											2019-02-20 10:10:31 +00:00
										 |  |  |       ;; | 
					
						
							| 
									
										
										
										
											2021-12-01 09:55:33 +01:00
										 |  |  |     pwsh | -pwsh | pwsh-preview | -pwsh-preview) | 
					
						
							| 
									
										
										
										
											2021-11-30 10:47:56 +01:00
										 |  |  |       echo "[System.Environment]::SetEnvironmentVariable('HOMEBREW_PREFIX','${HOMEBREW_PREFIX}',[System.EnvironmentVariableTarget]::Process)" | 
					
						
							|  |  |  |       echo "[System.Environment]::SetEnvironmentVariable('HOMEBREW_CELLAR','${HOMEBREW_CELLAR}',[System.EnvironmentVariableTarget]::Process)" | 
					
						
							|  |  |  |       echo "[System.Environment]::SetEnvironmentVariable('HOMEBREW_REPOSITORY','${HOMEBREW_REPOSITORY}',[System.EnvironmentVariableTarget]::Process)" | 
					
						
							|  |  |  |       echo "[System.Environment]::SetEnvironmentVariable('PATH',\$('${HOMEBREW_PREFIX}/bin:${HOMEBREW_PREFIX}/sbin:'+\$ENV:PATH),[System.EnvironmentVariableTarget]::Process)" | 
					
						
							|  |  |  |       echo "[System.Environment]::SetEnvironmentVariable('MANPATH',\$('${HOMEBREW_PREFIX}/share/man'+\$(if(\${ENV:MANPATH}){':'+\${ENV:MANPATH}})+':'),[System.EnvironmentVariableTarget]::Process)" | 
					
						
							|  |  |  |       echo "[System.Environment]::SetEnvironmentVariable('INFOPATH',\$('${HOMEBREW_PREFIX}/share/info'+\$(if(\${ENV:INFOPATH}){':'+\${ENV:INFOPATH}})),[System.EnvironmentVariableTarget]::Process)" | 
					
						
							|  |  |  |       ;; | 
					
						
							| 
									
										
										
										
											2019-02-20 10:10:31 +00:00
										 |  |  |     *) | 
					
						
							| 
									
										
										
										
											2021-04-28 20:47:39 +09:00
										 |  |  |       echo "export HOMEBREW_PREFIX=\"${HOMEBREW_PREFIX}\";" | 
					
						
							|  |  |  |       echo "export HOMEBREW_CELLAR=\"${HOMEBREW_CELLAR}\";" | 
					
						
							|  |  |  |       echo "export HOMEBREW_REPOSITORY=\"${HOMEBREW_REPOSITORY}\";" | 
					
						
							| 
									
										
										
										
											2024-10-07 14:11:02 -04:00
										 |  |  |       if [[ "${HOMEBREW_SHELL_NAME}" == "zsh" ]] || [[ "${HOMEBREW_SHELL_NAME}" == "-zsh" ]] | 
					
						
							|  |  |  |       then | 
					
						
							|  |  |  |         echo "fpath[1,0]=\"${HOMEBREW_PREFIX}/share/zsh/site-functions\";" | 
					
						
							|  |  |  |       fi | 
					
						
							| 
									
										
										
										
											2024-09-02 17:32:05 +08:00
										 |  |  |       if [[ -n "${PATH_HELPER_ROOT}" ]] | 
					
						
							|  |  |  |       then | 
					
						
							| 
									
										
										
										
											2024-09-02 21:12:36 +08:00
										 |  |  |         PATH_HELPER_ROOT="${PATH_HELPER_ROOT}" PATH="${HOMEBREW_PATH}" /usr/libexec/path_helper -s | 
					
						
							| 
									
										
										
										
											2024-09-02 17:32:05 +08:00
										 |  |  |       else | 
					
						
							|  |  |  |         echo "export PATH=\"${HOMEBREW_PREFIX}/bin:${HOMEBREW_PREFIX}/sbin\${PATH+:\$PATH}\";" | 
					
						
							|  |  |  |       fi | 
					
						
							| 
									
										
										
										
											2024-07-11 08:17:11 +01:00
										 |  |  |       echo "[ -z \"\${MANPATH-}\" ] || export MANPATH=\":\${MANPATH#:}\";" | 
					
						
							| 
									
										
										
										
											2021-04-28 20:47:39 +09:00
										 |  |  |       echo "export INFOPATH=\"${HOMEBREW_PREFIX}/share/info:\${INFOPATH:-}\";" | 
					
						
							| 
									
										
										
										
											2019-02-20 10:10:31 +00:00
										 |  |  |       ;; | 
					
						
							|  |  |  |   esac | 
					
						
							| 
									
										
										
										
											2018-09-13 09:27:43 +01:00
										 |  |  | } |