@@ -62,13 +62,36 @@ installed system wide. To do this:
62
62
63
63
### macOS (OS X)
64
64
65
- If you're using macOS (formerly OS X), ` /etc/bashrc ` is apparently not sourced at
66
- all. In that case, you can put the ` bash_completion ` file in ` /sw/etc `
67
- and add the following code to ` ~/.bash_profile ` :
65
+ If you're using macOS (formerly OS X), ` /etc/bashrc ` is apparently not sourced
66
+ at all, and ` ~/.bashrc ` is not sourced from ` ~/.bash_profile ` by default
67
+ (because ` ~/.bash_profile ` is not created by default). In this case, the
68
+ standard way is to configure ` ~/.bash_profile ` to source ` ~/.bashrc ` and write
69
+ interactive settings in ` ~/.bashrc ` . You can source ` ~/.bashrc ` in
70
+ ` ~/.bash_profile ` in the following way:
68
71
69
72
``` shell
70
- if [ -f /sw/etc/bash_completion ]; then
71
- . /sw/etc/bash_completion
73
+ # ~/.bash_profile
74
+
75
+ if [[ -f ~ /.bashrc ]]; then
76
+ source ~ /.bashrc
77
+ fi
78
+ ```
79
+
80
+ Then, you can source ` bash-completion ` in your ` ~/.bashrc ` . It should be noted
81
+ that ` bash-completion ` should not be sourced in ` ~/.bash_profile ` because
82
+ ` ~/.bash_profile ` is only loaded in interactive _ login_ shell sessions. If you
83
+ start nested Bash sessions, the interactive settings in ` ~/.bash_profile ` will
84
+ disappear. It is strongly recommended to source ` ~/.bashrc ` from
85
+ ` ~/.bash_profile ` and write interactive settings in ` ~/.bashrc ` .
86
+
87
+ For example, if you install ` bash-completion ` using Homebrew, it will install
88
+ the entry point of ` bash-completion ` to
89
+ ` $HOMEBREW_PREFIX/etc/profile.d/bash_completion.sh ` . We can source it by
90
+ adding the following to our startup file ` ~/.bashrc ` :
91
+
92
+ ``` shell
93
+ if [[ -s $HOMEBREW_PREFIX /etc/profile.d/bash_completion.sh ]]; then
94
+ . " $HOMEBREW_PREFIX /etc/profile.d/bash_completion.sh"
72
95
fi
73
96
```
74
97
0 commit comments