Skip to content

Commit

Permalink
Use homebrew prefix by default
Browse files Browse the repository at this point in the history
  • Loading branch information
kislyuk committed Nov 1, 2023
1 parent 278deb0 commit e3caa06
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <http://brew.sh/>`_ (``brew install bash`` - you will also need to add ``/usr/local/bin/bash`` to
`Homebrew <http://brew.sh/>`_ (``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``.

Expand Down
15 changes: 11 additions & 4 deletions scripts/activate-global-python-argcomplete
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import os
import shutil
import site
import sys
import subprocess

import argcomplete

Expand All @@ -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

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit e3caa06

Please sign in to comment.