You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/zh-cn/docs/tasks/tools/included/optional-kubectl-configs-bash-mac.md
+21-15Lines changed: 21 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,12 +2,20 @@
2
2
title: "macOS 系统上的 bash 自动补全"
3
3
description: "在 macOS 上实现 Bash 自动补全的一些可选配置。"
4
4
headless: true
5
+
_build:
6
+
list: never
7
+
render: never
8
+
publishResources: false
5
9
---
6
10
<!--
7
11
title: "bash auto-completion on macOS"
8
12
description: "Some optional configuration for bash auto-completion on macOS."
9
13
headless: true
10
-
-->
14
+
_build:
15
+
list: never
16
+
render: never
17
+
publishResources: false
18
+
-->
11
19
12
20
<!--
13
21
### Introduction
@@ -20,7 +28,7 @@ The kubectl completion script for Bash can be generated with `kubectl completion
20
28
However, the kubectl completion script depends on [**bash-completion**](https://github.com/scop/bash-completion) which you thus have to previously install.
There are two versions of bash-completion, v1 and v2. V1 is for Bash 3.2 (which is the default on macOS), and v2 is for Bash 4.1+. The kubectl completion script **doesn't work** correctly with bash-completion v1 and Bash 3.2. It requires **bash-completion v2** and **Bash 4.1+**. Thus, to be able to correctly use kubectl completion on macOS, you have to install and use Bash 4.1+ ([*instructions*](https://itnext.io/upgrading-bash-on-macos-7138bd1066ba)). The following instructions assume that you use Bash 4.1+ (that is, any Bash version of 4.1 or newer).
As mentioned, these instructions assume you use Bash 4.1+, which means you will install bash-completion v2 (in contrast to Bash 3.2 and bash-completion v1, in which case kubectl completion won't work).
@@ -104,14 +111,13 @@ As stated in the output of this command, add the following to your `~/.bash_prof
@@ -123,7 +129,7 @@ You now have to ensure that the kubectl completion script gets sourced in all yo
123
129
124
130
- Source the completion script in your `~/.bash_profile` file:
125
131
-->
126
-
你现在需要确保在所有的 shell 环境中均已导入(sourced)kubectl 的补全脚本,
132
+
你现在需要确保在所有的 Shell 环境中均已导入(sourced)kubectl 的补全脚本,
127
133
有若干种方法可以实现这一点:
128
134
129
135
- 在文件 `~/.bash_profile` 中导入(Source)补全脚本:
@@ -144,7 +150,7 @@ You now have to ensure that the kubectl completion script gets sourced in all yo
144
150
<!--
145
151
- If you have an alias for kubectl, you can extend shell completion to work with that alias:
146
152
-->
147
-
- 如果你为 kubectl 定义了别名,则可以扩展 shell 补全来兼容该别名:
153
+
- 如果你为 kubectl 定义了别名,则可以扩展 Shell 补全来兼容该别名:
148
154
149
155
```bash
150
156
echo'alias k=kubectl'>>~/.bash_profile
@@ -154,21 +160,21 @@ You now have to ensure that the kubectl completion script gets sourced in all yo
154
160
<!--
155
161
- If you installed kubectl with Homebrew (as explained [here](/docs/tasks/tools/install-kubectl-macos/#install-with-homebrew-on-macos)), then the kubectl completion script should already be in `/usr/local/etc/bash_completion.d/kubectl`. In that case, you don't need to do anything.
The Homebrew installation of bash-completion v2 sources all the files in the `BASH_COMPLETION_COMPAT_DIR` directory, that's why the latter two methods work.
0 commit comments