diff --git a/README.rst b/README.rst
index aaf9e1a1..c134a566 100644
--- a/README.rst
+++ b/README.rst
@@ -219,7 +219,7 @@ multiple Python versions on the same system, the version being used to run the s
When using bash, global completion requires bash support for ``complete -D``, which was introduced in bash 4.2. Since
Mac OS ships with an outdated version of Bash (3.2), you can either use zsh or install a newer version of bash using
- `Homebrew `_ (``brew install bash`` - you will also need to add ``/usr/local/bin/bash`` to
+ `Homebrew `_ (``brew install bash`` - you will also need to add ``/opt/homebrew/bin/bash`` to
``/etc/shells``, and run ``chsh`` to change your shell). You can check the version of the running copy of bash with
``echo $BASH_VERSION``.
diff --git a/scripts/activate-global-python-argcomplete b/scripts/activate-global-python-argcomplete
index 7b3d9b73..7db46b79 100755
--- a/scripts/activate-global-python-argcomplete
+++ b/scripts/activate-global-python-argcomplete
@@ -13,6 +13,7 @@ import os
import shutil
import site
import sys
+import subprocess
import argcomplete
@@ -29,15 +30,22 @@ source "{activator}"
"""
+def get_local_dir():
+ try:
+ return subprocess.check_output(["brew", "--prefix"]).decode().strip()
+ except (FileNotFoundError, subprocess.CalledProcessError):
+ return "/usr/local"
+
+
def get_zsh_system_dir():
- return "/usr/local/share/zsh/site-functions"
+ return f"{get_local_dir()}/share/zsh/site-functions"
def get_bash_system_dir():
if "BASH_COMPLETION_COMPAT_DIR" in os.environ:
return os.environ["BASH_COMPLETION_COMPAT_DIR"]
elif sys.platform == "darwin":
- return "/usr/local/etc/bash_completion.d" # created by homebrew
+ return f"{get_local_dir()}/etc/bash_completion.d" # created by homebrew
else:
return "/etc/bash_completion.d" # created by bash-completion
@@ -117,8 +125,7 @@ if args.dest:
destinations.append(args.dest)
elif site.ENABLE_USER_SITE and site.USER_SITE in argcomplete.__file__:
print(
- "Argcomplete was installed in the user site local directory. Defaulting to user installation.",
- file=sys.stderr
+ "Argcomplete was installed in the user site local directory. Defaulting to user installation.", file=sys.stderr
)
link_user_rcfiles()
elif sys.prefix != sys.base_prefix: