export PATH=$(zsh -l -c 'echo $PATH')
or shell agnostic
# 1. Detect the parent process name
parent_shell=$(ps -p $PPID -o comm= | tr -d '-') # tr removes the leading dash if it's a login shell
# 2. Map the process name to a valid binary path
# We use 'command -v' to ensure the shell actually exists on the system
if command -v "$parent_shell" >/dev/null 2>&1; then
shell_bin="$parent_shell"
else
# Fallback to the system's default SHELL if detection fails
shell_bin="${SHELL:-/bin/sh}"
fi
# 3. Capture the PATH as it would be in a fresh login session
# We use -l (login) and -c (command)
fresh_path=$($shell_bin -l -c 'echo $PATH' 2>/dev/null)
# 4. Apply it if we successfully got a result
if [ -n "$fresh_path" ]; then
export PATH="$fresh_path"
echo "Environment synced with $shell_bin login profile."
else
echo "Warning: Could not refresh PATH from parent shell. Using current PATH."
fi